- #1
Mr. Rho
- 15
- 1
So, I'm trying to plot a 3D "dipole" (an arrow with a small torus around it basically) in mathematica, and want to rotate it according to Euler angles...
I use this code for the rotation matrix:
rot[a, b, g] := RotationMatrix[g, {1, 0, 0}].RotationMatrix[b, {0, 1, 0}].RotationMatrix[a, {0, 0, 1}]
and I obtain the standard Euler angles rotation matrix.
For the arrow and the torus I'm using:
arrow[x_, y_, z_,a_, b_, g_, r_] := Graphics3D[{Red, Cone[{rot[a, b, g].{0, 0, 2^4 r} + {x, y, z}, rot[a, b, g].{0, 0, 2^4 r + 2^2 r} + {x, y, z}}, 3 r], Cylinder[{rot[a, b, g].{0, 0, 0} + {x, y, z}, rot[a, b, g].{0, 0, 2^4 r} + {x, y, z}}, r]}]
torus[x_, y_, z_, a_, b_, g_, r_] := ParametricPlot3D[rot[a, b, g].{(r*Cos[m] + 4 r) Cos[v], (r*Cos[m] + 4 r) Sin[v], r*Sin + z} + {x, y, z}, {m, 0, 2 Pi}, {v, 0, 2 Pi}, Mesh -> None, PlotStyle -> {Green, Opacity[.25]}]
(Note that I also introduced a boost) The next step is to show both plots using manipulate to change the angle and boost values, the code I use is simply:
Manipulate[Show[arrow[x,y,z-8,a,b,g,1], torus[x,y,z,a,b,g,1]], {x,0,1}, {y,0,1}, {z,0,1}, {a,0,2Pi}, {b,0,2Pi}, {g,0,2Pi}]
Everything is ok until here, the plot of a dipole is shown and it moves smootly. The problem is when I start introducing more and more arrows and torus. If I want, for example, 4 dipoles, the plot gets really really slow...
So, any plot optimization tips?
Thank you for your help!
I use this code for the rotation matrix:
rot[a, b, g] := RotationMatrix[g, {1, 0, 0}].RotationMatrix[b, {0, 1, 0}].RotationMatrix[a, {0, 0, 1}]
and I obtain the standard Euler angles rotation matrix.
For the arrow and the torus I'm using:
arrow[x_, y_, z_,a_, b_, g_, r_] := Graphics3D[{Red, Cone[{rot[a, b, g].{0, 0, 2^4 r} + {x, y, z}, rot[a, b, g].{0, 0, 2^4 r + 2^2 r} + {x, y, z}}, 3 r], Cylinder[{rot[a, b, g].{0, 0, 0} + {x, y, z}, rot[a, b, g].{0, 0, 2^4 r} + {x, y, z}}, r]}]
torus[x_, y_, z_, a_, b_, g_, r_] := ParametricPlot3D[rot[a, b, g].{(r*Cos[m] + 4 r) Cos[v], (r*Cos[m] + 4 r) Sin[v], r*Sin + z} + {x, y, z}, {m, 0, 2 Pi}, {v, 0, 2 Pi}, Mesh -> None, PlotStyle -> {Green, Opacity[.25]}]
(Note that I also introduced a boost) The next step is to show both plots using manipulate to change the angle and boost values, the code I use is simply:
Manipulate[Show[arrow[x,y,z-8,a,b,g,1], torus[x,y,z,a,b,g,1]], {x,0,1}, {y,0,1}, {z,0,1}, {a,0,2Pi}, {b,0,2Pi}, {g,0,2Pi}]
Everything is ok until here, the plot of a dipole is shown and it moves smootly. The problem is when I start introducing more and more arrows and torus. If I want, for example, 4 dipoles, the plot gets really really slow...
So, any plot optimization tips?
Thank you for your help!
Last edited: