Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to draw an arc between two points given centre and radius

1,626 views
Skip to first unread message

Chanpreet

unread,
Mar 30, 2010, 3:19:05 PM3/30/10
to
how to draw an arc between two points given centre and radius on matlab

Walter Roberson

unread,
Mar 30, 2010, 3:41:08 PM3/30/10
to
Chanpreet wrote:
> how to draw an arc between two points given centre and radius on matlab

If you are given the two points, and given the centre and radius, then you
cannot always do that. The distance from the centre and each of the points
define radii, and if those two radii are not equal or are not equal to the
given radius, then you cannot draw a circular arc.

The circular arcs that pass through any two given points define a line. If the
centre is not on that line, you cannot do what you ask. Only one coordinate of
the centre would need to be given, and the radius would not be needed. If,
alternately, the radius were given, then that would narrow it to one of
exactly two points, and the only reason the centre would need to be given
would be to distinguish which of the two points it was.

Did you have something different in mind, such as a non-circular arc? Perhaps
a parabolic arc, and the centre is really the focus?


Anyhow...


You can use arctan to find the sector angle to be drawn. Be sure to check in
case you are crossing over the periodic boundary, as you probably want to draw
the smaller of the two arcs. Then, knowing the angles involved, linspace() the
angle range into an appropriate number of points, and then the points of the
arc are

[radius * cos(theta_range) + x of centre, radius * sin(theta_range) + y of
centre)]

Roger Stafford

unread,
Mar 30, 2010, 7:02:21 PM3/30/10
to
"Chanpreet " <c.k...@tue.nl> wrote in message <hotir8$8a8$1...@fred.mathworks.com>...

> how to draw an arc between two points given centre and radius on matlab

Assuming you are in two dimensions, let your two points be the column vectors P1 = [x1;y1], and P2 = [x2;y2], and let the center be P0 = [x0;y0]. Then an arc between P1 and P2 with P0 as its center can be drawn by:

n = 1000; % The number of points in the arc
v1 = P1-P0;
v2 = P2-P0;
c = det([v1,v2]); % "cross product" of v1 and v2
a = linspace(0,atan2(abs(c),dot(v1,v2)),n); % Angle range
v3 = [0,-c;c,0]*v1; % v3 lies in plane of v1 and v2 and is orthog. to v1
v = v1*cos(a)+((norm(v1)/norm(v3))*v3)*sin(a); % Arc, center at (0,0)
plot(v(1,:)+x0,v(2,:)+y0,'y.') % Plot arc, centered at P0
axis equal

Note that it is assumed here that P2 is the same distance from P0 as is P1. If not, the arc will miss P2, though its endpoint will be on the line through P0 and P2.

Roger Stafford

Roger Stafford

unread,
Mar 30, 2010, 9:13:07 PM3/30/10
to
> "Chanpreet " <c.k...@tue.nl> wrote in message <hotir8$8a8$1...@fred.mathworks.com>...
> > how to draw an arc between two points given centre and radius on matlab

I should have added that if you are working with three dimensional space rather than two, a method of generating the arc was given in a thread yesterday at:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/277881

Roger Stafford

Brian

unread,
Apr 2, 2012, 6:55:15 PM4/2/12
to
"Roger Stafford" wrote in message <hotvtt$gdr$1...@fred.mathworks.com>...
> v = v1*cos(a)+((norm(v1)/norm(v3))*v3)*sin(a); % Arc, center at (0,0)

Excellent, elegant routine. Thanks for your effort.

But, the calculation fails if all three points are on the same line, as when drawing a semicircle. The calculation above results in a NaN for each element of v1. Any suggestions?

-Brian Callahan

ImageAnalyst

unread,
Apr 2, 2012, 7:24:28 PM4/2/12
to
On Apr 2, 6:55 pm, "Brian " <br1...@hotmail.com> wrote:
> "Roger Stafford" wrote in message <hotvtt$gd...@fred.mathworks.com>...
> >  v  = v1*cos(a)+((norm(v1)/norm(v3))*v3)*sin(a); % Arc, center at (0,0)
>
> Excellent, elegant routine. Thanks for your effort.
>
> But, the calculation fails if all three points are on the same line, as when drawing a semicircle. The calculation above results in a NaN for each element of v1. Any suggestions?
>
> -Brian Callahan

---------------------------------------------------------------
Exactly which 3 points are you drawing when you draw your
semicircle??? On the line that cuts across the diameter? That's the
only straight line. No points on the arc are in a line unless it's of
infinite radius.

Brian

unread,
Apr 2, 2012, 8:10:11 PM4/2/12
to
What about changing the statement to add this conditional?

if c==0 % semicircle
v3=[0 -1;1 0]*v1; % v1 rotated 90 degrees CCW
else
v3 = [0,-c;c,0]*v1; % v3 lies in plane of v1 and v2 and is orthog. to v1
end

This results in a counterclockwise semicircle from P1 around the center point. If you want the semicircle the other way, then swap P1 and P2.

This approach does not allow "missing" the P2 point and drawing the semicircle clockwise, though.

Brian

unread,
Apr 2, 2012, 8:20:12 PM4/2/12
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <0e6f9cf3-a0f0-4e69...@z17g2000yqf.googlegroups.com>...
> Exactly which 3 points are you drawing when you draw your
> semicircle??? On the line that cuts across the diameter? That's the
> only straight line. No points on the arc are in a line unless it's of
> infinite radius.

The original poster requested a routine intended to draw an arc from a start point to an end point around a center point, not an arc through three points...

Roger Stafford

unread,
Apr 2, 2012, 9:27:10 PM4/2/12
to
"Brian" wrote in message <jldf53$il7$1...@newscl01ah.mathworks.com>...
- - - - - - - - -
In 2D as the points approach a straight line the problem becomes computationally unstable, which reflects the growing uncertainty as to which of two arcs is to be followed. In 3D, it would be a particularly ill-defined problem since there are infinitely many possible arcs in that case.

(By the way, v1 does not become NaNs. It is v3/norm(v3) that makes v have NaNs.)

If it is understood that the arc is to be unconditionally drawn counterclockwise from P1 with P0 as center until reaching P2 no matter which way P2 points, you would do this:

v1 = P1-P0;
v2 = P2-P0;
v3 = [0 -1;1 0]*v1; % (as you suggested)
a = linspace(0,mod(atan2(det([v1,v2]),dot(v1,v2)),2*pi));
% Note the absence of the 'abs' function in 'atan2'
v = v1*cos(a)+v3*sin(a);
plot(v(1,:)+P0(1),v(2,:)+P0(2),'y.')
axis equal

Here the angle 'a' can range anywhere from 0 to 2*pi.

Roger Stafford

Muhammad nasiri

unread,
Aug 24, 2015, 3:52:13 AM8/24/15
to
"Chanpreet " <c.k...@tue.nl> wrote in message <hotir8$8a8$1...@fred.mathworks.com>...
> how to draw an arc between two points given centre and radius on matlab

if you want to draw semi circle, here you go:

r1=100;
t= -pi: pi/500 : 0;
x1=r1*cos(t);
y1=r1*sin(t);
plot(x1,y1,'b')

you can change value of t, x1, and y1, to draw your own required arc

thanks
0 new messages