如何使用 4d 转子

How to use 4d rotors

我正在尝试创建类似于 Miegakure 的 4D 环境。

我无法理解如何表示旋转。 Miegakure 的创建者写了这篇小文章解释说他为 4d 转子制作了 class。 http://marctenbosch.com/news/2011/05/4d-rotations-and-the-4d-equivalent-of-quaternions/

如何实现这个class的功能?特别是旋转矢量和其他转子的功能,并获得逆 ?

我希望能提供一些伪代码示例。 非常感谢任何愿意回答的人。

解决围绕任意向量的旋转问题会让您在 4D 中疯狂。是的,那里有像 The Euler–Rodrigues formula for 3D rotations expansion to 4D 这样的方程式,但它们都需要求解方程组,并且在 4D 中,它的使用对我们来说真的不直观。

我正在使用平行于平面的旋转(类似于 3D 中围绕主轴的旋转)在 4D 中有 6 个XY,YZ,ZX,XW,YW,ZW 所以只需创建旋转矩阵(类似于 3D)。我正在为 4D 使用 5x5 齐次变换矩阵 所以旋转看起来像这样:

xy: 
( c , s ,0.0,0.0,0.0)
(-s , c ,0.0,0.0,0.0)
(0.0,0.0,1.0,0.0,0.0)
(0.0,0.0,0.0,1.0,0.0)
(0.0,0.0,0.0,0.0,1.0)
yz: 
(1.0,0.0,0.0,0.0,0.0)
(0.0, c , s ,0.0,0.0)
(0.0,-s , c ,0.0,0.0)
(0.0,0.0,0.0,1.0,0.0)
(0.0,0.0,0.0,0.0,1.0)
zx:
( c ,0.0,-s ,0.0,0.0)
(0.0,1.0,0.0,0.0,0.0)
( s ,0.0, c ,0.0,0.0)
(0.0,0.0,0.0,1.0,0.0)
(0.0,0.0,0.0,0.0,1.0)
xw:
( c ,0.0,0.0, s ,0.0)
(0.0,1.0,0.0,0.0,0.0)
(0.0,0.0,1.0,0.0,0.0)
(-s ,0.0,0.0, c ,0.0)
(0.0,0.0,0.0,0.0,1.0)
yw:
(1.0,0.0,0.0,0.0,0.0)
(0.0, c ,0.0,-s ,0.0)
(0.0,0.0,1.0,0.0,0.0)
(0.0, s ,0.0, c ,0.0)
(0.0,0.0,0.0,0.0,1.0)
zw:
(1.0,0.0,0.0,0.0,0.0)
(0.0,1.0,0.0,0.0,0.0)
(0.0,0.0, c ,-s ,0.0)
(0.0,0.0, s , c ,0.0)
(0.0,0.0,0.0,0.0,1.0)

其中c=cos(a),s=sin(a)a是旋转角度。旋转轴通过坐标系原点(0,0,0,0)。有关更多信息,请查看这些:

  • 我的 3D 数学
  • 我的 C++ 4D 渲染
  • Visualising 4D objects in OpenGL 较旧的 QA
  • 4D to 3D perspective projection 较旧的 QA
  • Four-Space Visualization of 4D Objects 这是我找到的关于该主题的最全面的资料 阅读它 !!!

多亏了这个关于几何代数的 youtube 系列,我在学习了更多关于这个主题的知识后才能够使用转子:https://www.youtube.com/watch?v=PNlgMPzj-7Q&list=PLpzmRsG7u_gqaTo_vEseQ7U8KFvtiJY4K

解释得很好,我推荐给任何想使用几何代数的人。

如果你已经知道四元数乘法,转子乘法也不会有什么不同,四元数的i,j,k单位类似于几何代数的基本双面向量:e12,e13,e23(或e01 , e02, e12)

所以 4D 中的转子将是 (A + B*e12 + C*e13 + D*e14 + E*e23 + F*e24 + G*e34 + H*e1234)。

显示如何乘以这些单位的 table 可以在此页面上找到: http://www.euclideanspace.com/maths/algebra/clifford/d4/arithmetic/index.htm

要了解它的要点,请考虑 2D 转子。

它们的形式是:R = A + B*e12

现在,如果我们计算 2 个任意转子 R_1 和 R_2 之间的乘积,我们得到:

