我正在尝试创建一个与Miegakure类似的4D环境。
我很难理解如何表示旋转。Miegakure的创建者写了一篇小文章,解释他为4d转子做了一门课。http://marctenbosch.com/news/2011/05/4d-rotations-and-the-4d-equivalent-of-quaternions/
如何实现这个类的功能?特别是旋转矢量和其他转子的函数,并得到反求?
我希望有一些伪码的例子。非常感谢那些费心回答的人。
发布于 2018-02-28 13:47:33
在学习了更多关于几何代数的youtube系列之后,我就可以使用旋转体了: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*e 1234)。
显示如何乘这些单位的表格可在此页上找到:http://www.euclideanspace.com/maths/algebra/clifford/d4/arithmetic/index.htm
为了获得它的要点,请考虑2D转子。
它们的形式是:r=A+ B*e12
现在,如果我们计算两个任意转子之间的乘积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-12-07 15:11:09
在计算机中表示多向量(包括转子)的最常见的方法是通过一组系数来表示,每个标准形式的代数基元(标准基叶片)都是这样。对于4D基空间,你将有一个2^4维代数和2^4维系数数组。表示它们的另一种但可能更快的方法是使用一个动态调整大小的列表,每个元素都包含对刀片的索引和相关刀片的系数。在这种情况下,两个多向量的乘法将只使用非零基刀片,因此在算法上应该更便宜,内存使用也更轻。
在实际使用方面,我发现最容易开始玩几何代数的地方可能是用https://github.com/pygae/clifford的python。完全免责声明,我每天使用这个库,并对它作出广泛的贡献。该库使用平面数组系数方法。使用这个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维几何代数中多向量的几何积和反求的具体定义,可在克里斯·多兰和安东尼·拉森比的“物理学家几何代数”第四章中找到。
一个好的C++ GA参考实现N维气体使用的元素列表方法,可以在list的书几何代数为物理学家或他的网站:http://www.geometricalgebra.net/code.html。一般来说,这对于遗传算法来说是一个很好的资源,特别是保角形模型和数值实现以及关注的问题。
发布于 2017-07-15 08:17:46
在4D中,求解任意向量的旋转会使你发疯。是的,有一些方程,比如三维旋转扩展到4D的欧拉-罗德里格斯公式,但是它们都需要解方程组,它的使用对我们来说在,4D,中是不直观的。
我使用的是平行于平面的旋转(类似于3D中围绕主轴的旋转),在4D中,有6个是XY,YZ,ZX,XW,YW,ZW,所以只需创建旋转矩阵(类似于3D)。我使用5x5均匀变换矩阵来表示4D,因此旋转如下所示:
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)。欲了解更多信息,请看以下内容:
https://stackoverflow.com/questions/45108306
复制相似问题