Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Plotting Arc in Matlab

Subject: Plotting Arc in Matlab

From: Daniel

Date: 20 Feb, 2007 19:02:22

Message: 1 of 16

Hi,

Hopefully this is an easy question to answer:

How can you plot a part of a circle (arc) when begin point, end point
and radius of the arc is known.

I looked around but haven't yet found the solution

Thanks,

Daniel

Subject: Plotting Arc in Matlab

From: John D'Errico

Date: 20 Feb, 2007 22:12:28

Message: 2 of 16

Daniel wrote:
>
>
> Hi,
>
> Hopefully this is an easy question to answer:
>
> How can you plot a part of a circle (arc) when begin point, end
> point
> and radius of the arc is known.
>
> I looked around but haven't yet found the solution
>
> Thanks,
>
> Daniel

Which arc do you desire?

Perhaps you might consider if you have
provided enough information to determine
the arc uniquely.

John

Subject: Plotting Arc in Matlab

From: Daniel

Date: 20 Feb, 2007 19:26:17

Message: 3 of 16

On Feb 21, 2:12 pm, "John D'Errico" <woodch...@rochester.rr.com>
wrote:
> Daniel wrote:
>
> > Hi,
>
> > Hopefully this is an easy question to answer:
>
> > How can you plot a part of a circle (arc) when begin point, end
> > point
> > and radius of the arc is known.
>
> > I looked around but haven't yet found the solution
>
> > Thanks,
>
> > Daniel
>
> Which arc do you desire?
>
> Perhaps you might consider if you have
> provided enough information to determine
> the arc uniquely.
>
> John- Hide quoted text -
>
> - Show quoted text -

The problem is, is that the only information I have is a begin point
of the arc, the end point of the arc, and the radius of curvature of
the arc. This should be enough information to minimise the uniqueness
of the arc to 2.

Subject: Plotting Arc in Matlab

From: Daniel

Date: 20 Feb, 2007 19:51:29

Message: 4 of 16

On Feb 21, 2:26 pm, "Daniel" <vanhen...@gmail.com> wrote:
> On Feb 21, 2:12 pm, "John D'Errico" <woodch...@rochester.rr.com>
> wrote:
>
>
>
>
>
> > Daniel wrote:
>
> > > Hi,
>
> > > Hopefully this is an easy question to answer:
>
> > > How can you plot a part of a circle (arc) when begin point, end
> > > point
> > > and radius of thearcis known.
>
> > > I looked around but haven't yet found the solution
>
> > > Thanks,
>
> > > Daniel
>
> > Whicharcdo you desire?
>
> > Perhaps you might consider if you have
> > provided enough information to determine
> > thearcuniquely.
>
> > John- Hide quoted text -
>
> > - Show quoted text -
>
> The problem is, is that the only information I have is a begin point
> of thearc, the end point of thearc, and the radius of curvature of
> thearc. This should be enough information to minimise the uniqueness
> of thearcto 2.- Hide quoted text -
>
> - Show quoted text -

I found this piece of code, which creates an arc using begin point,
end point and arc length:

P1=[150,300]; P2=[500,600];
P=P2-P1;
[ThC,C]=cart2pol(P(1),P(2));
f=inline('2*L*sin(Th/2)-C*Th','Th','L','C');
options=optimset('Display','off');
for inc=50:100:950
   L=C+inc;
   Th=fzero(f,sqrt(24*(1-C/L)),options,L,C);
   R=C/(2*sin(Th/2));
   [x,y]=pol2cart(ThC+(pi-Th)/2,R);
   CC=P1+[x,y];
   P=P1-CC;
   ThP1=cart2pol(P(1),P(2));
   [x,y]=pol2cart(linspace(ThP1,ThP1+Th),R);
   plot(x+CC(1),y+CC(2)); hold on
end
daspect([1,1,1]); grid; hold off

This is nearly what I need... Does someone know how to create an arc
when not the arc length of the radius of curvature is known?

Thanks

Subject: Plotting Arc in Matlab

From: us

Date: 20 Feb, 2007 22:52:34

Message: 5 of 16

