给定旋转后的法向矢量,找到平面的OpenGL旋转矩阵 [英] Find OpenGL rotation matrix for a plane, given the normal vector after the rotation

查看:235
本文介绍了给定旋转后的法向矢量,找到平面的OpenGL旋转矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以获取将平面旋转到新方向的矩阵,给定其新的法向矢量

Is there a way to obtain the matrix which rotates a plane to a new orientation, given its new normal vector

下图描述了所描述的内容

The following image depicts what is described

推荐答案

鉴于旧的法线N和新的法线N',您可以通过以下方式获得旋转值:

Given the old normal N and the new normal N' you can obtain the rotation by:

RotationAxis = cross(N, N')
RotationAngle = arccos(dot(N, N') / (|N| * |N'|))

哪里

  • cross(x, y)是向量xy
  • 的叉积
  • dot(x, y)是向量xy
  • 的点积
  • |x|是向量x
  • 的长度
  • cross(x, y) is the cross product of the vectors x and y
  • dot(x, y) is the dot product of the vectors x and y
  • |x| is the length of the vector x

这将以尽可能短的方式将旧法线旋转到新法线上.

This will rotate the old normal onto the new one by the shortest way possible.

注释

  • RotationAngle将采用弧度(如果arccos像大多数实现一样返回弧度)
  • arccos是余弦函数的反函数.这是必要的,因为dot(N, N') = |N| * |N'| * cos(RotationAngle)其中RotationAngle是矢量之间的角度.
  • RotationAxis未规范化
  • 如果两个法线均被归一化,则不必用(|N| * |N'|)除(实际上,如果N被归一化,则可以忽略产品的|N|,如果N'被归一化,则排除|N'|)
  • 如果N' = -N,此方法将失败(因为有许多最短的方法)
  • RotationAngle will be in radians (if arccos returns radians as it does in most implementations)
  • arccos is the inverse of the cosine function. It is necessary because dot(N, N') = |N| * |N'| * cos(RotationAngle) where RotationAngle is the angle between the vectors.
  • RotationAxis is not normalized
  • If both normals are normalized the division by (|N| * |N'|) becomes unnecessary (in fact if N is normalized you can leave out |N| of the product and if N' is normalized then leave out |N'|)
  • This method will fail if N' = -N (as there are infinite many shortest ways)

它如何工作?

第一个观察结果是,两个法线将始终(至少)定义两个均位于其中的平面.分开它们的最小角度也将在此平面内测量.

The first observation is that the two normals will always define (at least) one plane in which both are lying. The smallest angle that parts them will be measured inside this plane too.

所以RotationAxis向量将是同时包含NN'的平面的法线,而RotationAngle是前面提到的两者之间的最小角度.

So the RotationAxis vector will be the normal of the plane that encloses both N and N' and the RotationAngle is the smallest angle between the two mentioned earlier.

因此,通过RotationAngle围绕RotationAxis旋转,旧法线N在平面内旋转,朝着通往N'的最短路径.

So by rotating around RotationAxis by the RotationAngle the old normal N is rotated inside the plane, on the shortest path towards N'.

这篇关于给定旋转后的法向矢量,找到平面的OpenGL旋转矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