Got Questions? Get Answers.
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:
matlab (given three points , how to find a circular arc. )

Subject: matlab (given three points , how to find a circular arc. )

From: taesun park

Date: 22 Nov, 2010 17:40:08

Message: 1 of 14

given three points , how to find a circular arc.

there is 3 points.

p1(x1,y1) p2(x2,y2) p3(x3,y3)


I have to find arc of the 3 point connection.


plz, help me. I have to finish this work until tommorrow.

Subject: matlab (given three points , how to find a circular arc. )

From: Roger Stafford

Date: 22 Nov, 2010 18:08:03

Message: 2 of 14

"taesun park" <ts10004ok@hanmail.net> wrote in message <ice9to$5uu$1@fred.mathworks.com>...
> given three points , how to find a circular arc. there is 3 points.
> p1(x1,y1) p2(x2,y2) p3(x3,y3)
> I have to find arc of the 3 point connection.
> .......
- - - - - - - - - -
  My contribution to this thread might be of assistance:

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

Roger Stafford

Subject: matlab (given three points , how to find a circular arc. )

From: taesun park

Date: 22 Nov, 2010 18:19:04

Message: 3 of 14

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <icebi3$n6i$1@fred.mathworks.com>...
> "taesun park" <ts10004ok@hanmail.net> wrote in message <ice9to$5uu$1@fred.mathworks.com>...
> > given three points , how to find a circular arc. there is 3 points.
> > p1(x1,y1) p2(x2,y2) p3(x3,y3)
> > I have to find arc of the 3 point connection.
> > .......
> - - - - - - - - - -
> My contribution to this thread might be of assistance:
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/294297
>
> Roger Stafford

thank for your help.
but i cant understand about that exactly.
couly you plz write down new answer clearly??

Subject: matlab (given three points , how to find a circular arc. )

From: Roger Stafford

Date: 22 Nov, 2010 18:46:04

Message: 4 of 14

"taesun park" <ts10004ok@hanmail.net> wrote in message <icec6o$6rf$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <icebi3$n6i$1@fred.mathworks.com>...
> > http://www.mathworks.com/matlabcentral/newsreader/view_thread/294297
> thank for your help.
> but i cant understand about that exactly.
> couly you plz write down new answer clearly??
- - - - - - - -
 Look at the fourth article in that thread at the part that begins, "Below is a somewhat more direct way of solving the three-point problem."

Roger Stafford

Subject: matlab (given three points , how to find a circular arc. )

From: taesun park

Date: 22 Nov, 2010 19:03:03

Message: 5 of 14

sorry . this is m-file. but this is no correct

so could you plz change to correct??? And If you find answer. just check like this

for example
dddddd <<<<<<<< like this

 i am so sorry. thank you for your effort
=========================================

function case1(x1,y1,x2,y2,x3,y3)
xc=(((x2-x3)/(y2-y3))*((x2+x3)/2)+(y2+y3)/2-((x1-x2)/(y1-y2))*((x1+x2)/2)-((y1+y2)/2))/(((x2-x3)/(y2-y3))-((x1-x2)/(y1-y2)))
yc=-((x1-x2)/(y1-y2))*(xc-((x1+x2)/2))+((y1+y2)/2)

a1=atan((y1-yc)/(x1-xc))
a2=atan((y3-yc)/(x3-xc))

if x1<xc
a2 = a2 +pi;
end

r=sqrt((x1-xc)^2+(y1-yc)^2)

th = linspace( a1 , a2 , 20);
D = (x2-x1)*(y2-y1);
if D > 0
    Px = xc - r*cos(th);
    Py = yc - r*sin(th);
elseif D < 0
   Px = xc + r*cos(th);
   Py = yc + r*sin(th);
elseif D==0
    if (x3-x1)*(y3-y1)>0
        Px = xc - r*cos(th);
        Py = yc - r*sin(th);
    else
        Px = xc + r*cos(th);
       Py = yc + r*sin(th);
   end
 
end


plot(Px,Py), axis([xc-r xc+r yc-r yc+r]),grid on)

Subject: matlab (given three points , how to find a circular arc. )

