From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: matlab (given three points , how to find a circular arc. )
Date: Tue, 23 Nov 2010 18:34:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 42
Message-ID: <ich1et$cab$>
References: <ice9to$5uu$> <icebi3$n6i$> <icec6o$6rf$> <icedpc$krt$> <icfopm$8p7$> <icgi7c$iva$> <ich0oc$pn8$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1290537245 12619 (23 Nov 2010 18:34:05 GMT)
NNTP-Posting-Date: Tue, 23 Nov 2010 18:34:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2625313
Xref: comp.soft-sys.matlab:689404

"Roger Stafford" <> wrote in message <ich0oc$pn8$>...
> "Sam park" <> wrote in message <icgi7c$iva$>...
> > ........
> > 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^^