Rotating a 3D body in sympy.physics.mechanics #21690
Replies: 7 comments 4 replies
-
Do you have some (short?) code that demonstrates this? |
Beta Was this translation helpful? Give feedback.
-
Dear Oscar,
I do not know how to put the code on github.
Jason explained to me, but I am too dumb to do it.
Please send your email to me,
***@***.*** ***@***.***>*
then I will send the code to you.
On Wed 30. Jun 2021 at 15:20, Oscar Benjamin ***@***.***> wrote:
Do you have some (short?) code that demonstrates this?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#21690 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AT5MQUS2GLRAYQKKZAELZXDTVMK3PANCNFSM47R5H5SQ>
.
--
Best regards,
Peter Stahlecker
|
Beta Was this translation helpful? Give feedback.
-
Dear Jason,
I would be very grateful if you would do this!
Seems I am too old to learn certain things!
So, YES, please post it!
On Wed 30. Jun 2021 at 16:03, Jason K. Moore ***@***.***> wrote:
Peter, can I post your notebook you sent me publicly? If so I'll make a
gist for it.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#21690 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AT5MQUXRTF4D3GGPKWIE77TTVMP3PANCNFSM47R5H5SQ>
.
--
Best regards,
Peter Stahlecker
|
Beta Was this translation helpful? Give feedback.
-
I have made the comparison 'Body' vs. auxiliary frames and 'Axis' on several examples. |
Beta Was this translation helpful? Give feedback.
-
To get to the bottom of this a simple example of a single rigid body with orientations formed in each way could reveal the discrepancies. Basically, use |
Beta Was this translation helpful? Give feedback.
-
I will do exactly this and will inform you about the outcome.
On Mon 5. Jul 2021 at 09:31, Jason K. Moore ***@***.***> wrote:
To get to the bottom of this a simple example of a single rigid body with
orientations formed in each way could reveal the discrepancies. Basically,
use KanesMethod to form Euler's equations of motion and associated
kinematic differential equations for the Euler angles with the two
different kinematic definitions. That would give the simplest example to
examine.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#21690 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AT5MQUWXLF6BKMHRZT3GLFLTWFNUNANCNFSM47R5H5SQ>
.
--
Best regards,
Peter Stahlecker
|
Beta Was this translation helpful? Give feedback.
-
This is my example, a simple 3D pendulum with one body.
On my iPad, the operations count in rhs was
- 43,722 in case of ‚Axis‘
- 863,824 in case of ‚Body‘
# 3D pedulum with one body.
from sympy.physics.mechanics import *
import sympy
from sympy import lambdify, symbols, count_ops
import numpy as np
import time
start = time.time()
q1, q2, q3 = dynamicsymbols('q1, q2, q3')
u1, u2, u3 = dynamicsymbols('u1, u2, u3')
q1d, q2d, q3d = dynamicsymbols('q1, q2, q3', 1)
m, g, l = symbols('m , g, l')
iXX, iYY, iZZ = symbols('iXX, iYY, iZZ')
N = ReferenceFrame('N')
P0 = Point('P0')
P0.set_vel(N, 0)
#==============================================================================
keyword = 'Body' # Please enter which method, 'Body'
or 'Axis' will be used
#===============================================================================
if keyword == 'Body':
A = N.orientnew('A', 'Body', (q2, q1, q3), '213')
else:
Ly = N.orientnew('Ly', 'Axis', [q2, N.y])
Lx = Ly.orientnew('Lx', 'Axis', [q1, Ly.x])
A = Lx.orientnew('A', 'Axis', [q3, Lx.z])
rot = A.ang_vel_in(N)
A.set_ang_vel(N, u1*N.x + u2*N.y + u3*N.z)
rot1 = A.ang_vel_in(N)
P1 = P0.locatenew('A', l*A.y)
P1.v2pt_theory(P0, N, A)
I = inertia(A, iXX, iYY, iZZ)
P1a = RigidBody('P1a', P1, A, m, (I, P1))
BODY = [P1a]
kd = [dot(rot - rot1, uv) for uv in N]
FL = [(P1, - m*g*N.y)]
q = [q1, q2, q3]
u = [u1, u2, u3]
KM = KanesMethod(N, q_ind=q, u_ind=u, kd_eqs=kd)
(fr, frstar) = KM.kanes_equations(BODY, FL)
MM = KM.mass_matrix_full
force = KM.forcing_full
rhs = KM.rhs()
print("with method '{}' RHS contains {} operations".format(keyword,
np.sum(np.array([count_ops(rhs[j]) for j in range(len(rhs))]))))
qL = q + u
pL = [g, m, l, iXX, iYY, iZZ]
MM_lam = lambdify(qL + pL, MM)
force_lam = lambdify(qL + pL, force)
print("it took {:.3f} sec to establish Kanes's
equations".format(time.time() - start))
On Mon 5. Jul 2021 at 10:22 Jason K. Moore ***@***.***> wrote:
Sounds good. Pasting a simple script here that we can rerun is easiest.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#21690 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AT5MQUXPFZ4RVRYURQMVJHDTWFTUBANCNFSM47R5H5SQ>
.
--
Best regards,
Peter Stahlecker
|
Beta Was this translation helpful? Give feedback.
-
When I want to rotate a body there are two options:
A.) Do it all at once, using the ‚Body‘ key word in A = N.orientnew(…..)
B.) Introduce two intermediate frames, and use the ‚Axis‘ keyword
The result is the same. However, option A seems to create much ‚larger‘ equations of motion compared to option B, anf hence calculation last much longer. Im one of my programs the size of the rhs of the equations of motion with Axis was only around 7% des size of the same with ‚Body‘.
As per an expert, option A should be faster.
I am just an amateur in this field. I wonder, whether I did something wrong in my programming, or whether this effect is real.
Any help / explanation is highly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions