2D Circle 3D Plot.
243 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
reza
il 31 Dic 2013
Risposto: Aaron T. Becker's Robot Swarm Lab
il 14 Mar 2022
Hello, How can i draw a circle in a 3d plot? thanks,
0 Commenti
Risposta accettata
Azzi Abdelmalek
il 31 Dic 2013
Modificato: Azzi Abdelmalek
il 31 Dic 2013
r=1
teta=-pi:0.01:pi
x=r*cos(teta);
y=r*sin(teta)
plot3(x,y,zeros(1,numel(x)))
Più risposte (2)
Aaron T. Becker's Robot Swarm Lab
il 14 Mar 2022
%A circle in 3D is parameterized by six numbers: two for the orientation of its unit normal vector, one for the radius, and three for the circle center.
function drawCircle(rad,pos,n,color)
%https://demonstrations.wolfram.com/ParametricEquationOfACircleIn3D/
%draws a 3D circle at position pos with radius rad, normal to the
%circle n, and color color.
phi = atan2(n(2),n(1)); %azimuth angle, in [-pi, pi]
theta = atan2(sqrt(n(1)^2 + n(2)^2) ,n(3));% zenith angle, in [0,pi]
t = 0:pi/32:2*pi;
x = pos(1)- rad*( cos(t)*sin(phi) + sin(t)*cos(theta)*cos(phi) );
y = pos(2)+ rad*( cos(t)*cos(phi) - sin(t)*cos(theta)*sin(phi) );
z = pos(3)+ rad*sin(t)*sin(theta);
plot3(x,y,z,color)
% then call the function as
pos = rand(3,1);rad = 1;R = eye(3);
drawCircle(rad,pos,R(:,1),'r')
hold on
drawCircle(rad,pos,R(:,2),'g')
drawCircle(rad,pos,R(:,3),'b')
axis equal
0 Commenti
Vedere anche
Categorie
Scopri di più su Graphics Object Programming in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!