空间解析几何6:空间圆柱体的离散化表示【附MATLAB代码】
matlab代码
clc;
clear;
PP1 = [0,0,0];
Rz = [0 0 -1];
Rx = [0 1 0];
h= 10;
r = 10;
result = getCylinder(PP1,Rz,Rx,h,r);
function result = getCylinder(PP1,Rz,Rx,h,r)
%%圆柱参数
result = [];
pp2 = PP1-h/2*Rz;
radius=r;
Rz = Rz'/norm(Rz);
Rx = -Rx'/norm(Rx);
Ry = cross(Rz,Rx);
Tc1=[Rx,Ry,Rz,pp2'0,0,0,1];
range = 180;
container = [];
stepZ = 0.01;
stepX = 1;
for l_k = 0:stepZ:1for theta_u = -range:stepX:range cylinder_ku = Tc1*[radius*cos(theta_u/180*pi),radius*sin(theta_u/180*pi),l_k*h,1]'; container = [container;cylinder_ku(1:3,1)'];end
end
figure('color',[1 1 1]);
plot3(container(:,1),container(:,2),container(:,3),'r.','MarkerSize',10)
grid on
result = container;
end
结果验证:
可以自己修改离散化参数看看不同参数下的效果,加深理解。