how to draw a tilted circle?

조회 수: 13 (최근 30일)
bsd
bsd 2011년 10월 3일
Hai,
The following code draws a circle in the x-z plane in 3D.
radius=1;
center=[2 4 2];
theta=linspace(0,2*pi);
rho=ones(1,100).*radius;
[x,z]=pol2cart(theta,rho);
x=x+center(1);
z=z+center(3);
y=center(2)*ones(1,length(x));
figure;
h=plot3(x,y,z);
grid on;
axis square;
By default the above circle is vertical in the x-z plane. I need to draw a circle which is inclined or tilted at some angle. How could I do this?
Looking forward for your reply.
BSD
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 10월 3일
Duplicate is at http://www.mathworks.com/matlabcentral/answers/17160-how-to-draw-an-inclined-circle

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2011년 10월 3일
You have X-, Y- and Z-coordinates. Now you want to tilt the obejct. This can be done by applying a rotation matrix, e.g. for a rotation around the Z-axis by the angle a :
R = [ cos(a), sin(a), 0; ...
-sin(a), cos(a), 0; ...
0, 0, 1];
This matrix must be multiplied to the array of coordinates. See also: Wiki: Rotation Matrix
  댓글 수: 4
Walter Roberson
Walter Roberson 2011년 10월 4일
Generate the circle around (0,0,0), rotate it, and then translate the circle by the coordinates of the new center that you want.
Or if you already have a circle existing and decide later that you want to tilt it, then translate it to (0,0,0), rotate it, and then translate it back.
bsd
bsd 2011년 10월 5일
It is working. Excellent... Thank you...
BSD

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 10월 3일
The answer hasn't changed since your previous time asking.
If you wish to do it mathematically instead of the way I suggested before, then say as much (at which point I would say, "So, did you read the documentation to find out what that routine actually does ?")
  댓글 수: 1
Jan
Jan 2011년 10월 3일
@Walter: Your answer has been complete. I add more details only, because it seems that the OP cannot follow completely.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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!

Translated by