[英]How to draw a curve line with points between it on the shaded region that situated on the surface of the hemisphere using Matlab?
具有阴影区域的半球已经形成。 然后,计划在位于半球表面上带有点的阴影区域上形成路径或曲线。 甚至不知道绘制弧线的纬度或经度是什么,因此,关于如何获取起点和终点的纬度或经度或形成曲线的任何想法,如下图所示?
[x,y,z] = sphere; % Makes a 21-by-21 point sphere
x = x(11:end,:); % Keep top 11 x points
y = y(11:end,:); % Keep top 11 y points
z = z(11:end,:); % Keep top 11 z points
radius = 0.13;
c = [0.36 0 0];
hs = surf(radius.*x + c(1),radius.*y,radius.*z,'FaceColor','yellow','FaceAlpha',.3);
axis equal
xlabel('X');ylabel('Y');zlabel('Z');
% Putting the ranges for the elevation and azimuth
minAzimuth = 0;
maxAzimuth = 180;
minElevation = 0;
maxElevation = 80;
% Compute angles
phi = atan2d(y,x);
theta = acosd (z);
% Highlighting logic (Shading the subset of the hemisphere)
ind = (phi >= minAzimuth & phi <= maxAzimuth) & (theta >= minElevation & theta <= maxElevation); % Find those indices
x2 = x; y2 = y; z2 = z; % Make a copy of the hemisphere coordinates
x2(~ind) = NaN; y2(~ind) = NaN; z2(~ind)=NaN; % Set those out of boundary to NaN
hold on;
surf(radius.*x2+c(1),radius.*y2,radius.*z2,'FaceColor','red');
就像您对球体线段所做的那样,先在球坐标中定义线,然后在需要显示时将其转换为笛卡尔坐标会更容易。 如果您在自己的代码之后添加此代码:
% set line parameters
np = 10 ; % number of points
LineAziStart = 17 ; % Starting azimuth
LineAziStop = 122 ; % Ending azimuth
LineElevation = 49 ; % Elevation
% generate spherical coordinates
azp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;
elp = zeros(np,1) + deg2rad(LineElevation) ;
rp = zeros(np,1) + radius ;
% convert to cartesian
[xp,yp,zp]=sph2cart(azp,elp,rp) ;
% adjust coordinates for center of the sphere
xp = xp + c(1) ;
yp = yp + c(2) ;
zp = zp + c(3) ;
% display
hp = plot3(xp,yp,zp,'g','LineWidth',2,'Marker','x') ;
您可以通过调整代码顶部的第一个参数(使其与您自己的值匹配)来调整线条的起点,终点和终点。
编辑:解释球坐标的生成:要获得3D线,您需要一组3个坐标,它们可以是x/y/z
( 笛卡尔参考 )或radius/azimuth/elevation
( 球参考 )。
该行的约束是:
方位角:(称为azp
)必须从一个值变化到另一个值。 为此,我使用了语句azp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;
azp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;
。 我建议您阅读linspace
函数的文档。 它将在LineAziStart
和LineAziStop
之间生成一组np
线性间隔的点。 我还必须使用deg2rad
因为对于deg2rad
坐标,您想用弧度表示角度。
半径:(称为rp
)这很容易。 您的线必须在球体的表面上,因此线的所有点都将具有相同的radius
值(原始球体的半径 。我们只是生成一个np
个点的向量,都等于半径。这可以通过rp = zeros(np,1) + radius;
高程:(称为elp
)您的线必须与纬度平行,因此线的所有点的高程也是恒定的。 与半径一样,我们以相同的方式生成一组常数点: elp = zeros(np,1) + deg2rad(LineElevation) ;
。
到那时,您将拥有3个向量( rp/azp/elp
)的rp/azp/elp
,它们全部具有相同数量的值,并一起在3D空间中以球坐标定义一组点。 Matlab绘图功能需要笛卡尔坐标,因此最后一步就是转换这组坐标。 这是通过sph2cart
函数完成的,该函数将rp/azp/elp
转换为xp/yp/zp
。 我们生成的球坐标以原点(点0,0,0,
)为中心,因此也存在转换后的笛卡尔坐标。 最后一步是简单地平移这些坐标,以便它们将与球体位于同一点/中心。 之后,您就可以绘制坐标了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.