Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: sph2cart, orientation, lines and coordinates in 3d space / volume
Replies: 1   Last Post: Feb 25, 2014 4:42 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
kees de kapper

Posts: 73
Registered: 12/7/04
sph2cart, orientation, lines and coordinates in 3d space / volume
Posted: Feb 25, 2014 8:29 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Dear all,
I've got a problem, which should be trivial, but I do not manage to solve this.
Please help.

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 tried the following code below.

The result should show a line with two circles around each point, perpendicular to the line. However, the result is actually a line with two circles at the wrong positions.

What am I doing wrong?

Many thanx,
Kees
===================

% Two coordinates that represents a line
Crd(1,:) = [0,0,0];
Crd(2,:) = [1,1,1];
figure; plot3(Crd(:,1), Crd(:,2),Crd(:,3), '.-');

% defining the orientation of the vector/line
DCrd = diff(Crd); DCrd(end+1,:) = DCrd(end,:);
[OrientCrd(:,1), OrientCrd(:,2), OrientCrd(:,3)] = cart2sph(DCrd(:,1), DCrd(:,2), DCrd(:,3));

% Setting up the plane around the two coordinates, which is perpendicular
% to the direction of the line
AziList = linspace(0, 2*pi, 36);
EleList = pi/2; % swap of 90 degrees
Radius = 4;
clear TmpCrd ExtCrd;
for n = 1:size(Crd,1)
k = 1;
for A = 1:length(AziList)
for E = 1:length(EleList)
[TmpCrd(k,1), TmpCrd(k,2), TmpCrd(k,3)] = ...
sph2cart(OrientCrd(n,1)+AziList(A), OrientCrd(n,2)+EleList(E), Radius);
k = k+1;
end;
end;
ExtCrd(n,:,:) = TmpCrd + ones(size(TmpCrd,1),1)*Crd(n,:);
clear TmpCrd;
end;
hold on; plot3(ExtCrd(:,:,1), ExtCrd(:,:,2),ExtCrd(:,:,3), '.'); hold off;



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.