Daniel:
<SNIP looking for an incomplete circle...

> How can you plot a part of a circle (arc) when begin point, end
point and radius of the arc is known...

one of the many solutions

% some data
     xyoff=[2,1];
     ba=-30; % degrees
     ea=-90;
     r=10;
     res=1; % resolution
% the engine
     be=sort(mod([ba,ea],360));
     v=be(1):res:be(2);
     line(xyoff(1)+r*cosd(v),xyoff(2)+r*sind(v),...
          'marker','.',...
          'markersize',10,...
          'color',[1,0,0]);
% ...embedded
     line(xyoff(1)+r*cosd(1:360),xyoff(2)+r*sind(1:360),...
          'marker','none',...
          'color',[0,0,0]);
     set(gca,'xlim',[-20,20]);
     axis equal;

us

Subject: Plotting Arc in Matlab

From: Daniel

Date: 20 Feb, 2007 20:01:26

Message: 6 of 16

On Feb 21, 2:52 pm, us <u...@neurol.unizh.ch> wrote:
> Daniel:
> <SNIP looking for an incomplete circle...
>
> > How can you plot a part of a circle (arc) when begin point, end
>
> point and radius of the arc is known...
>
> one of the many solutions
>
> % some data
> xyoff=[2,1];
> ba=-30; % degrees
> ea=-90;
> r=10;
> res=1; % resolution
> % the engine
> be=sort(mod([ba,ea],360));
> v=be(1):res:be(2);
> line(xyoff(1)+r*cosd(v),xyoff(2)+r*sind(v),...
> 'marker','.',...
> 'markersize',10,...
> 'color',[1,0,0]);
> % ...embedded
> line(xyoff(1)+r*cosd(1:360),xyoff(2)+r*sind(1:360),...
> 'marker','none',...
> 'color',[0,0,0]);
> set(gca,'xlim',[-20,20]);
> axis equal;
>
> us

Thanks,

but your solution suggest you know the center of the circle and the
number of degrees you want to plot. I only know begin[x,y] end[x,y]
and radius of curvature.

Subject: Plotting Arc in Matlab

From: John D'Errico

Date: 20 Feb, 2007 23:23:04

Message: 7 of 16

Daniel wrote:
> Thanks,
>
> but your solution suggest you know the center of the circle and the
> number of degrees you want to plot. I only know begin[x,y] end[x,y]
> and radius of curvature.

As I suggested before, there are two
solutions to the arc.

You have not explained which arc is
to be chosen. Knowledge of the center
will eliminate the ambiguity.

John

Subject: Plotting Arc in Matlab

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 21 Feb, 2007 04:27:39

Message: 8 of 16

In article <1172026942.177795.138250@h3g2000cwc.googlegroups.com>,
Daniel <vanhengel@gmail.com> wrote:

>Hopefully this is an easy question to answer:

>How can you plot a part of a circle (arc) when begin point, end point
>and radius of the arc is known.

If those values are the only ones known, then the arc is underspecified
even in cartesian coordinates (and on the surface of a sphere,
for example, there would be an infinite number of solutions.)
You need at least one extra piece of information, such as that the
two points are to be connected by a counter-clockwise arc.
--
  "It is important to remember that when it comes to law, computers
  never make copies, only human beings make copies. Computers are given
  commands, not permission. Only people can be given permission."
                                               -- Brad Templeton

Subject: Plotting Arc in Matlab

From: Daniel

Date: 20 Feb, 2007 20:33:38

Message: 9 of 16

On Feb 21, 3:27 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
> In article <1172026942.177795.138...@h3g2000cwc.googlegroups.com>,
>
> Daniel <vanhen...@gmail.com> wrote:
> >Hopefully this is an easy question to answer:
> >How can you plot a part of a circle (arc) when begin point, end point
> >and radius of the arc is known.
>
> If those values are the only ones known, then the arc is underspecified
> even in cartesian coordinates (and on the surface of a sphere,
> for example, there would be an infinite number of solutions.)
> You need at least one extra piece of information, such as that the
> two points are to be connected by a counter-clockwise arc.
> --
> "It is important to remember that when it comes to law, computers
> never make copies, only human beings make copies. Computers are given
> commands, not permission. Only people can be given permission."
> -- Brad Templeton

