所有,
假设我有两个矢量U和V,分别为2个单位和1个单位长度,如草图所示。矢量U旋转角度θ。
至少有两种可能的情况,即矢量U可以“向上”或“向下”,如草图所示。
我的问题是,拥有上述数据集是否可以有一个通用的公式,可以转移到Matlab中获得点M的坐标?
矢量U和V的长度以及角度θ是任意的。
谢谢!
从Pythogoras我们知道
M = sqrt(U ^ 2 + V ^ 2)
M和U之间的角度是
alpha = arctan(V / U)
那么你就知道M的x坐标和y坐标是:
“up”案例:
M =(sqrt(U ^ 2 + V ^ 2)* cos(theta + sign(costa(theta))* arctan(V / U)),sqrt(U ^ 2 + V ^ 2)* sin(theta + sign) (cos(theta))* arctan(V / U))
“失败”的情况:
M =(sqrt(U ^ 2 + V ^ 2)* leg(theta - sign(costa(theta))* arctan(V / U)),sqrt(U ^ 2 + V ^ 2)* sin(theta - sign) (cos(theta))* arctan(V / U))
计算这个的第二种方法是在x和y方向上添加U
和V
的长度,并将它们相加。
U的坐标是:
(Ucos(theta),Usin(theta))
对于这个坐标,我们必须加上/减去V的x和y坐标。沿x和y的V长度是:
(abs(sin(theta)),abs(cos(theta))
是否应该从U中添加或减去这些取决于theta。一般来说,我们可以将Up和Down写为
Vup =(V * sign(-cos(theta))sin(theta),Vsign(cos(theta))* cos(theta))
Vdown =(V * sign(cos(theta))sin(theta),Vsign(-cos(theta))* cos(theta))
那么我们总是可以将UP添加到Up和Down。最后
Mup = U + Vup
Mdown = U + Vdown
有一个更有效的解决方案。
U
端点的坐标由下式给出:
(U * cos(theta), U * sin(theta))
对于任何矢量(x, y)
,顺时针垂直方向(即第二个图“向下”)是(y, -x)
,而逆时针方向的那些是负的。因此M
的坐标由下式给出:
(U * cos(theta) - M * sin(theta), U * sin(theta) + M * cos(theta))
(U * cos(theta) + M * sin(theta), U * sin(theta) - M * cos(theta))
无需拨打arctan
或sqrt
这些都非常昂贵。您也可以只计算一次sin/cos
并将结果用于两个组件。
只是另一个紧凑的解
theta = 30;
L = 2; % norm of U vector
U = L*[cosd(theta) ; sind(theta)];
Vup = [-U(2) ; U(1)] / L; % Normal vectors, unit length
Vdown = [U(2) ; -U(1)] / L;
Mup = U + Vup; % Two possible values of M
Mdown = U + Vdown;
% Bonus plot
figure
plot([0 U(1)] , [0 U(2)] , 'k-')
hold on; axis equal;
plot([0 Vup(1)]+U(1) , [0 Vup(2)]+U(2) , 'r-')
plot([0 Vdown(1)]+U(1) , [0 Vdown(2)]+U(2) , 'r-')
text(Mup(1),Mup(2),'M_u_p')
text(Mdown(1),Mdown(2),'M_d_o_w_n')
您可以利用Uinit
和Urot
的叉积的属性。产品的标志将告知您生成的矢量的方向。
假设原点是O(0,0)
,你的初始向量是Uinit(x1,y1)
,你的最终向量是Urot(x2,y2)
。 M(x,y)
也很容易计算。
如果你想过滤旋转的矢量Urot
,它最终在'上方'或'下方'M
与你的三角形的前一个方向相比,你可以采用以下交叉产品:M cross Uinit
和M cross Urot
。如果它们的符号相同,那么得到的旋转矢量不会越过线OM,如果符号不同则相反。