Draw a circle for arbitrary orientation on spherical surface

조회 수: 26(최근 30일)
AVM 2020년 2월 6일
댓글: Adam Danz 2020년 2월 7일
I would like to draw a circular loop on spherical surface for a fixed orientation of theta(i.e. polar angle on sphere) and variying the azimuthal angle. The following code only generates the circle which are parallel to the equiatorial plane, but I need arbitrary orientation of ploar angle on the sphere. Pl somebody help me.
clear; clc;
for i=1:N+1
for j=1:N+1
if (d<=r)
axis equal

채택된 답변

Jim Riggs
Jim Riggs 2020년 2월 7일
편집: Jim Riggs 2020년 2월 7일
My approach is to define the circle around the X-axis, then rotate it into the desired position through a Yaw-Pitch rotation.
% Specify the user inputs
Rmag= 10; % Sphere radius
radius = 1; % circle radius
psi = 30*pi/180; % yaw rotation angle
theta = -45*pi/180; % pitch rotation angle (negative rotation is up)
% Define vectors and Calculate the YAW-PITCH transformation matrix
alpha = asin(radius/Rmag);
YAW = [cos(psi), -sin(psi), 0; sin(psi), cos(psi), 0; 0, 0, 1]; % Planar YAW rotation
PITCH = [cos(theta), 0, sin(theta); 0,1,0; -sin(theta), 0, cos(theta)]; % Planar PITCH rotation
YP = YAW*PITCH; % YAW-PITCH rotation matrix
% Rc = Column Vector pointing to circle on X-Axis (start point)
Rc = [Rmag*cos(alpha); 0; radius];
R = YP*[Rmag; 0; 0]; % Vector pointing to Circle center
% Now sweep the Rc vector around the X-axis to generate the circle
% This is done by adding a planar ROLL rotation to YP
clear C
C = []; % C is the vector containing the circle X-Y-Z cordinates
for phi = 0:pi/50:2*pi
ROLL = [1, 0, 0; 0, cos(phi), -sin(phi); 0, sin(phi), cos(phi) ];
YPR = YP*ROLL; % 3-dimentional transform
Rnew = YPR*Rc;
C = [C, Rnew];
% plot the result
mesh(Rmag.*Sx, Rmag.*Sy, Rmag.*Sz); % draw the sphere
hold on;
plot3([0, R(1)], [0, R(2)], [0,R(3)], 'r'); % Vector to Circle center
plot3(C(1,:), C(2,:),C(3,:), 'b'); % Circle
axis equal
  댓글 수: 6
Adam Danz
Adam Danz 2020년 2월 7일
Also, make sure the circle isn't appearing on the other side of the sphere that is not visible from the view point.
There are two solutions to that
1) use view(az,el) to rotate the plot.
2) make the sphere partially transparent.

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

추가 답변(0개)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by