Yes, sorry, you're right. I can specify if the arc should be a
(counter)clockwise arc. This should reduce the ambiguity. Thanks for
your patience.

Daniel

Subject: Plotting Arc in Matlab

From: us

Date: 20 Feb, 2007 23:41:10

Message: 10 of 16

Daniel:
<SNIP <us> provided bad solution...

> but your solution suggest you know the center of the circle and the
number of degrees you want to plot. I only know begin[x,y] end[x,y]
and radius of curvature...

yes, i obviously misread your OP!
sorry for having been careless...
us

Subject: Plotting Arc in Matlab

From: Daniel

Date: 20 Feb, 2007 21:40:30

Message: 11 of 16

On Feb 21, 3:33 pm, "Daniel" <vanhen...@gmail.com> wrote:
> On Feb 21, 3:27 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
> wrote:
>
>
>
>
>
> > In article <1172026942.177795.138...@h3g2000cwc.googlegroups.com>,
>
> > Daniel <vanhen...@gmail.com> wrote:
> > >Hopefully this is an easy question to answer:
> > >How can you plot a part of a circle (arc) when begin point, end point
> > >and radius of thearcis known.
>
> > If those values are the only ones known, then thearcis underspecified
> > even in cartesian coordinates (and on the surface of a sphere,
> > for example, there would be an infinite number of solutions.)
> > You need at least one extra piece of information, such as that the
> > two points are to be connected by a counter-clockwisearc.
> > --
> > "It is important to remember that when it comes to law, computers
> > never make copies, only human beings make copies. Computers are given
> > commands, not permission. Only people can be given permission."
> > -- Brad Templeton
>
> Yes, sorry, you're right. I can specify if thearcshould be a
> (counter)clockwisearc. This should reduce the ambiguity. Thanks for
> your patience.
>
> Daniel- Hide quoted text -
>
> - Show quoted text -

Okay, now I know the arc length too. So how can I create an arc when
knowing:

begin(x,y)
end(x,y)
radius of curvature
arc length
clockwise or counterclockwise arc

Any help would be sincerely appreciated

Daniel

Subject: Plotting Arc in Matlab

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 21 Feb, 2007 08:39:50

Message: 12 of 16

In article <1172036429.833451.114930@v45g2000cwv.googlegroups.com>,
Daniel <vanhengel@gmail.com> wrote:

>Okay, now I know the arc length too. So how can I create an arc when
>knowing:

>begin(x,y)
>end(x,y)
>radius of curvature
>arc length
>clockwise or counterclockwise arc

I don't think you know the arc length.

What you could do is solve the simultaneous equations,
  (x1-xc)^2+(y1-yc)^2=R^2
  (x2-xc)^2+(y2-yc)^2=R^2
for xc and yc.

There might perhaps be a simple solution; when I put it through
Maple, the solution comes out kind of messy. It simplifies in
interesting ways if you look at the difference between x1 and x2,
and y1 and y2. Either way, you get two solutions, one of which
will be for the clockwise arc, and the other for counterclockwise.

e.g.,

