Guest User

Untitled

a guest
Mar 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. (*Euler angles*)
  2. MatrixForm[
  3. Rz = {{Cos[α], Sin[α], 0}, {-Sin[α],
  4. Cos[α], 0}, {0, 0, 1}}]
  5. MatrixForm[
  6. Rxprime = {{1, 0, 0}, {0, Cos[β],
  7. Sin[β]}, {0, -Sin[β], Cos[β]}}]
  8. MatrixForm[
  9. Rzdoubleprime = {{Cos[γ], Sin[γ], 0}, {-Sin[γ],
  10. Cos[γ], 0}, {0, 0, 1}}]
  11.  
  12. (*"Total Rotator"*)
  13. (R[α_, β_, γ_] = Rzdoubleprime.Rxprime.Rz) // MatrixForm
  14.  
  15. (*Translation*)
  16. OffsetTrans[d_, e_, f_] := {d, e, f};
  17.  
  18. (*Parametric Equations of Arbitrarily Rotated and Translated Ellipsoid*)
  19.  
  20. X0[x0_, y0_, z0_] := {x0, y0, z0};
  21.  
  22. XPar[θ_, ϕ_, a_, b_, c_, α_, β_, γ_] =
  23. R[α, β, γ].X0[x0, y0, z0] /. {x0 ->
  24. a Cos[θ] Sin[ϕ], y0 -> b Sin[θ] Sin[ϕ],
  25. z0 -> c Cos[ϕ]};
  26. XParTrans[d_, e_, f_, a_, b_, c_, α_, β_, γ_] =
  27. OffsetTrans[d, e, f] +
  28. XPar[θ, ϕ, a, b, c, α, β, γ];
  29.  
  30. (*Ellipsoidal Axes*)
  31.  
  32. (*Non rotated; no translated*)
  33. Cross0[a_, b_, c_] := {Line[{{-a, 0, 0}, {a, 0, 0}}],
  34. Line[{{0, -b, 0}, {0, b, 0}}], Line[{{0, 0, -c}, {0, 0, c}}]}
  35.  
  36. (*rotated but not translated*)
  37. CrossRot0[a_, b_,
  38. c_, α_, β_, γ_] := {Line[{R[α, β,
  39. γ].{-a, 0, 0}, R[α, β, γ].{a, 0, 0}}],
  40. Line[{R[α, β, γ].{0, -b, 0},
  41. R[α, β, γ].{0, b, 0}}],
  42. Line[{R[α, β, γ].{0, 0, -c},
  43. R[α, β, γ].{0, 0, c}}]}
  44.  
  45. (*rotated and translated; final coordinate system: xyz*)
  46. CrossRotTrans[d_, e_, f_, a_, b_,
  47. c_, α_, β_, γ_] := {Line[{R[α, β,
  48. γ].{-a, 0, 0} + {d, e, f},
  49. R[α, β, γ].{a, 0, 0} + {d, e, f}}],
  50. Line[{R[α, β, γ].{0, -b, 0} + {d, e, f},
  51. R[α, β, γ].{0, b, 0} + {d, e, f}}],
  52. Line[{R[α, β, γ].{0, 0, -c} + {d, e, f},
  53. R[α, β, γ].{0, 0, c} + {d, e, f}}]}
  54.  
  55. (*rotated and translated; first intermediate coordinate system: x'y'z'*)
  56. CrossRotTransAlpha[d_, e_, f_, a_, b_,
  57. c_, α_, β_, γ_] := {Line[{R[α, 0, 0].{-a, 0,
  58. 0} + {d, e, f}, R[α, 0, 0].{a, 0, 0} + {d, e, f}}],
  59. Line[{R[α, 0, 0].{0, -b, 0} + {d, e, f},
  60. R[α, 0, 0].{0, b, 0} + {d, e, f}}],
  61. Line[{R[α, 0, 0].{0, 0, -c} + {d, e, f},
  62. R[α, 0, 0].{0, 0, c} + {d, e, f}}]}
  63.  
  64. (*rotated and translated; second intermediate coordinate system: x''y''z''*)
  65. CrossRotTransBetaAlpha[d_, e_, f_, a_, b_,
  66. c_, α_, β_, γ_] := {Line[{R[α, β, 0].{-a,
  67. 0, 0} + {d, e, f}, R[α, β, 0].{a, 0, 0} + {d, e, f}}],
  68. Line[{R[α, β, 0].{0, -b, 0} + {d, e, f},
  69. R[α, β, 0].{0, b, 0} + {d, e, f}}],
  70. Line[{R[α, β, 0].{0, 0, -c} + {d, e, f},
  71. R[α, β, 0].{0, 0, c} + {d, e, f}}]}
  72.  
  73.  
  74. (* Cross sections*)
  75.  
  76. CrossSectionX[d_, e_, f_, a_, b_, c_, α_, β_, γ_] :=
  77. ParametricPlot3D[
  78. OffsetTrans[d, e, f] +
  79. R[α, β, γ].{0, b Cos[ϕ], c Sin[ϕ]}, {ϕ,
  80. 0, 2 Pi}, PlotStyle -> {Dashed, Gray}];
  81.  
  82. CrossSectionY[d_, e_, f_, a_, b_, c_, α_, β_, γ_] :=
  83. ParametricPlot3D[
  84. OffsetTrans[d, e, f] +
  85. R[α, β, γ].{a Cos[ϕ], 0, c Sin[ϕ]}, {ϕ,
  86. 0, 2 Pi}, PlotStyle -> {Dotted, Gray}];
  87.  
  88. CrossSectionZ[d_, e_, f_, a_, b_, c_, α_, β_, γ_] :=
  89. ParametricPlot3D[
  90. OffsetTrans[d, e, f] +
  91. R[α, β, γ].{a Cos[ϕ], b Sin[ϕ], 0}, {ϕ,
  92. 0, 2 Pi}, PlotStyle -> {DotDashed, Gray}];
  93.  
  94.  
  95. (*XYZ system*)
  96. arrowAxesXYZ[arrowLength_] :=
  97. Map[Arrow[Tube[{{0, 0, 0}, #}]] &, arrowLength IdentityMatrix[3]]
  98. AxesXYZ[pos_] := {Text[Style["X", 20, Italic], {pos + 0.2, 0, 0}],
  99. Text[Style["Y", 20, Italic], {0, pos + 0.2, 0}],
  100. Text[Style["Z", 20, Italic], {0, 0, pos + 0.2}]}
  101.  
  102. Clear[g1, g2, g3, g4, g5, g6, g7, g9, EllipsoidalFunMod]
  103. EllipsoidalFunMod[d_, e_, f_, a_, b_,
  104. c_, α_, β_, γ_, {opts___}] :=
  105. Module[{g1, g2, g3, g4, g5, g6, g7, g8},
  106. g2 = CrossRotTrans[d, e, f, a, b, c, α, β, γ];
  107. g3 = CrossSectionX[d, e, f, a, b, c, α, β, γ];
  108. g4 = CrossSectionY[d, e, f, a, b, c, α, β, γ];
  109. g5 = CrossSectionZ[d, e, f, a, b, c, α, β, γ];
  110. g6 = CrossRotTransAlpha[d, e, f, a, b,
  111. c, α, β, γ];
  112. g7 = CrossRotTransBetaAlpha[d, e, f, a, b,
  113. c, α, β, γ];
  114. g1 = ParametricPlot3D[
  115. XParTrans[d, e, f, a, b,
  116. c, α, β, γ], {θ, 0, 2 Pi}, {ϕ, 0,
  117. Pi}, PlotStyle ->
  118. Directive[Orange, Specularity[White, 40], Opacity[0.5]],
  119. Mesh -> None];
  120. g8 = Arrow[Tube[{{0, 0, 0}, {d, e, f}}, 0.05]];
  121. Legended[
  122. Show[{g1,
  123. Graphics3D[{{Black, g8}, {Red, Thick, g6}, {Green, Thick,
  124. g7}, {Blue, Thick, g2}, {Gray, arrowAxesXYZ[30]},
  125. AxesXYZ[31]}], g3, g4, g5}, Axes -> False,
  126. AxesOrigin -> {0, 0, 0}, PlotRange -> All, ImageSize -> Large,
  127. PlotLabel ->
  128. Style[Framed[
  129. "Arbitrarily Oriented & Translated EllipsoidnEllipsoidal
  130. Semi-Axes: ta=" <> ToString[a] <> "tb=" <> ToString[b] <> "tc=" <>
  131. ToString[c]], Blue, 20, Background -> Lighter[Yellow]], opts],
  132. LineLegend[{Directive[Thick, Black], Directive[Thick, Red],
  133. Directive[Thick, Green],
  134. Directive[Thick, Blue]}, {Style[
  135. "Translation by " <>
  136. ToString[TraditionalForm[!(TraditionalForm`*
  137. StyleBox["d", "TI"] *
  138. OverscriptBox[
  139. StyleBox["X", "TI"], "^"] + *
  140. StyleBox["e", "TI"] *
  141. OverscriptBox[
  142. StyleBox["Y", "TI"], "^"] + *
  143. StyleBox["f", "TI"] *
  144. OverscriptBox[
  145. StyleBox["Z", "TI"], "^"])]], FontSize -> 18, Black],
  146. Style["rotation through " <> ToString[TraditionalForm@α] <>
  147. " about Z–axisnNew Coordinate System x'y'z'; z'
  148. ≡Z", 18, Red],
  149. Style["rotation through " <> ToString[TraditionalForm@β] <>
  150. " about x'–axisnNew Coordinate System x''y''z''; x
  151. ''≡x'", 18, Green],
  152. Style["rotation through " <> ToString[TraditionalForm@γ] <>
  153. " about z''–axisnFinal Coordinate System xyz; z
  154. ≡z''", 18, Blue]}, LegendFunction -> "Frame",
  155. LegendLayout -> "Column"]]]
  156.  
  157. EllipsoidalFunMod[12, 21, 30, 3, 5, 19, Pi/4, Pi/6, Pi/3, {}]
  158.  
  159. Block[{$PerformanceGoal = "Speed"},
  160. Manipulate[
  161. EllipsoidalFunMod[d, e, f, a, b,
  162. c, α, β, γ, {}], {{d, 0}, -10, 10,
  163. 1}, {{e, 0}, -10, 10, 1}, {{f, 0}, -10, 10, 1}, {{a, 1}, 1, 10,
  164. 1}, {{b, 1}, 1, 10, 1}, {{c, 1}, 1, 100, 1}, {{α, 0}, 0,
  165. 2 Pi, Pi/10}, {{β, 0}, 0, 2 Pi, Pi/10}, {{γ, 0}, 0,
  166. 2 Pi, Pi/10}]]
Add Comment
Please, Sign In to add comment