简体   繁体   English

从4个点计算旋转矩阵

[英]calculate rotation matrix from 4 points

I would like to stick a moving car to a curvy terrarian. 我想将行驶中的汽车贴在弯曲的地形上。 I can calculate the y coordinate (which is height in my case) for each wheel. 我可以计算每个车轮的y坐标(在我的情况下为高度)。 These 4 points forms a plane. 这四个点构成一个平面。 I don't know how to calculate the rotation matrix from these 4 pints so I can apply it to the car. 我不知道如何从这4品脱中计算出旋转矩阵,因此我可以将其应用于汽车。 So this is what I would like to achieve: 因此,这就是我想要实现的目标:

calculateRotationMatrix(p1,p2,p3,p4); computeRotationMatrix(p1,p2,p3,p4);

BTW I am using c++ and openGL. 顺便说一句,我正在使用c ++和openGL。

Could anybody help me out here? 有人可以帮我吗?

If you guarantee that all 4 points lie on one plane, then the problem is not that hard to solve: Let's call the points (A,B,C,D) and we define a up vector (UP = [0,1,0]) 如果保证所有4个点都在一个平面上,那么问题就不那么难解决了:我们将这些点称为(A,B,C,D),然后定义一个向上矢量(UP = [0,1,0 ])

1) Calculate the plane normal (N) 1)计算平面法线(N)

N = normalize(cross(B-A, C-A));

2) Calculate the rotation axis (R) 2)计算旋转轴(R)

R = normalize(cross(N,UP))

3) Calculate rotation angle (alpha) 3)计算旋转角度(alpha)

alpha = dot(N, UP)

The resulting matrix is then the one that rotates around R by an angle of alpha. 然后,生成的矩阵就是围绕R旋转一个α角的矩阵。 If your matrix library does not support creating rotation axis around arbitrary axis, you can find the form here . 如果您的矩阵库不支持创建围绕任意轴的旋转轴,则可以在此处找到表格。

Note, that there is a singularity when alpha is very small (N will then vanish), so you should only calculate the matrix if alpha is sufficiently large. 请注意,当alpha很小时会出现奇点(然后N会消失),因此仅当alpha足够大时才应计算矩阵。 It might also be that case that some of the vectors point to the opposite direction depending on the winding order in which the points are defined. 在某些情况下,某些矢量也可能指向相反的方向,具体取决于定义点的绕线顺序。 In this case just switch the two parameters of the cross function. 在这种情况下,只需切换交叉功能的两个参数即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM