基于平面法线计算物体旋转。

huangapple go评论45阅读模式
英文:

Calculating object rotation based on plane normal

问题

I am currently working on procedurally generated terrain using simplex noise and the marching cubes algorithm. I've completed the process of creating a ground mesh which different entities like plants will lie on. However the models rendered will always point upwards instead of the direction which the triangular face they lie on is pointing. This renders them into the ground which does not look good. I have already calculated the normals of each triangle so I am wondering how I would convert the normal of the triangular face to a 3D XYZ rotation for the model.

The image below shows my current problem:

Clipped plant models
基于平面法线计算物体旋转。

英文:

I am currently working on procedurally generated terrain using simplex noise and the marching cubes algorithm. I've completed the process of creating a ground mesh which different entities like plants will lie on. However the models rendered will always point upwards instead of the direction which the trianglular face they lie on is pointing. This renders them into the ground which does not look good. I have already calculated the normals of each triangle so I am wondering how I would convert the normal of the triangular face to a 3D XYZ rotation for the model.

The image below shows my current problem:

Clipped plant models
基于平面法线计算物体旋转。

答案1

得分: 1

只需将上向量与平面法线向量叉乘,这将给出旋转轴。然后将上向量与平面法线向量点乘,这将给出旋转角的余弦值。所以你有:

轴 = normalize(cross(up, normal))

角度 = acos(dot(up, normal))

然后,你可以使用轴和角度构建四元数或旋转矩阵。

参考:
https://en.m.wikipedia.org/wiki/Rodrigues%27_rotation_formula

https://en.m.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle

https://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm

英文:

Just take the cross product of up vector with plane normal. That will give you the rotation axis. Then take the dot product of the up vector with plane normal, that will give you the cosine of the rotation angle. So you have:

Axis = normalize(cross(up, normal))

Angle = acos(dot(up, normal))

Then you can construct a quaternion or a rotation matrix from axis and angle.

See:
https://en.m.wikipedia.org/wiki/Rodrigues%27_rotation_formula

https://en.m.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle

https://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm

huangapple
  • 本文由 发表于 2020年8月2日 11:36:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63212143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定