4

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

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

我怎样才能实现这个类的功能?特别是旋转矢量和其他转子的功能,并得到逆?

我将不胜感激一些伪代码示例。非常感谢任何打扰回答的人。

4

3 回答 3

6

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

在实际使用方面,我发现最容易开始使用几何代数的地方可能是在 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 维几何代数中多向量的几何乘积和逆的具体定义可以在 Chris Doran 和 Anthony Lasenby 的物理学家几何代数第 4 章中找到。

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

于 2018-12-07T15:11:09.180 回答
3

多亏了这个关于几何代数的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)。

可以在此页面上找到显示如何将这些单位相乘的表格: 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,
于 2018-02-28T13:47:33.653 回答
0

解决任意向量的旋转问题会让你在4D中发疯。是的,那里有方程,比如用于 3D 旋转扩展到 4D 的 Euler-Rodrigues 公式,但它们都需要求解方程组,并且它的使用对于我们在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)。有关更多信息,请查看以下内容:

于 2017-07-15T08:17:46.947 回答