Circle plotting on different Planes
이전 댓글 표시
Hey,
I am trying to plot a series of 2D circle in a 3D plot, which are all on slightly different planes (orientated at different angles).
The information I have is;
Centers of the circles;
X = [2 4 5 7];
Y = [0 2 1 0];
Z = [1 3 5 7];
The radii for the circles are the same at 0.5 units.
When I plot these circles I want to see them orientated so that the normal from each circle is pointing in the direction of the next circle. In other words, the plane the circle is drawn on will be perpendicular to the line joining the centers.
the final picture would look like a small section of a pipe.
How could I achieve this?
All help is greatly appreciated.
채택된 답변
추가 답변 (2개)
Matt J
2013년 9월 10일
You could start by plotting a prototype circle in the xy plane. Then roto-translate them in 3D using a transformation
R*points + t
where R is a 3x3 rotation matrix and t is a translation vector. This FEX file might help with that
Finally, use scatter3() to plot the transformed points.
댓글 수: 4
Mazhar
2013년 9월 10일
For example, in the following, I plot circles of radius 5 in a 45 degree tilted plane. Just adjust the transformation parameters to your liking.
r=5;
theta=linspace(0,2*pi,1000);
t=reshape(0:4,1,1,[]); %translations
xyz=[r*cos(theta);r*sin(theta); zeros(1,1000)]; %prototype circles
xyz=bsxfun(@plus,xyz,t);
xyz=reshape(xyz,3,[]);
XYZ=num2cell(AxelRot(xyz,45,[1,0,0],[]),2); %transformed circles
scatter3(XYZ{:});
Mazhar
2013년 9월 10일
Mazhar
2013년 9월 10일
Grzegorz Knor
2013년 9월 10일
편집: Grzegorz Knor
2013년 9월 10일
Try this code:
X = [2 4 5 7];
Y = [0 2 1 0];
Z = [1 3 5 7];
r = 0.5;
[x,y,z] = cylinder(r*ones(size(X)),100);
hold on
for k=length(X):-1:1
x(k,:) = x(k,:)+X(k);
y(k,:) = y(k,:)+Y(k);
z(k,:) = z(k,:)+Z(k);
h(k) = plot3(x(k,:),y(k,:),z(k,:),'r-');
direction = rand(1,3);
alpha = randi(90);
rotate(h(k),direction,alpha)
end
hold off
view(3)
axis equal
I've used random rotation directions and angles. Just calculate the proper values and replace in the code above.
댓글 수: 3
Mazhar
2013년 9월 10일
Grzegorz Knor
2013년 9월 10일
First of all there is a small mistake, should be:
z(k,:) = Z(k);
instead of:
z(k,:) = z(k,:)+Z(k);
Each circle should be perpendicular to the line connecting its center point with the center point of the next circle, right? And what about last circle and its orientation?
Mazhar
2013년 9월 10일
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!