# Graph a cylinder moving in 3D

I need to generate a graph (series of stills) or animation of a cylinder (or other shape) moving in 3D. The object moves in projectile motion and rotates about two different axes.

Now, I have the actual physical equations that describe how the cylinder moves, so I can solve by hand and manually enter the relevant coordinates to generate a bunch of still images using Graphics3D or something similar.

What I'm interested in is a way to give Mathematica the equations, have it do that math, and then generate an animation of this cylinder flipping in space.

I see from this question & answer that this could be at least partially possible by defining a projectile path for the cylinder to follow based on my equations, but I'm missing how this could be applied for the rotation part. The rotation part could be handled as in this question, but that leaves out the projectile motion. I need both to happen simultaneously. How do I graph/animate projectile and rotational motion simultaneously for a 3D object?

Edit: This is why I don't bother posting here:

y = 1 + 5 t + (1/2)*-9.8*t^2
x = 2 t


Very basic projectile motion equations, can be combined into one parametric equation with sine function. Just made-up variables. I also have an inertia tensor for the cylinder, but that is dependent on axes and coordinate system choice - choices I have not made yet because it is unclear which will be most graphable using Mathematica. I.e. Cartesian coords are great for projectile motion, with origin at launch pt; polar would be great for rotation, with origin at center of mass.

Projectile motion attempt for just a point:

Animate[Show[ParametricPlot3D[{x, -(x - .5)^2 + 2.3, 0}, {x, 0, 1}],Graphics3D[{Purple, PointSize[0.05],
Point[{x, -(x - .5)^2 + 2.3, 0}]}]], {x, 0, 1}]


Unworking projectile motion attempt for cylinder (I can probably figure this out on my own):

Animate[
Graphics3D[Cylinder[{{0, x - .75, 0}, {0, x + .25, 0}}, 0.125],
AlignmentPoint -> {x, -(x - .5)^2 + 2.3, 0}], {x, 0, 1}]


Please note that the cylinder does not rotate about its line of symmetry; rather, it is "top-heavy". So for projectile motion, I am attempting to have its center of mass NOT its center move along the parabola defined in first Animate code (this parabola is what the first two equations produce). Regardless, code above works only for projectile motion, not rotation. What I need is a strategy to get them working together; I can troubleshoot bugs on my own.

• "Now, I have the actual physical equations" - so, where are they? – J. M.'s discontentment Oct 16 '18 at 4:11
• Please have a look at Menu/Help/WolframDocumentation/Cylinder. There you will find how to draw a cylinder in 3D. Implementing your solutions should be then straightforward. Try that and come back with your code and further questions. The rule of this site requires some work to be done by the person who asks a question before receiving an answer. – Alexei Boulbitch Oct 16 '18 at 7:18

The rotation of the cylinder is not as interesting as the rotation of the body, which has three different moments of inertia. Then the body can flip, which is called the Janibekov effect or the effect of a tennis racket. Here I will give an example of a model of this kind.

G3D = RegionUnion[Cone[{{0, 0, 0}, {0, 0, 3}}, 1/2],
Cuboid[{-0.3, -1, 0}, {0.3, 1, 1}]];

c = RegionCentroid[G3D];
J3 = NIntegrate[x^2 + y^2, {x, y, z} ∈ G3D];

J2 = NIntegrate[x^2 + (z - c[[3]])^2, {x, y, z} ∈ G3D];

J1 = NIntegrate[y^2 + (z - c[[3]])^2, {x, y, z} ∈ G3D];

eq1 = {Ω1[
t] == φ'[t]*Sin[θ[t]]*
Sin[ψ[t]] + θ'[t]*Cos[ψ[t]], Ω2[
t] == φ'[t]*Sin[θ[t]]*
Cos[ψ[t]] - θ'[t]*Sin[ψ[t]], Ω3[
t] == φ'[t]*Cos[θ[t]] + ψ'[t]};
eq2 = {J1*Ω1'[t] + (J3 - J2)*Ω2[
t]*Ω3[t] == 0,
J2*Ω2'[t] + (J1 - J3)*Ω1[
t]*Ω3[t] == 0,
J1*Ω3'[t] + (J2 - J1)*Ω2[
t]*Ω1[t] == 0};
eq3 = {φ[0] == .001, θ[0] == .001, ψ[
0] == .001, Ω3[0] ==
10, Ω1[0] == .0, Ω2[0] == .1};

ListAnimate[
Table[Graphics3D[{Cuboid[{5, 5, -3}, {5.2, 5.2, 5}],
Cuboid[{-5, -5, -3.1}, {5, 5, -3}],
GeometricTransformation[{Cone[{{0, 0, 0}, {0, 0, 3}}, 1/2],
Cuboid[{-0.2, -1, 0}, {0.3, 1, 1}]},
EulerMatrix[{NDSolveValue[{eq1, eq2, eq3}, φ[tn], {t,
0, tn}],
NDSolveValue[{eq1, eq2, eq3}, θ[tn], {t, 0, tn}],
NDSolveValue[{eq1, eq2, eq3}, ψ[tn], {t, 0, tn}]}]]},
Boxed -> False, Lighting -> {{"Point", Yellow, {10, 3, 3}}}], {tn,
0, 5, .025}]]


• Thanks for this post! Appreciate it. Can I ask, in your code above, are GeometricTransform and EulerMatrix working together to rotate your shape once the functions governing their motion are determined? And, do you need ListAnimate because you've got the two shapes to manipulate, or because you've got a function to define the shape(s) and a function to manipulate the shape(s)? Please let me know if my questions are unclear. – stuck2 Oct 17 '18 at 2:44
• To describe the rotation of the body, the Euler equations are used, in which the Euler angles appear. EulerMatrix [] performs body turns in accordance with the current values of Euler angles, which are calculated by NDSolveValue[]. ListAnimate[] is used for motion animation. – Alex Trounev Oct 17 '18 at 5:13
• It's a great answer. – A little mouse on the pampas Mar 7 at 6:54
• @PleaseCorrectGrammarMistakes Thank you. The code was written 5 years ago but it still works even in version 12. – Alex Trounev Mar 7 at 11:42