Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*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}}]
- (*"Total Rotator"*)
- (R[α_, β_, γ_] = Rzdoubleprime.Rxprime.Rz) // MatrixForm
- (*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}]}
- 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 EllipsoidnEllipsoidal
- 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–axisnNew Coordinate System x'y'z'; z'
- ≡Z", 18, Red],
- Style["rotation through " <> ToString[TraditionalForm@β] <>
- " about x'–axisnNew Coordinate System x''y''z''; x
- ''≡x'", 18, Green],
- Style["rotation through " <> ToString[TraditionalForm@γ] <>
- " about z''–axisnFinal Coordinate System xyz; z
- ≡z''", 18, Blue]}, LegendFunction -> "Frame",
- LegendLayout -> "Column"]]]
- EllipsoidalFunMod[12, 21, 30, 3, 5, 19, Pi/4, Pi/6, Pi/3, {}]
- 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}]]
Add Comment
Please, Sign In to add comment