Rotating a body in 3D

21 views
Skip to first unread message

Peter Stahlecker

unread,
Jun 28, 2021, 11:09:39 PM6/28/21
to sympy
When I want to do this, it seems to me there are these possibilities:

1.
A = N.orientnew(‚A‘, ‚Body‘, [q1, q2, q3], ‚123‘)
This does it in one step

2.
I use two intermediate frames and use the word ‚Axis‘ instead of ‚Body‘

Geometrically, this should be the same, but it seems to me, that with the intermediate frames establishing Kane‘s equations, lambdifying them and doing the numerical integration is MUCH faster.

Are methods 1 and 2 not equivalent, as I assumed, or am I doing something wrong?

Thanks for any explanation!

Jason Moore

unread,
Jun 29, 2021, 5:32:06 AM6/29/21
to sympy
Peter,

THey are equivalent other than one may provide a simpler set of direction cosine matrices and angular velocity definitions. The "Body" method should give simpler equations of motion in the end because we try to use pre-simplified forms of the equations. I don't know why you'd see faster with the intermediate frame method.

You can use sympy's count_ops() function to see how many operations each symbolic form gives. The one with more operations should ultimately be slower when lambdified().

Jason

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/d1597154-f8a8-42fa-b29b-6e8f57062441n%40googlegroups.com.

Peter Stahlecker

unread,
Jun 29, 2021, 7:00:01 AM6/29/21
to sy...@googlegroups.com
Dear Jason,

Thanks!
I tested it right away, and I counted the operations of an entry of rhs = KM.rhs()

For ‚Body‘ I got the count 245,633
With the auxiliary frames the count was 13,235

Thanks again and stay healthy!

I will keep on testing this.

Peter




--
Best regards,

Peter Stahlecker

Oscar Benjamin

unread,
Jun 29, 2021, 7:09:49 AM6/29/21
to sympy
How do the op counts get into the tens or hundreds of thousands?

When the expressions are that complicated I would have thought that it
was faster and more numerically accurate to perform whatever symbolic
operations are used to obtain those expressions using numerical
routines. For example if a matrix is inverted symbolically it would be
better to substitute your values and invert the matrix numerically
etc. A 3D rotation can be computed very cheaply in floating point with
quaternions.

--
Oscar
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CABKqA0bdrLLiCY7w3yG_3sPTmx7O4Z00tn-mLSssj0rvT4m9QA%40mail.gmail.com.

Peter Stahlecker

unread,
Jun 29, 2021, 7:20:19 AM6/29/21
to sy...@googlegroups.com
Dear Oskar,

It is just one 3D pendulum, one body only.
I have no idea, how big these terms should be.

I am doing this for no other purpose than to spend some time in my semi retirement stage.
(I studied mechanical engineering 45 years ago).
If find this sumpy Kane's method fascinating!

I never looked at these quaternions, because we did not use them when I studied. Maybe I should do it.

Take care, 

Peter

Jason Moore

unread,
Jun 29, 2021, 8:24:36 AM6/29/21
to sympy
Peter,

Sounds like that could use some improvements. I'm not sure why the body fixed rotations are so much worse.

Jason

Jason Moore

unread,
Jun 29, 2021, 8:31:36 AM6/29/21
to sympy
Oscar,

There are essentially two approaches in computational multibody dynamics to arrive at the equations of motion: symbolic first (what SymPy does) or fully numeric (tools like Simbody, Bullet, etc.). You have to calculate derivatives with respect to the coordinates of the system to get Newton and Euler's dynamical equations, thus having the symbolic expressions is one way to calculate those derivatives. The rotations have to be parameterized symbolically for this approach. This is how sympy.physics.mechanics works. The rotations can be designed as quaternions, Euler angles, Rodriguez parameters, Euler parameters, or many other ways, but you still have to compute the derivatives of these symbolically parameterized rotations.

Peter's number of operations is very small compared to many other more complicated multibody problems.

Jason

Peter Stahlecker

unread,
Jun 29, 2021, 8:45:22 AM6/29/21
to sy...@googlegroups.com
Dear Jason,

Maybe it is not 'Body' vs. 'Axis', but my clumpsy programming!
The results look reasonable, but maybe my kinematic equatios are clumsy or....?

Take care!

Peter

Jason Moore

unread,
Jun 29, 2021, 9:17:04 AM6/29/21
to sympy
Peter,

Feel free to open an issue on the sympy github repository with precise instructions on reproducing this and we can look into it.

Jason

Peter Stahlecker

unread,
Jun 30, 2021, 5:23:18 AM6/30/21
to sy...@googlegroups.com
Dear Jason,

I just did what you suggested. I hope I did it right.
I tried to attach the program I used, but I could not do it.

Peter



Reply all
Reply to author
Forward
0 new messages