From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 3d arc plotting
Date: Tue, 27 Mar 2012 22:37:21 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 38
Message-ID: <jktff1$jl7$>
References: <jks456$jqq$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1332887841 20135 (27 Mar 2012 22:37:21 GMT)
NNTP-Posting-Date: Tue, 27 Mar 2012 22:37:21 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:762386

"satish sahu" <> wrote in message <jks456$jqq$>...
> i have three point center point(p0), begin point(p1) and end point(p2).
> p0=(x0,y0,z0)
> p1=(x1,y1,z1)
> p2=(x2,y2,z2)
> want to plot arc on 3d,
> case(1)=(x0,y0,z0,x1,y1,z1,x2,y2,z2) all are known
> case(2)=(x0,y0,z0,x1,y1,z1,z2)  are known (x2 and y2 are unknown)
> plz reply
- - - - - - - - - -
  I assume that by "center point(p0)" you mean that p0 is to be at the center of a circular arc between p1 and p2.  In your case(2) the possible location of p2 is any point on the surface of a sphere with center at p0 and with norm(p1-p0) as radius.  That means that knowing only z2 is not sufficient to uniquely determine p2 - it could be anywhere in a ring at height z2.  Case(2) is not a well-formed problem.

  As for case(1) the following code should draw the arc.  It works even if p0 is not at the midpoint of the arc.

% The three points as row vectors
p0 = randn(1,3); p2 = randn(1,3); p1 = randn(1,3); % You choose p0,p1,p2

% The engine
t = p2-p0; u = p1-p0; v = p1-p2;
w = cross(t,u);
t2 = sum(t.^2); u2 = sum(u.^2); w2 = sum(w.^2);
c = p0+(t2*sum(u.*v)*u-u2*sum(t.*v)*t)/(2*w2); % <-- The center
r = 1/2*sqrt(t2*u2*sum(v.^2)/w2); % <-- The radius
a = p1-c; a = a/norm(a);
b = cross(w,a); b = b/norm(b);
n = 100;
ang = linspace(0,mod(atan2(dot(p2-c,b),dot(p2-c,a)),2*pi),n).';
T = bsxfun(@plus,r*(cos(ang)*a+sin(ang)*b),c);

% The plot of the circular arc from p1 to p2

You can add the points p0, p1, and p2 to this plot to verify that they are on the arc.

Roger Stafford