我在3d空间(x,y,z)中有一个点。我想离散地从该点向外径向移动(例如对于r = 1和r = 2)。在x,y平面上,我可以简单地通过步进((x + r cos(theta)),(y + r sin(theta)),z)来向外移动,其中r = 1或2并且theta每隔10度变化一次。
但是,如果我要使线在倾斜的平面上向外移动并在该平面内移动我的线,我不确定如何描述此运动。
我以为那将只是使用球坐标。但是,如果我使用(x = rho sin phi cos theta,y = ...,z = ...)从中心点绘制线,那会不会形成圆锥体而不是在平面上倾斜的圆?
PS将在MATLAB中实现
您可以首先使坐标从P0向外移动,然后使用旋转矩阵旋转坐标。
因此,正如MBo所指出的那样,对所有R和theta取点P。
P = [P0x + R * cos(theta); P0y + R * sin(θ); 0]
然后创建一个旋转矩阵,以所需的角度旋转XY平面
如果将其乘以坐标,则会得到旋转的坐标。例如,[1,0,0]点绕Z轴旋转90度:
但是,您可能想绕点P0旋转而不是绕原点旋转,那么您必须使用以下平移制作一个仿射矩阵:
tx = x- r00 * x-r01 * y-r02 * z
ty = y- r10 * x-r11 * y-r12 * z
tz = z- r20 * x-r21 * y-r22 * z
然后使用T和R(在图中指定为M,对不起)制作一个仿射变换矩阵:
在此图中,Q是旧坐标,而Q'是新坐标。
我遇到了类似的问题,并使用了此答案并将其调整为您的问题:
%input point and rotated plane
p0 = [10;10;10;1]; % the last entry is your homogeneous dimension
r0 = [45,45,45]; r0 = r0*pi/180;
%rotation to plane
Rx=[1 0 0 0;
0 cos(r0(1)) sin(r0(1)) 0;
0 -sin(r0(1)) cos(r0(1)) 0;
0 0 0 1];
Ry=[cos(r0(2)) 0 -sin(r0(2)) 0;
0 1 0 0;
sin(r0(2)) 0 cos(r0(2)) 0;
0 0 0 1];
Rz=[cos(r0(3)) sin(r0(3)) 0 0;
-sin(r0(3)) cos(r0(3)) 0 0;
0 0 1 0;
0 0 0 1];
R = Rz*Ry*Rx; A = R;
T = ( eye(3)-R(1:3,1:3) ) * p0(1:3); %calculate translation to rotate about the point P0
A(1:3,4) = T; % to rotate about the origin just leave out this line
%make coordinates for the points going outward from p0
nangles = 36; anglestep = 2*pi/nangles;
nradii = 2; radiistep = 1;
thetas = anglestep:anglestep:2*pi;
rs = radiistep:radiistep:nradii*radiistep;
npoints = nradii*nangles;
coordinates = zeros(4,npoints); curpoint = 0;
for itheta = 1:nangles; for iradius = 1:nradii;
curpoint = curpoint+1;
coordinates(:, curpoint) = p0+rs(iradius)*[cos(thetas(itheta));sin(thetas(itheta));0;0];
end; end
coordinates_tilted = A*coordinates; %rotate the coordinates to the new plane
结果在此图中:
figure;
scatter3(coordinates_tilted(1,:),coordinates_tilted(2,:),coordinates_tilted(3,:), 'MarkerEdgeColor', 'green')
hold on
scatter3(coordinates(1,:),coordinates(2,:),coordinates(3,:), 'MarkerEdgeColor', 'red')
legend('tilted', 'original')
或将它们绘制为线:
%or as lines
coorarray = reshape(coordinates, [4 nradii nangles]);
Xline = squeeze(coorarray(1,:,:));
Yline = squeeze(coorarray(2,:,:));
Zline = squeeze(coorarray(3,:,:));
coorarray_tilted = reshape(coordinates_tilted, [4 nradii nangles]);
Xline_tilted = squeeze(coorarray_tilted(1,:,:));
Yline_tilted = squeeze(coorarray_tilted(2,:,:));
Zline_tilted = squeeze(coorarray_tilted(3,:,:));
figure;
plot3(Xline,Yline,Zline, 'r');
hold on
plot3(Xline_tilted,Yline_tilted,Zline_tilted, 'g');
legend( 'original', 'tilted')
这回答了你的问题了吗?现在,这些点是与平面中的点P0的距离为1和2的36度角倍数的点,该平面在围绕点P0的所有轴上倾斜45度。如果您需要单独的“像素”来指定您的线(即整数坐标),则可以四舍五入,这将是最接近的一种邻域方法:
coordinates_tilted_nearest = round(coordinates_tilted);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句