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;
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;