1
$\begingroup$

EDIT! This is a recent post updated and with better wording. The title has also changed. Any attempts to find something relevant have failed so far. The closest is this Ellipsoid.

First some background.

I want to visualize a general ellispoid arbitrary oriented and translated. For a triaxial or general ellipsoid, a sequence of three rotations is necessary to arrive at an arbitrary orientation. The rotation order will be the so-called zxz rotation.

enter image description here

Refer to the figure above the angles define the relative orientation between xyz and $ABC$. The angles describe three successive rotations of one coordinate system $xyz$ that align it with the other one, $ABC$.

Choosing the first rotation to be an angle $\alpha$, clockwise, about the original $z$ axis gives new $x$ and $y$ coordinate axes that will be referred to as $x'$ and $y'$ (coordinate system $x'y'z'$).

A second rotation, clockwise, of an angle $\beta$ about the $y'$ axis gives new coordinate axes of $x''$ and $z''$ (coordinate system $x''y''z''$).

The third rotation and final one, clockwise, of an angle $\gamma$ about the $z''$ axis gives the final ellipsoid orientation (coordinate system $ABC$).

This is the code I use in Mathematica.
(The rotations will be counterclockwise; $XYZ$ the global coordianate system; $x'y'z'$ the system after the first rotation $\alpha$; $x''y''z''$ the system after the second rotation $\beta$; $xyz$ the final-ellipsoid-coordinate system after the final rotation $\gamma$).

(*Euler angles*)
MatrixForm[
 Rz = {{Cos[α], Sin[α], 0}, {-Sin[α], 
    Cos[α], 0}, {0, 0, 1}}]
MatrixForm[
 Rxprime = {{1, 0, 0}, {0, Cos[β], 
    Sin[β]}, {0, -Sin[β], Cos[β]}}]
MatrixForm[
 Rzdoubleprime = {{Cos[γ], Sin[γ], 0}, {-Sin[γ], 
    Cos[γ], 0}, {0, 0, 1}}]

enter image description here

(*"Total Rotator"*)
    (R[α_, β_, γ_] = Rzdoubleprime.Rxprime.Rz) // MatrixForm

enter image description here

(*Translation*)
OffsetTrans[d_, e_, f_] := {d, e, f};

(*Parametric Equations of Arbitrarily Rotated and Translated Ellipsoid*)

X0[x0_, y0_, z0_] := {x0, y0, z0};

XPar[θ_, ϕ_, a_, b_, c_, α_, β_, γ_] = 
  R[α, β, γ].X0[x0, y0, z0] /. {x0 -> 
     a Cos[θ] Sin[ϕ], y0 -> b Sin[θ] Sin[ϕ], 
    z0 -> c Cos[ϕ]};
XParTrans[d_, e_, f_, a_, b_, c_, α_, β_, γ_] = 
  OffsetTrans[d, e, f] + 
   XPar[θ, ϕ, a, b, c, α, β, γ];

(*Ellipsoidal Axes*)

(*Non rotated; no translated*)
Cross0[a_, b_, c_] := {Line[{{-a, 0, 0}, {a, 0, 0}}], 
  Line[{{0, -b, 0}, {0, b, 0}}], Line[{{0, 0, -c}, {0, 0, c}}]}

(*rotated but not translated*)
CrossRot0[a_, b_, 
  c_, α_, β_, γ_] := {Line[{R[α, β, \
γ].{-a, 0, 0}, R[α, β, γ].{a, 0, 0}}], 
  Line[{R[α, β, γ].{0, -b, 0}, 
    R[α, β, γ].{0, b, 0}}], 
  Line[{R[α, β, γ].{0, 0, -c}, 
    R[α, β, γ].{0, 0, c}}]}

(*rotated and translated; final coordinate system: xyz*)
CrossRotTrans[d_, e_, f_, a_, b_, 
  c_, α_, β_, γ_] := {Line[{R[α, β, \
γ].{-a, 0, 0} + {d, e, f}, 
    R[α, β, γ].{a, 0, 0} + {d, e, f}}], 
  Line[{R[α, β, γ].{0, -b, 0} + {d, e, f}, 
    R[α, β, γ].{0, b, 0} + {d, e, f}}], 
  Line[{R[α, β, γ].{0, 0, -c} + {d, e, f}, 
    R[α, β, γ].{0, 0, c} + {d, e, f}}]}

(*rotated and translated; first intermediate coordinate system: x'y'z'*)
    CrossRotTransAlpha[d_, e_, f_, a_, b_, 
      c_, α_, β_, γ_] := {Line[{R[α, 0, 0].{-a, 0, 
           0} + {d, e, f}, R[α, 0, 0].{a, 0, 0} + {d, e, f}}], 
      Line[{R[α, 0, 0].{0, -b, 0} + {d, e, f}, 
        R[α, 0, 0].{0, b, 0} + {d, e, f}}], 
      Line[{R[α, 0, 0].{0, 0, -c} + {d, e, f}, 
        R[α, 0, 0].{0, 0, c} + {d, e, f}}]}

 (*rotated and translated; second intermediate  coordinate system: x''y''z''*)
    CrossRotTransBetaAlpha[d_, e_, f_, a_, b_, 
      c_, α_, β_, γ_] := {Line[{R[α, β, 0].{-a, 
           0, 0} + {d, e, f}, R[α, β, 0].{a, 0, 0} + {d, e, f}}], 
      Line[{R[α, β, 0].{0, -b, 0} + {d, e, f}, 
        R[α, β, 0].{0, b, 0} + {d, e, f}}], 
      Line[{R[α, β, 0].{0, 0, -c} + {d, e, f}, 
        R[α, β, 0].{0, 0, c} + {d, e, f}}]}


(* Cross sections*)

    CrossSectionX[d_, e_, f_, a_, b_, c_, α_, β_, γ_] := 
      ParametricPlot3D[
       OffsetTrans[d, e, f] + 
        R[α, β, γ].{0, b Cos[ϕ], c Sin[ϕ]}, {ϕ,
         0, 2 Pi}, PlotStyle -> {Dashed, Gray}];

    CrossSectionY[d_, e_, f_, a_, b_, c_, α_, β_, γ_] := 
      ParametricPlot3D[
       OffsetTrans[d, e, f] + 
        R[α, β, γ].{a Cos[ϕ], 0, c Sin[ϕ]}, {ϕ,
         0, 2 Pi}, PlotStyle -> {Dotted, Gray}];

    CrossSectionZ[d_, e_, f_, a_, b_, c_, α_, β_, γ_] := 
      ParametricPlot3D[
       OffsetTrans[d, e, f] + 
        R[α, β, γ].{a Cos[ϕ], b Sin[ϕ], 0}, {ϕ,
         0, 2 Pi}, PlotStyle -> {DotDashed, Gray}];


    (*XYZ system*)
    arrowAxesXYZ[arrowLength_] := 
     Map[Arrow[Tube[{{0, 0, 0}, #}]] &, arrowLength IdentityMatrix[3]]
    AxesXYZ[pos_] := {Text[Style["X", 20, Italic], {pos + 0.2, 0, 0}], 
      Text[Style["Y", 20, Italic], {0, pos + 0.2, 0}], 
      Text[Style["Z", 20, Italic], {0, 0, pos + 0.2}]}

For example for a translation $12\hat{X}+21\hat{Y}+30\hat{Z}$ and rotation by the angles $\alpha=\frac{\pi}{4}$, $\beta=\frac{\pi}{6}$, $\gamma=\frac{\pi}{3}$ one obtains

enter image description here

The questions now:
1) I want to use this visualization for publications, presentations and demonstrations. I will appreciate any comments, suggestions and the like for the better appearance of it.

2) I want to label the three coordinate systems (the intermediate ones: $x'y'z'$ corresponding to (the first) $\alpha$ rotation; $x''y''z''$ corresponding to (the second) $\beta$ rotation and the final one: $xyz$ corresponding to (the third) rotation $\gamma$. I can do it manually. But I want to do it aumatically by passing suitable functions to the EllipsoidalFun function. I cannot figure out how can I do this.

3) I want to demonstrate also the rotations adding suitable curvy arrows between the respective axes. I can do it manually but I want also to be done automatically.

Thank you very much for your help.

$\endgroup$
  • $\begingroup$ EulerAngles[] and EulerMatrix[] are built-in as of 10.2 $\endgroup$ – J. M. will be back soon Nov 9 '15 at 13:45
  • $\begingroup$ @ybeltukov: Thanks for the edit! $\endgroup$ – Dimitris Nov 9 '15 at 18:08
  • $\begingroup$ @J.M. A serious reason to upgrade:-)! $\endgroup$ – Dimitris Nov 9 '15 at 18:09
2
$\begingroup$

Not exactly what I want but the best that I can arrive. I post it as an answer because it may be useful for other people; especially for those dealing with inclusions.

Of course the questions still remain:-)!

All the code remains the same but slightly modify the final function.

Clear[g1, g2, g3, g4, g5, g6, g7, g9, EllipsoidalFunMod] 
EllipsoidalFunMod[d_, e_, f_, a_, b_, 
  c_, α_, β_, γ_, {opts___}] := 
 Module[{g1, g2, g3, g4, g5, g6, g7, g8},
  g2 = CrossRotTrans[d, e, f, a, b, c, α, β, γ];
  g3 = CrossSectionX[d, e, f, a, b, c, α, β, γ]; 
  g4 = CrossSectionY[d, e, f, a, b, c, α, β, γ]; 
  g5 = CrossSectionZ[d, e, f, a, b, c, α, β, γ];
  g6 = CrossRotTransAlpha[d, e, f, a, b, 
    c, α, β, γ]; 
  g7 = CrossRotTransBetaAlpha[d, e, f, a, b, 
    c, α, β, γ];
  g1 = ParametricPlot3D[
    XParTrans[d, e, f, a, b, 
     c, α, β, γ], {θ, 0, 2 Pi}, {ϕ, 0,
      Pi}, PlotStyle -> 
     Directive[Orange, Specularity[White, 40], Opacity[0.5]], 
    Mesh -> None];
  g8 = Arrow[Tube[{{0, 0, 0}, {d, e, f}}, 0.05]];
  Legended[
   Show[{g1, 
     Graphics3D[{{Black, g8}, {Red, Thick, g6}, {Green, Thick, 
        g7}, {Blue, Thick, g2}, {Gray, arrowAxesXYZ[30]}, 
       AxesXYZ[31]}], g3, g4, g5}, Axes -> False, 
    AxesOrigin -> {0, 0, 0}, PlotRange -> All, ImageSize -> Large, 
    PlotLabel -> 
     Style[Framed[
       "Arbitrarily Oriented & Translated Ellipsoid\nEllipsoidal \
Semi-Axes: \ta=" <> ToString[a] <> "\tb=" <> ToString[b] <> "\tc=" <> 
        ToString[c]], Blue, 20, Background -> Lighter[Yellow]], opts],
    LineLegend[{Directive[Thick, Black], Directive[Thick, Red], 
     Directive[Thick, Green], 
     Directive[Thick, Blue]}, {Style[
      "Translation by " <> 
       ToString[TraditionalForm[\!\(TraditionalForm\`\*
StyleBox["d", "TI"] \*
OverscriptBox[
StyleBox["X", "TI"], "^"] + \*
StyleBox["e", "TI"] \*
OverscriptBox[
StyleBox["Y", "TI"], "^"] + \*
StyleBox["f", "TI"] \*
OverscriptBox[
StyleBox["Z", "TI"], "^"]\)]], FontSize -> 18, Black], 
     Style["rotation through " <> ToString[TraditionalForm@α] <>
        " about Z–axis\nNew Coordinate System x'y'z'; z'\
≡Z", 18, Red], 
     Style["rotation through " <> ToString[TraditionalForm@β] <>
        " about x'–axis\nNew Coordinate System x''y''z''; x\
''≡x'", 18, Green], 
     Style["rotation through " <> ToString[TraditionalForm@γ] <>
        " about z''–axis\nFinal Coordinate System xyz; z\
≡z''", 18, Blue]}, LegendFunction -> "Frame", 
    LegendLayout -> "Column"]]]

So for example

EllipsoidalFunMod[12, 21, 30, 3, 5, 19, Pi/4, Pi/6, Pi/3, {}]

enter image description here

and similarly

enter image description here

etc.

Block[{$PerformanceGoal = "Speed"}, 
 Manipulate[
  EllipsoidalFunMod[d, e, f, a, b, 
   c, α, β, γ, {}], {{d, 0}, -10, 10, 
   1}, {{e, 0}, -10, 10, 1}, {{f, 0}, -10, 10, 1}, {{a, 1}, 1, 10, 
   1}, {{b, 1}, 1, 10, 1}, {{c, 1}, 1, 100, 1}, {{α, 0}, 0, 
   2 Pi, Pi/10}, {{β, 0}, 0, 2 Pi, Pi/10}, {{γ, 0}, 0, 
   2 Pi, Pi/10}]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.