Let Dy2 = (y2-y1)
Let Dr^2 = (x2-x1)^2+(y2-y1)^2
then
yc = ((y2+y1)+(Dx2^2*Dr^2*(4*R^2-Dr^2))^(1/2))/(2*Dr^2)
(if I've resubstituted correctly)

xc is messier, at least without a bunch of simplification
steps that it's too late at night to think of doing.
--
  "It is important to remember that when it comes to law, computers
  never make copies, only human beings make copies. Computers are given
  commands, not permission. Only people can be given permission."
                                               -- Brad Templeton

Subject: Plotting Arc in Matlab

From: John D'Errico

Date: 21 Feb, 2007 06:39:02

Message: 13 of 16

Walter Roberson wrote:
>
>
> In article
<1172036429.833451.114930@v45g2000cwv.googlegroups.com>,
> Daniel <vanhengel@gmail.com> wrote:
>
>>Okay, now I know the arc length too. So how can I create an arc
> when
>>knowing:
>
>>begin(x,y)
>>end(x,y)
>>radius of curvature
>>arc length
>>clockwise or counterclockwise arc
>
> I don't think you know the arc length.
>
> What you could do is solve the simultaneous equations,
> (x1-xc)^2+(y1-yc)^2=R^2
> (x2-xc)^2+(y2-yc)^2=R^2
> for xc and yc.
>
> There might perhaps be a simple solution; when I put it through
> Maple, the solution comes out kind of messy. It simplifies in
> interesting ways if you look at the difference between x1 and x2,
> and y1 and y2. Either way, you get two solutions, one of which
> will be for the clockwise arc, and the other for counterclockwise.
>
> e.g.,
>
> Let Dy2 = (y2-y1)
> Let Dr^2 = (x2-x1)^2+(y2-y1)^2
> then
> yc = ((y2+y1)+(Dx2^2*Dr^2*(4*R^2-Dr^2))^(1/2))/(2*Dr^2)
> (if I've resubstituted correctly)
>
> xc is messier, at least without a bunch of simplification
> steps that it's too late at night to think of doing.
> --
> "It is important to remember that when it comes to law, computers
> never make copies, only human beings make copies. Computers are
> given
> commands, not permission. Only people can be given permission."
> -- Brad Templeton
>
  
Law of cosines is a nice trick here.
I know, it hurts my head too to go
all the way back to high school trig.

Given two arbitrary points in the
plane (label them A and B), and a
third point at a known radius R,
label it C.

ABC forms a triangle, with three
sides of length [R,R,norm(A-B)]. Yes?

First, what is the angle between edges
CA and CB? Yes, Law of cosines. It
reduces here to

  (norm(A-B))^2 = 2*R^2(1-cos(theta))

Solve for theta. A little more algebra
and we are done. Lets put it together
with an example.

% Pick 2 arbitrary points in the plane.
A = [0 1]; A = rand(1,2);
B = [2 2]; B = rand(1,2);

% The distance between A and B is...
norm(A-B)
% ans =
% 2.2361
% or sqrt(5) if you prefer.

% Choose a radius of 2 for our circle
R = 2; R = 1;

% the angle theta (in radians)
theta = acos(1-(norm(A-B)^2/2/R^2))
% theta =
% 1.1864

% in degrees...
theta*180/pi
% ans =
% 67.976

% Now, find C. There are two solutions.
% Surprise! N is a normal vector to the
% line AB.
N = (A-B)*[0 -1;1 0];
N = N/norm(N);

% one of them is
C1 = (A+B)/2 + N*R*cos(theta/2)
% C1 =
% 0.25838 2.9832

% convince ourselves that C1 is a solution.
norm(C1-B)
% ans =
% 2
norm(C1-A)
% ans =
% 2

% the other colution is
C2 = (A+B)/2 - N*R*cos(theta/2)

% Draw the circular arcs now, one for
% each center.
n = 200;
t = linspace(0,theta,n)';

phi1 = atan2(A(2)-C1(2), A(1)-C1(1));
xy1 = repmat(C1,n,1)+R*[cos(t+phi1),sin(t+phi1)];

phi2 = atan2(A(2)-C2(2), A(1)-C2(1));
xy2 = repmat(C2,n,1)+R*[cos(-t+phi2),sin(-t+phi2)];

% and plot the whole mess.
plot([A(1),B(1)],[A(2),B(2)],'r-o')
hold on
plot(C1(1),C1(2),'g+',C2(1),C2(2),'b+')
axis equal

plot(xy1(:,1),xy1(:,2),'g-',xy2(:,1),xy2(:,2),'b-')
plot([A(1),C1(1)],[A(2),C1(2)],'g-')
plot([B(1),C1(1)],[B(2),C1(2)],'g-')
plot([A(1),C2(1)],[A(2),C2(2)],'b-')
plot([B(1),C2(1)],[B(2),C2(2)],'b-')

hold off
grid on

John

Subject: Plotting Arc in Matlab

From: Duane Hanselman

Date: 21 Feb, 2007 09:57:41

Message: 14 of 16

Daniel wrote:
>
>
> Hi,
>
> Hopefully this is an easy question to answer:
>
> How can you plot a part of a circle (arc) when begin point, end
> point
> and radius of the arc is known.
>
> I looked around but haven't yet found the solution
>
> Thanks,
>
> Daniel
>
>
  

There is a function in the MATLAB File Exchange that does what you
want.

 <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4082&objectType=file>

Duane

Subject: Plotting Arc in Matlab

From: ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)

Date: 21 Feb, 2007 19:10:45

Message: 15 of 16

In article <1172032417.970378.161210@s48g2000cws.googlegroups.com>,
"Daniel" <vanhengel@gmail.com> wrote:

> > Daniel <vanhen...@gmail.com> wrote:
> > >Hopefully this is an easy question to answer:
> > >How can you plot a part of a circle (arc) when begin point, end point
> > >and radius of the arc is known.
> >
> Yes, sorry, you're right. I can specify if the arc should be a
> (counter)clockwise arc. This should reduce the ambiguity. Thanks for
> your patience.
>
> Daniel
-----------------------
  Even though John and Duane have given you solutions to your problem,
Daniel, I cannot resist giving one in a more condensed form. If (x1,y1)
and (x2,y2) are the beginning and end points, respectively, and r the
radius of the desired arc which is to bend in a counterclockwise
direction, then do this:

d = sqrt((x2-x1)^2+(y2-y1)^2); % Distance between points
a = atan2(-(x2-x1),y2-y1); % Perpendicular bisector angle
b = asin(d/2/r); % Half arc angle
c = linspace(a-b,a+b); % Arc angle range
e = sqrt(r^2-d^2/4); % Distance, center to midpoint
x = (x1+x2)/2-e*cos(a)+r*cos(c); % Cartesian coords. of arc
y = (y1+y2)/2-e*sin(a)+r*sin(c);
plot(x,y,'y.',x1,y1,'r*',x2,y2,'b*')
axis equal

  If you want the bending to go clockwise, just change the second line to:

a = atan2(x2-x1,-(y2-y1));

Roger Stafford

Subject: Plotting Arc in Matlab

From: Daniel

Date: 21 Feb, 2007 19:36:52

Message: 16 of 16

On Feb 22, 6:10 am, ellieandrogerxy...@mindspring.com.invalid (Roger
Stafford) wrote:
> In article <1172032417.970378.161...@s48g2000cws.googlegroups.com>,
>
> "Daniel" <vanhen...@gmail.com> wrote:
> > > Daniel <vanhen...@gmail.com> wrote:
> > > >Hopefully this is an easy question to answer:
> > > >How can you plot a part of a circle (arc) when begin point, end point
> > > >and radius of the arc is known.
>
> > Yes, sorry, you're right. I can specify if the arc should be a
> > (counter)clockwise arc. This should reduce the ambiguity. Thanks for
> > your patience.
>
> > Daniel
>
> -----------------------
> Even though John and Duane have given you solutions to your problem,
> Daniel, I cannot resist giving one in a more condensed form. If (x1,y1)
> and (x2,y2) are the beginning and end points, respectively, and r the
> radius of the desired arc which is to bend in a counterclockwise
> direction, then do this:
>
> d = sqrt((x2-x1)^2+(y2-y1)^2); % Distance between points
> a = atan2(-(x2-x1),y2-y1); % Perpendicular bisector angle
> b = asin(d/2/r); % Half arc angle
> c = linspace(a-b,a+b); % Arc angle range
> e = sqrt(r^2-d^2/4); % Distance, center to midpoint
> x = (x1+x2)/2-e*cos(a)+r*cos(c); % Cartesian coords. of arc
> y = (y1+y2)/2-e*sin(a)+r*sin(c);
> plot(x,y,'y.',x1,y1,'r*',x2,y2,'b*')
> axis equal
>
> If you want the bending to go clockwise, just change the second line to:
>
> a = atan2(x2-x1,-(y2-y1));
>
> Roger Stafford

Roger, your code works beautifully, thanks!

Everyone else thanks for replies too!

Daniel

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us