From: ImageAnalyst

Date: 22 Nov, 2010 21:36:37

Message: 6 of 14

What exactly does this mean?

"for example
dddddd <<<<<<<< like this "

Subject: matlab (given three points , how to find a circular arc. )

From: taesun park

Date: 23 Nov, 2010 03:05:04

Message: 7 of 14

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <54f724d9-eb69-4c76-bbfa-dccafe2b6247@30g2000yql.googlegroups.com>...
> What exactly does this mean?
>
> "for example
> dddddd <<<<<<<< like this "



dont confuse about it.
that is mark what you will change form.

Subject: matlab (given three points , how to find a circular arc. )

From: Greg Heath

Date: 23 Nov, 2010 05:35:43

Message: 8 of 14

On Nov 22, 12:40 pm, "taesun park" <ts1000...@hanmail.net> wrote:
> given three points , how to find a circular arc.
>
> there is 3 points.
>
> p1(x1,y1) p2(x2,y2) p3(x3,y3)
>
> I have to find arc of the 3 point connection.
>
> plz, help me. I have to finish this work until tommorrow.

(xi-x0)^2 + (yi-y0)^2 = a^2, i = 1,2,3

Solve for (x0,y0,a^2)

If x0 and y0 are known, any of the
above 3 equations yields a^2.

x0 and y0 are obtained from the two linear
equations resulting from subtracting
equations 2 and 3 from equation 1.

Hope this helps.

Greg

Subject: matlab (given three points , how to find a circular arc. )

From: Roger Stafford

Date: 23 Nov, 2010 07:00:06

Message: 9 of 14

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <icedpc$krt$1@fred.mathworks.com>...
> Look at the fourth article in that thread ......
- - - - - - - - -
  My apologies. I meant the seventh article, not the fourth article, in the thread I mentioned earlier. Here is the pertinent part of that seventh article:

  "... the three given points on the circle are (x1,y1), (x2,y2), and (x3,y3).

x21 = x2-x1; y21 = y2-y1;
x31 = x3-x1; y31 = y3-y1;
h21 = x21^2+y21^2; h31 = x31^2+y31^2;
d = 2*(x21*y31-x31*y21);
a = x1+(h21*y31-h31*y21)/d;
b = y1-(h21*x31-h31*x21)/d;
r = sqrt(h21*h31*((x3-x2)^2+(y3-y2)^2))/abs(d);

The circle's center is at (a,b) and its radius is r."

  These three quantities determine the circle you have asked for.

Roger Stafford

Subject: matlab (given three points , how to find a circular arc. )

From: Sam park

Date: 23 Nov, 2010 09:00:06

Message: 10 of 14

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <icfopm$8p7$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <icedpc$krt$1@fred.mathworks.com>...
> > Look at the fourth article in that thread ......
> - - - - - - - - -
> My apologies. I meant the seventh article, not the fourth article, in the thread I mentioned earlier. Here is the pertinent part of that seventh article:
>
> "... the three given points on the circle are (x1,y1), (x2,y2), and (x3,y3).
>
> x21 = x2-x1; y21 = y2-y1;
> x31 = x3-x1; y31 = y3-y1;
> h21 = x21^2+y21^2; h31 = x31^2+y31^2;
> d = 2*(x21*y31-x31*y21);
> a = x1+(h21*y31-h31*y21)/d;
> b = y1-(h21*x31-h31*x21)/d;
> r = sqrt(h21*h31*((x3-x2)^2+(y3-y2)^2))/abs(d);
>
> The circle's center is at (a,b) and its radius is r."
>
> These three quantities determine the circle you have asked for.
>
> Roger Stafford

thank you very much. i will try to that.
if i cant solve this problem . i will ask for another answer. ^^

Subject: matlab (given three points , how to find a circular arc. )

From: Sam park

Date: 23 Nov, 2010 14:14:04

