MATLAB绘制倾斜圆

绘制倾斜圆

绘制倾斜圆,设半径为\(\rho\);在x,y,z轴上的投影分别为x,y,z,则\(\rho\)2 = x2+y2+z2

圆平面绕着y轴倾斜\(\theta\)=45\(^{\circ}\),则tan\(\theta\)=\(\frac{z}{y}\),x2+y2+{ytan\(\theta\)}2=\(\rho\)2,求解得到\(y = \sqrt{ \frac{ \rho^2 - x^2}{ 1 + tan^2\theta} }\)

假设\(\rho\)=5,\(\theta\)=45\(^{\circ}\),则令x=linspace(-\(\rho\),0.1,\(\rho\)),可求得y,进而求得z。

MATLAB绘制倾斜圆

附录

附录1:demo_for_circle_theta

clc,clear all
% 三维图窗
figure
r=5;
scatter3(0,0,0,'r','filled');
xlabel('x');
ylabel('y');
zlabel('z');
% 绘制xy平面圆和绕x轴倾斜45度圆
hold on
circle_theta(r,pi/4);
hold on
circle_theta(r,0);
hold on
% 绘制重要的点
scatter3(3,0,0,'r','filled');
scatter3(3,4,0,'r','filled');
scatter3(3,2*sqrt(2),2*sqrt(2),'r','filled');
scatter3(3,2*sqrt(2),0,'r','filled');
% 绘制线段
plot3([-r,r],[0,0],[0,0]);
plot3([3,3],[0,4],[0,0]);
plot3([3,3],[0,2*sqrt(2)],[0,2*sqrt(2)]);
plot3([0,3],[0,2*sqrt(2)],[0,2*sqrt(2)]);
plot3([3,3],[2*sqrt(2),2*sqrt(2)],[0,2*sqrt(2)]);
% 标注
text(3,1,0.5,'\theta=45^\circ');
text(2,2,2,'\rho');
text(1.5,0,0,'x');
text(3,sqrt(2),0,'y');
text(3,2*sqrt(2),sqrt(2),'z');

附录2:circle_theta

function [] = circle_theta(radius,theta)
% 绘制绕x轴旋转theta角度得到的圆
% 不能等于PI/2
x=linspace(-radius,radius,50);
y=sqrt((radius^2-x.^2)/(1+tan(theta)^2));
z=y.*tan(theta);
plot3(x,y,z,'k');
hold on
plot3(-x,-y,-z,'k');
hold off
end
上一篇:用python作画


下一篇:求圆面积自定义异常类