Path: news.mathworks.com!not-for-mail 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$1@newscl01ah.mathworks.com> References: <hotir8$8a8$1@fred.mathworks.com> <hotvtt$gdr$1@fred.mathworks.com> <jldaoj$6fu$1@newscl01ah.mathworks.com> <jldf53$il7$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1333416430 2019 172.30.248.47 (3 Apr 2012 01:27:10 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Tue, 3 Apr 2012 01:27:10 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:763100 "Brian" wrote in message <jldf53$il7$1@newscl01ah.mathworks.com>... > 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); 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