Message: 11 of 14

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <icfopm$8p7$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <icedpc$krt$1@fred.mathworks.com>...
> > Look at the fourth article in that thread ......
> - - - - - - - - -
> My apologies. I meant the seventh article, not the fourth article, in the thread I mentioned earlier. Here is the pertinent part of that seventh article:
>
> "... the three given points on the circle are (x1,y1), (x2,y2), and (x3,y3).
>
> x21 = x2-x1; y21 = y2-y1;
> x31 = x3-x1; y31 = y3-y1;
> h21 = x21^2+y21^2; h31 = x31^2+y31^2;
> d = 2*(x21*y31-x31*y21);
> a = x1+(h21*y31-h31*y21)/d;
> b = y1-(h21*x31-h31*x21)/d;
> r = sqrt(h21*h31*((x3-x2)^2+(y3-y2)^2))/abs(d);
>
> The circle's center is at (a,b) and its radius is r."
>
> These three quantities determine the circle you have asked for.
>
> Roger Stafford
=====================================
function case1(x1,y1,x2,y2,x3,y3)
 

 x21 = x2-x1; y21 = y2-y1;
 x31 = x3-x1; y31 = y3-y1;
 
 
 h21 = x21^2+y21^2; h31 = x31^2+y31^2;
 d = 2*(x21*y31-x31*y21);
 a = x1+(h21*y31-h31*y21)/d;
 b = y1-(h21*x31-h31*x21)/d;


 r = sqrt(h21*h31*((x3-x2)^2+(y3-y2)^2))/abs(d);

 
a1=atan((y1-b)/(x1-a))
a2=atan((y3-b)/(x3-a))

th=0;

if x1<a
a2 = a2 -2*pi;
end

r=sqrt((x1-a)^2+(y1-b)^2)

th = linspace( a1 , a2 , 1000);
D = (x2-x1)*(y2-y1);
if D > 0
    Px = a - r*cos(th);
    Py = b - r*sin(th);
elseif D < 0
   Px = a + r*cos(th);
   Py = b + r*sin(th);
elseif D==0
    if (x3-x1)*(y3-y1)>0
        Px = a - r*cos(th);
        Py = b - r*sin(th);
    else
        Px = a + r*cos(th);
       Py = b + r*sin(th);
   end
 
end


plot(Px,Py), grid on
=====================================
excuse Roger Stafford. i have failed this problem TT in matlab.
, for example, in this case (x1=x2) i type case1(3,4,3,6,6,5) In matlab<<<
. i cant obtain graph in matlab. that is error.

thanks for your effort

Subject: matlab (given three points , how to find a circular arc. )

From: Roger Stafford

Date: 23 Nov, 2010 18:22:04

Message: 12 of 14

"Sam park" <ts10004ok@hanmail.net> wrote in message <icgi7c$iva$1@fred.mathworks.com>...
> ........
> excuse Roger Stafford. i have failed this problem TT in matlab.
> , for example, in this case (x1=x2) i type case1(3,4,3,6,6,5) In matlab<<<
> . i cant obtain graph in matlab. that is error.
> thanks for your effort
- - - - - - - - - - -
  I'm sorry you still have trouble plotting the circular arc. Based on the code you show I am guessing you are attempting to draw the arc starting with P1 = (x1,y1), passing through P2 = (x2,y2), and ending up at P3 = (x3,y3) no matter how they may be oriented. Here are some observations about your code.

  First you should be using atan2 rather than atan, because atan2 gives a result that ranges from -pi to +pi which is what you need here rather than atan's more limited range of -pi/2 to +pi/2. It's very messy having to correct for all the eventualities that occur with atan.

  Second, the quantity d in my code is equal four times the signed area of the triangle with P1, P2, and P3 as vertices. You can use the sign of d as an indication of which direction your desired arc should take from P1 to P3 so as to pass through P2. If d > 0, it should be counterclockwise, and otherwise clockwise.

  I include code here using atan2 which would trace the arc according to the above guess. The (sign(d)-sign(a3-a1))*pi correction on a3 is designed to add or subtract 2*pi to or from a3 if needed to make the arc tracing go in the proper direction. For example if both d and a3-a1 are positive, no correction is needed. If d is negative and a3-a1 is positive this subtracts 2*pi from a3, which is what would be needed to force a backward (clockwise) direction. When a3-a1 is negative, 2*pi is added to force a counterclockwise direction if d is positive. With both negative, again no correction is needed.

  If my guess is wrong, perhaps some of this code would still give you some good ideas?

  Here is the code:

