Use quaternion to transform coordinate system in yade

Asked by xuanshenyu

Hi,everyone!

I try to use quaternion in yade source code to convert between granular coordinate system and geodetic coordinate system.

Suppose there is a fixed point, p, on the particle, and its coordinate is p1 in the particle coordinate system. We want to obtain the coordinate p2 of the fixed point in the geodetic coordinate system under each time step by the quaternion,Q, of this particle.

I wrote the following code:

###################### ############Ig2_Sphere_Sphere_ScGeom.cpp

bool Ig2_Sphere_Sphere_ScGeom::go(
        const shared_ptr<Shape>& cm1,
        const shared_ptr<Shape>& cm2,
        const State& state1,
        const State& state2,
        const Vector3r& shift2,
        const bool& force,
        const shared_ptr<Interaction>& c)
{
 ......
        const Se3r& se31 = state1.se3;
        const Sphere *s1 = static_cast<Sphere*>(cm1.get()), *s2 = static_cast<Sphere*>(cm2.get());
        Vector3r p1(0,0,s1->radius);
        Vector3r p2;
        p2=Quaternionr(se31,orientation).inverse()*(p1-se31.position) //p2=Q^-1*(p1-position)
       ......
}
################

May I ask if this method is correct?

Thanks for your help :).

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
Last query:
Last reply:
Revision history for this message
Best Jan Stránský (honzik) said :
#1

Hello,

> I try to use quaternion in yade source code

Suggestion: try it in python first.
Why do you need it in C++? Is the value needed in C++?

> granular coordinate system and geodetic coordinate system.

In yade, usually "local" and "global" is used terminology

> May I ask if this method is correct?

of course you may ask.

What also you may do is to test it yourself.
Create an artificial settings, where you know p1 and p2 and test if the code works as expected or not.
If it does not work, then it is not correct.
If it does work, it might be correct.

> May I ask if this method is correct?
> Quaternionr(se31,orientation)

First thing to make it correct is to compile the code and fix errors

> p2=Quaternionr(se31,orientation).inverse()*(p1-se31.position) //p2=Q^-1*(p1-position)

I **guess** (not tested, just intuition, you have to verify yourself) that it should be inverse:
p2 = se31.position + Quaternionr(se31.orientation)*p1 //p2=position+Q*p1
or in Python:
p2 = state.pos + state.ori * p1

Cheers
Jan

Revision history for this message
xuanshenyu (shenyuxuan) said :
#2

Thanks for generous reply, that has solved my confused about the using of Quaternionr in Yade.

Revision history for this message
xuanshenyu (shenyuxuan) said :
#3

Thanks Jan Stránský, that solved my question.