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:
3d arc plotting

Subject: 3d arc plotting

From: satish sahu

Date: 27 Mar, 2012 10:18:14

Message: 1 of 2

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

Subject: 3d arc plotting

From: Roger Stafford

Date: 27 Mar, 2012 22:37:21

Message: 2 of 2

"satish sahu" <satishs@iitk.ac.in> wrote in message <jks456$jqq$1@newscl01ah.mathworks.com>...
> 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
plot3(T(:,1),T(:,2),T(:,3))

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

Roger Stafford

Tags for this Thread

No tags are associated with 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