% Previous code
 x21 = x2-x1; y21 = y2-y1;
 x31 = x3-x1; y31 = y3-y1;
 h21 = x21^2+y21^2; h31 = x31^2+y31^2;
 d = 2*(x21*y31-x31*y21);
 a = x1+(h21*y31-h31*y21)/d;
 b = y1-(h21*x31-h31*x21)/d;
 r = sqrt(h21*h31*((x3-x2)^2+(y3-y2)^2))/abs(d);

% Preparations for plotting
 a1 = atan2(y1-b,x1-a); % Angle counterclockwise from x-axis to P1
 a3 = atan2(y3-b,x3-a); % Angle counterclockwise from x-axis to P3
 a3 = a3+(sign(d)-sign(a3-a1))*pi; % Make needed correction on a3
 t = linspace(a1,a3,1000); % Make plot go from P1 to P3 through P2
 x = a+r*cos(t); % Use x and y for your plot
 y = b+r*sin(t);

Now do the plot with x and y. Use "axis equal" to get a true circular plot.

Roger Stafford

Subject: matlab (given three points , how to find a circular arc. )

From: Sam park

Date: 23 Nov, 2010 18:34:05

Message: 13 of 14

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ich0oc$pn8$1@fred.mathworks.com>...
> "Sam park" <ts10004ok@hanmail.net> wrote in message <icgi7c$iva$1@fred.mathworks.com>...
> > ........
> > excuse Roger Stafford. i have failed this problem TT in matlab.
> > , for example, in this case (x1=x2) i type case1(3,4,3,6,6,5) In matlab<<<
> > . i cant obtain graph in matlab. that is error.
> > thanks for your effort
> - - - - - - - - - - -
> I'm sorry you still have trouble plotting the circular arc. Based on the code you show I am guessing you are attempting to draw the arc starting with P1 = (x1,y1), passing through P2 = (x2,y2), and ending up at P3 = (x3,y3) no matter how they may be oriented. Here are some observations about your code.
>
> First you should be using atan2 rather than atan, because atan2 gives a result that ranges from -pi to +pi which is what you need here rather than atan's more limited range of -pi/2 to +pi/2. It's very messy having to correct for all the eventualities that occur with atan.
>
> Second, the quantity d in my code is equal four times the signed area of the triangle with P1, P2, and P3 as vertices. You can use the sign of d as an indication of which direction your desired arc should take from P1 to P3 so as to pass through P2. If d > 0, it should be counterclockwise, and otherwise clockwise.
>
> I include code here using atan2 which would trace the arc according to the above guess. The (sign(d)-sign(a3-a1))*pi correction on a3 is designed to add or subtract 2*pi to or from a3 if needed to make the arc tracing go in the proper direction. For example if both d and a3-a1 are positive, no correction is needed. If d is negative and a3-a1 is positive this subtracts 2*pi from a3, which is what would be needed to force a backward (clockwise) direction. When a3-a1 is negative, 2*pi is added to force a counterclockwise direction if d is positive. With both negative, again no correction is needed.
>
> If my guess is wrong, perhaps some of this code would still give you some good ideas?
>
> Here is the code:
>
> % Previous code
> x21 = x2-x1; y21 = y2-y1;
> x31 = x3-x1; y31 = y3-y1;
> h21 = x21^2+y21^2; h31 = x31^2+y31^2;
> d = 2*(x21*y31-x31*y21);
> a = x1+(h21*y31-h31*y21)/d;
> b = y1-(h21*x31-h31*x21)/d;
> r = sqrt(h21*h31*((x3-x2)^2+(y3-y2)^2))/abs(d);
>
> % Preparations for plotting
> a1 = atan2(y1-b,x1-a); % Angle counterclockwise from x-axis to P1
> a3 = atan2(y3-b,x3-a); % Angle counterclockwise from x-axis to P3
> a3 = a3+(sign(d)-sign(a3-a1))*pi; % Make needed correction on a3
> t = linspace(a1,a3,1000); % Make plot go from P1 to P3 through P2
> x = a+r*cos(t); % Use x and y for your plot
> y = b+r*sin(t);
>
> Now do the plot with x and y. Use "axis equal" to get a true circular plot.
>
> Roger Stafford

