Quantcast
Viewing all articles
Browse latest Browse all 15

Re: sph2cart, orientation, lines and coordinates in 3d space / volume

"kees de Kapper" <kees_de_kapper@hotmail.com> wrote in message <lei5r4$421$1@newscl01ah.mathworks.com>...
> I'd like to get a circle around the coordinates of a line in 3D space. The planes of circles have to be oriented in the same direction as the line.
> .......
- - - - - - - - -
  I haven't the time to study your code to see what difficulties it has, but I have prepared a shorter method of doing the same thing.

  Let P and Q be 3 x 1 column vectors containing the x, y, z coordinates of the two points that define the line.

 r = 4; % Circles' radius
 v = null((P-Q)'); % Find two vectors orthogonal to the line & each other
 t = linspace(0,2*pi); % Let t sweep through a full circular angle
 c = r*(v(:,1)*cos(t) + v(:,2)*sin(t)); % Circle around the origin
 c1 = bsxfun(@plus,Q,c); % Circle around Q
 c2 = bsxfun(@plus,P,c); % Circle around P
 X1 = c1(1,:); Y1 = c1(2,:); Z1 = c1(3,:); % Separate x, y, z coords.
 X2 = c2(1,:); Y2 = c2(2,:); Z2 = c2(3,:);

Then you can plot the circles in X1,Y1,Z1 and X2,Y2,Z2 using plot3. Also you will want to plot P and Q and perhaps the line connecting them.

  Be sure to set 'axis' for equal scale factors along the three axes so that orthogonality will not be distorted in the plot. Unequal scale factors can make orthogonal lines look non-orthogonal, or circles look like ellipses.

Roger Stafford

Viewing all articles
Browse latest Browse all 15

Trending Articles