您可以先使坐标从 P0 向外移动,然后使用 rotation matrix 旋转坐标。
因此,正如 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' 是新坐标。
我也遇到过类似的问题,用this的回答,根据你的问题调整了一下:
%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 倾斜 45 度的平面中,距离点 P0 1 和 2 处所有 36 度角的倍数的点。如果您需要单独的“像素”来指定您的线(所以整数坐标),您可以将坐标四舍五入,这将是一种最近邻方法:
coordinates_tilted_nearest = round(coordinates_tilted);