Thanks for your effort. God bless you.^^ I will challage this problem again^^

Subject: matlab (given three points , how to find a circular arc. )

From: Sam park

Date: 23 Nov, 2010 18:50:07

Message: 14 of 14

"Sam park" <ts10004ok@hanmail.net> wrote in message <ich1et$cab$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ich0oc$pn8$1@fred.mathworks.com>...
> > "Sam park" <ts10004ok@hanmail.net> wrote in message <icgi7c$iva$1@fred.mathworks.com>...
> > > ........
> > > excuse Roger Stafford. i have failed this problem TT in matlab.
> > > , for example, in this case (x1=x2) i type case1(3,4,3,6,6,5) In matlab<<<
> > > . i cant obtain graph in matlab. that is error.
> > > thanks for your effort
> > - - - - - - - - - - -
> > I'm sorry you still have trouble plotting the circular arc. Based on the code you show I am guessing you are attempting to draw the arc starting with P1 = (x1,y1), passing through P2 = (x2,y2), and ending up at P3 = (x3,y3) no matter how they may be oriented. Here are some observations about your code.
> >
> > First you should be using atan2 rather than atan, because atan2 gives a result that ranges from -pi to +pi which is what you need here rather than atan's more limited range of -pi/2 to +pi/2. It's very messy having to correct for all the eventualities that occur with atan.
> >
> > Second, the quantity d in my code is equal four times the signed area of the triangle with P1, P2, and P3 as vertices. You can use the sign of d as an indication of which direction your desired arc should take from P1 to P3 so as to pass through P2. If d > 0, it should be counterclockwise, and otherwise clockwise.
> >
> > I include code here using atan2 which would trace the arc according to the above guess. The (sign(d)-sign(a3-a1))*pi correction on a3 is designed to add or subtract 2*pi to or from a3 if needed to make the arc tracing go in the proper direction. For example if both d and a3-a1 are positive, no correction is needed. If d is negative and a3-a1 is positive this subtracts 2*pi from a3, which is what would be needed to force a backward (clockwise) direction. When a3-a1 is negative, 2*pi is added to force a counterclockwise direction if d is positive. With both negative, again no correction is needed.
> >
> > If my guess is wrong, perhaps some of this code would still give you some good ideas?
> >
> > Here is the code:
> >
> > % Previous code
> > x21 = x2-x1; y21 = y2-y1;
> > x31 = x3-x1; y31 = y3-y1;
> > h21 = x21^2+y21^2; h31 = x31^2+y31^2;
> > d = 2*(x21*y31-x31*y21);
> > a = x1+(h21*y31-h31*y21)/d;
> > b = y1-(h21*x31-h31*x21)/d;
> > r = sqrt(h21*h31*((x3-x2)^2+(y3-y2)^2))/abs(d);
> >
> > % Preparations for plotting
> > a1 = atan2(y1-b,x1-a); % Angle counterclockwise from x-axis to P1
> > a3 = atan2(y3-b,x3-a); % Angle counterclockwise from x-axis to P3
> > a3 = a3+(sign(d)-sign(a3-a1))*pi; % Make needed correction on a3
> > t = linspace(a1,a3,1000); % Make plot go from P1 to P3 through P2
> > x = a+r*cos(t); % Use x and y for your plot
> > y = b+r*sin(t);
> >
> > Now do the plot with x and y. Use "axis equal" to get a true circular plot.
> >
> > Roger Stafford
>
> Thanks for your effort. God bless you.^^ I will challage this problem again^^



Dear , Roger Stafford
If I have no your help. I cant solve this problem. thanks for your effort.
bless with you . thank you very much. I cant forget this situation forever.
thank you TT. If I have another problem in matlab. May I have your help?^^
Thank you so much.

Tags for 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