From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to draw an arc between two points given centre and radius
Date: Tue, 3 Apr 2012 01:27:10 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 31
Message-ID: <jldjle$1v3$>
References: <hotir8$8a8$> <hotvtt$gdr$> <jldaoj$6fu$> <jldf53$il7$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1333416430 2019 (3 Apr 2012 01:27:10 GMT)
NNTP-Posting-Date: Tue, 3 Apr 2012 01:27:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:763100

"Brian" wrote in message <jldf53$il7$>...
> 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.
- - - - - - - - -
  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);
 axis equal

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

Roger Stafford