使用四元数旋转球体(Wolfram Mathematica软件)

时间:2018-09-04 20:59:00

标签: rotation wolfram-mathematica quaternions

以下代码在Wolfram Mathematica软件中用于使用四元数组构建像立方体这样的立方体并将其旋转:

<< Quaternions`
Q = Quaternion;
rotateq[theta_, v_] :=  Q @@ ({Cos[theta/2], 0, 0, 0} + (Sin[theta/2] Prepend[v, 0])/Sqrt[ Plus @@ (v^2)]);
Rotaterho[vector_, angle_, axis_] := N[rotateq[angle,axis] ** (Q @@ (Prepend[vector, 0])) ** (rotateq[angle, axis])^-1] // Rest// Chop

faces = {{{0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}}, {{0, 0, 0}, {0, 0, 1}, {0, 1, 1}, {0, 1, 0}}, {{1, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 0, 1}}, {{1, 1, 0},  

{0, 1, 0}, {0, 1, 1}, {1, 1, 1}}};
axis = {1, 1, 1};
dots = {{.5, 0, 1}, {.5, 1, 1}, {1.5, .5, .5}, {-.5, .5, .5}};

Manipulate[t = ANGLE Degree;
points = Table[List @@ Rotaterho[dots[[m]], t, axis], {m, 1, 4}];
rotatedfaces = Table[Table[List @@ Rotaterho[faces[[c, m]], t, axis], {m, 1, 4}], {c, 1, 4}];
box = Table[Polygon[rotatedfaces[[m]]], {m, 1, 4}];
Graphics3D[{{EdgeForm[{Thick, Blue}], FaceForm[Red, LightBlue], box},
Thickness[Medium], Line[{{-2, -2, -2}, {2, 2, 2}}], PointSize[.03],Yellow, Point[points[[1]]], Green, Point[points[[2]]], Purple, 
Point[points[[3]]], Point[points[[4]]],
Line[{points[[3]], points[[4]]}], Black, Point[{0, 0, 0}], 
Point[{1, 1, 1}]}, Axes -> True,
Lighting -> Automatic, BaseStyle -> {FontSize -> 13}, Boxed -> True,
BoxStyle -> Directive[Dashed], AxesLabel -> {x, y, z},
PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}], {ANGLE, 0., 360., 1.}]

结果如图所示 https://i.stack.imgur.com/75NAb.jpg

如何添加该代码并构建类似球形的结构并获得相似的结果?

0 个答案:

没有答案