【问题标题】:How can I describe lines moving radially outwards from a center point?如何描述从中心点径向向外移动的线?
【发布时间】:2015-01-23 10:22:42
【问题描述】:

我在 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=...) 从中心点画线,那会不会形成一个圆锥体而不是一个在平面上倾斜的圆?

附:将在 MATLAB 中实现这一点

【问题讨论】:

  • 你可以在 XY 平面上定义你的线(更简单的开始定义),然后在你倾斜平面时旋转它们(只是一个旋转操作符应用于你的点)。顺便说一句,当您谈论“倾斜”平面时,您需要精确地围绕要执行旋转的线/轴。

标签: matlab geometry coordinate-systems


【解决方案1】:

您可以先使坐标从 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);

【讨论】:

  • 抱歉 - 只是回顾一下代码。文本正文中的旋转矩阵(与其他文献匹配)和代码中的矩阵似乎反转了 sin 项的负号。这是一个错字还是我遗漏了什么?
  • 哦,是的,你是对的,它们都是顺时针而不是逆时针。那是一个错字。
【解决方案2】:

您的倾斜平面是如何定义的?
用基点P0和两个垂直的单位向量UV来定义它。从任何其他人那里得到这种表示并不难。例如,如果您的平面的法线向量分别具有轴 OX、OY、OZ 的角度 ax、y、az,则其归一化形式为 N = (nx, ny, nz) = (Cos(ax )、Cos(ay)、Cos(az))。可以选择任意向量U(平面内)as described here,求V向量为向量积V = U x N
那么需要的点是:

P = P0 + U * R * Cos(Theta) + V * R * Sin( θ)

【讨论】:

  • 平面未定义 - 我希望在径向线的步进中通过与轴的角度来定义它?所以你说 P0 将是我的 3d 中心点 (x,y,z)。我仍然不确定如何获得 U 和 V?
  • 我基本上是在尝试找到最好的飞机,以便在一系列倾斜中循环。例如我在 x,y 平面上创建线条,然后我想倾斜那个平面(比如 10 度)并在那个平面上画出线条
猜你喜欢
  • 1970-01-01
  • 2020-07-06
  • 1970-01-01
  • 1970-01-01
  • 2011-09-19
  • 2014-08-26
  • 2016-04-14
  • 1970-01-01
  • 2020-06-21
相关资源
最近更新 更多