How to do a 3D circle in matlab

106 ビュー (過去 30 日間)
john pag
john pag 2013 年 6 月 17 日
コメント済み: Rudranarayan Kandi 2018 年 9 月 12 日
Hello,
I need a code for a 3D circle. I have the code but i can not to do 3D.
Thank you
  1 件のコメント
Kye Taylor
Kye Taylor 2013 年 6 月 17 日
Do you know the parametric equation for the circle in 3D?

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2013 年 6 月 17 日

その他の回答 (1 件)

Kye Taylor
Kye Taylor 2013 年 6 月 17 日
編集済み: Kye Taylor 2013 年 6 月 17 日
I assume you do not have a parametric form for the circle in 3D, but you do have the equation for the plane where the circle lives in 3D. In that case, i would solve this problem by creating the data in the xy-plane
% Original points, original plane
t = linspace(0,2*pi);
x = cos(t);
y = sin(t);
z = 0*t;
pnts = [x;y;z];
% unit normal for original plane
n0 = [0;0;1];
n0 = n0/norm(n0);
Then, I would rotate the circle data into a new plane
% unit normal for plane to rotate into
% plane is orthogonal to n1... given by equation
% n1(1)*x + n1(2)*y + n1(3)*z = 0
n1 = [1;1;1];
n1 = n1/norm(n1);
% theta is the angle between normals
c = dot(n0,n1) / ( norm(n0)*norm(n1) ); % cos(theta)
s = sqrt(1-c*c); % sin(theta)
u = cross(n0,n1) / ( norm(n0)*norm(n1) ); % rotation axis...
u = u/norm(u); % ... as unit vector
C = 1-c;
% the rotation matrix
R = [u(1)^2*C+c, u(1)*u(2)*C-u(3)*s, u(1)*u(3)*C+u(2)*s
u(2)*u(1)*C+u(3)*s, u(2)^2*C+c, u(2)*u(3)*C-u(1)*s
u(3)*u(1)*C-u(2)*s, u(3)*u(2)*C+u(1)*s, u(3)^2*C+c];
% Rotated points
newPnts = R*pnts;
Visualize:
plot3(newPnts(1,:),newPnts(2,:),newPnts(3,:),'ko')
  3 件のコメント
Vince
Vince 2018 年 1 月 13 日
Fantastic answer for creating a circle located in arbitrary 3D space!
Rudranarayan Kandi
Rudranarayan Kandi 2018 年 9 月 12 日
very nice approach for plotting in a different plane with normal specified.!!!! Cheers!!!

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-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