R_1*R_2 = (
  R_1.a     * R_2.a
+ R_1.a     * R_2.b*e12
+ R_1.b*e12 * R_2.a
+ R_1.b*e12 * R_2.b*e12 )
// but: e12*e12 = e1e2e1e2 = -e1e2e2e1= -e1e1 = -1
// this is confirmed by the computation rules I linked above
=
( (R_1.a * R_1.a - R_2.b * R_2.b)
+ (R_1.a * R_2.b + R_1.b * R_2.a) * e12 )

所以在代码中,你会做类似的事情:

R_3.a = R_1.a * R_2.a - R_1.b * R_2.b
R_3.b = R_1.a * R_2.b + R_1.b * R_2.a

现在只需要对那些大的 4D 转子做同样的事情,应用上面链接的 4 维乘法规则。

这是生成的代码(使用 e0、e1、e2、e3 作为基向量):

e: self.e*other.e - self.e01*other.e01 - self.e02*other.e02 - self.e03*other.e03 - self.e12*other.e12 - self.e13*other.e13 - self.e23*other.e23 + self.e0123*other.e0123,
e01: self.e*other.e01 + self.e01*other.e - self.e02*other.e12 - self.e03*other.e13 + self.e12*other.e02 + self.e13*other.e03 - self.e23*other.e0123 - self.e0123*other.e23,
e02: self.e*other.e02 + self.e01*other.e12 + self.e02*other.e - self.e03*other.e23 - self.e12*other.e01 + self.e13*other.e0123 + self.e23*other.e03 + self.e0123*other.e13,
e03: self.e*other.e03 + self.e01*other.e13 + self.e02*other.e23 + self.e03*other.e - self.e12*other.e0123 - self.e13*other.e01 - self.e23*other.e02 - self.e0123*other.e12,
e12: self.e*other.e12 - self.e01*other.e02 + self.e02*other.e01 - self.e03*other.e0123 + self.e12*other.e - self.e13*other.e23 + self.e23*other.e13 - self.e0123*other.e03,
e13: self.e*other.e13 - self.e01*other.e03 + self.e02*other.e0123 + self.e03*other.e01 + self.e12*other.e23 + self.e13*other.e - self.e23*other.e12 + self.e0123*other.e02,
e23: self.e*other.e23 - self.e01*other.e0123 - self.e02*other.e03 + self.e03*other.e02 - self.e12*other.e13 + self.e13*other.e12 + self.e23*other.e - self.e0123*other.e01,
e0123: self.e*other.e0123 + self.e01*other.e23 - self.e02*other.e13 + self.e03*other.e12 + self.e12*other.e03 - self.e13*other.e02 + self.e23*other.e01 + self.e0123*other.e,

在计算机中表示几何代数多向量(包括转子)的最常见方法是通过一组系数,每个系数代表一个规范形式的代数基元素(规范基 blade),即。对于 4D 基础 space,您将拥有 2^4 维代数和 2^4 维系数数组。表示它们的另一种但可能更快的方法是使用动态调整大小的列表,其中每个元素包含 blade 的索引和关联的 blade 的系数。在这种情况下,两个多向量的乘法将仅使用非零基础 blades,因此在算法上应该更便宜且内存使用更轻。

就实际使用而言,我发现开始玩几何代数最简单的地方可能是 python 和 https://github.com/pygae/clifford。完全免责声明我每天都使用这个库并为它做出了广泛的贡献。该库使用平面系数数组方法。使用这个 python 库,您可以通过三明治产品应用 4D 转子,并通过波浪号运算符进行反转(转子的反转):

# Create a 4D geometric algebra with euclidean metric
from clifford.g4 import *

# Create a rotor
R = layout.randomRotor()

# Create a vector to rotate
V = layout.randomV()

# Apply the rotor to the vector
V2 = R*V*~R

N-dimensional 几何代数中多向量的几何积和逆的具体定义可以在 Chris Doran 和 Anthony Lasenby 合着的物理学家几何代数第 4 章中找到。

可以在 Leo Dorst 的《物理学家几何代数》一书中或在他的网站上找到使用元素列表方法的 N-dimensional GA 的良好 C++ GA 参考实现: http://www.geometricalgebra.net/code.html。总的来说,这是 GA 的重要资源,尤其是共形模型和数值实现以及关注点。