There's something wrong with the function shape.setVertices() of polyhedra.

Asked by MikeZhao

Hi there, I find that there will be something wrong when I use shape.setVertices() to update the coords of polyhedra element.
The following is a simple example:

a = [[0,0,0],[0,0,1],[0,1,0],[1,0,0]]
b = [[0,0,0],[0,0,1],[0,1,0],[2,0,0]]
The I created two tetraPoly Elements:
The first one:
O.bodies.append(yade.utils.tetraPoly(a))
And the second one:
O.bodies.append(yade.utils.tetraPoly(b))

We can get the two elements' geometrical parameters:

/******** The first one: *********/
Local coords:
[Vector3(0.816496580927726,-2.7755575615628914e-17,0.14433756729740668),
 Vector3(-0.408248290463863,0.7071067811865476,0.14433756729740627),
 Vector3(-0.40824829046386313,-0.7071067811865475,0.14433756729740638),
 Vector3(1.1102230246251565e-16,0,-0.43301270189221935)]
Center position:
Vector3(0.25,0.25,0.25)
And orientation:
Quaternion((-0.7692737357538557,0.5902844985873291,-0.24450384497347377),0.9878610573978008)

/******** The second one: *********/
Local coords:
[Vector3(1.540585613069975,-2.7755575615628914e-17,0.03994957824318643),
 Vector3(-0.5735312506428961,0.7071067811865476,0.21462037306834483),
 Vector3(-0.5735312506428962,-0.7071067811865477,0.2146203730683448),
 Vector3(-0.3935231117841831,-2.7755575615628914e-17,-0.46919032437987607)]
Center position:
Vector3(0.5,0.25,0.25)
And orientation:
Quaternion((-0.947296213713065,0.29597311537489573,-0.12259607848609863),0.8244158709535887)

Then, we use 'shape.setVertices()' function to pass the coords of the second element to the first one:
O.bodies[0].shape.setVertices(b)
/******** The first one's geometrical parameters after calling 'setVertices': *********/
Local coords:
[Vector3(1.540585613069975,-2.7755575615628914e-17,0.03994957824318643),
 Vector3(-0.5735312506428961,0.7071067811865476,0.21462037306834483),
 Vector3(-0.5735312506428962,-0.7071067811865477,0.2146203730683448),
 Vector3(-0.3935231117841831,-2.7755575615628914e-17,-0.46919032437987607)]
Center position:
Vector3(0.25,0.25,0.25)
And orientation:
Quaternion((-0.7692737357538557,0.5902844985873291,-0.24450384497347377),0.9878610573978008)

It seems that the 'setVertices() function only changed the Local coords of the element, leaving Center position and orientation of the element unchanged, which will make the global coordinates of the element go wrong.
Could you please help me find out a solution to correct this? Thank you very much!

Question information

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

Hi Mike,
I agree that this behavior might be a bit confusing.. But the logic is that
you call setVertices an Shape instance, which does not know about its
State. To make it work like you want, make something similar like in
tetraPoly [1] or polyhedron [2] functions. You can then put it in single
function to save some lines of code if you are going to use it repeatedly.

###########################################
b.shape.setVertices(v)
b.state.pos = b.shape.GetCentroid()
b.state.ori = b.shape.GetOri()
b.state.mass = b.mat.density * b.shape.GetVolume()
b.state.inertia = b.mat.density * b.shape.GetInertia()
###########################################

cheers
Jan

[1] https://github.com/yade/trunk/blob/master/py/utils.py#L268
[2] https://github.com/yade/trunk/blob/master/py/utils.py#L314

2016-04-12 8:52 GMT+02:00 MikeZhao <email address hidden>:

> New question #290716 on Yade:
> https://answers.launchpad.net/yade/+question/290716
>
> Hi there, I find that there will be something wrong when I use
> shape.setVertices() to update the coords of polyhedra element.
> The following is a simple example:
>
> a = [[0,0,0],[0,0,1],[0,1,0],[1,0,0]]
> b = [[0,0,0],[0,0,1],[0,1,0],[2,0,0]]
> The I created two tetraPoly Elements:
> The first one:
> O.bodies.append(yade.utils.tetraPoly(a))
> And the second one:
> O.bodies.append(yade.utils.tetraPoly(b))
>
> We can get the two elements' geometrical parameters:
>
> /******** The first one: *********/
> Local coords:
> [Vector3(0.816496580927726,-2.7755575615628914e-17,0.14433756729740668),
> Vector3(-0.408248290463863,0.7071067811865476,0.14433756729740627),
> Vector3(-0.40824829046386313,-0.7071067811865475,0.14433756729740638),
> Vector3(1.1102230246251565e-16,0,-0.43301270189221935)]
> Center position:
> Vector3(0.25,0.25,0.25)
> And orientation:
>
> Quaternion((-0.7692737357538557,0.5902844985873291,-0.24450384497347377),0.9878610573978008)
>
> /******** The second one: *********/
> Local coords:
> [Vector3(1.540585613069975,-2.7755575615628914e-17,0.03994957824318643),
> Vector3(-0.5735312506428961,0.7071067811865476,0.21462037306834483),
> Vector3(-0.5735312506428962,-0.7071067811865477,0.2146203730683448),
> Vector3(-0.3935231117841831,-2.7755575615628914e-17,-0.46919032437987607)]
> Center position:
> Vector3(0.5,0.25,0.25)
> And orientation:
>
> Quaternion((-0.947296213713065,0.29597311537489573,-0.12259607848609863),0.8244158709535887)
>
> Then, we use 'shape.setVertices()' function to pass the coords of the
> second element to the first one:
> O.bodies[0].shape.setVertices(b)
> /******** The first one's geometrical parameters after calling
> 'setVertices': *********/
> Local coords:
> [Vector3(1.540585613069975,-2.7755575615628914e-17,0.03994957824318643),
> Vector3(-0.5735312506428961,0.7071067811865476,0.21462037306834483),
> Vector3(-0.5735312506428962,-0.7071067811865477,0.2146203730683448),
> Vector3(-0.3935231117841831,-2.7755575615628914e-17,-0.46919032437987607)]
> Center position:
> Vector3(0.25,0.25,0.25)
> And orientation:
>
> Quaternion((-0.7692737357538557,0.5902844985873291,-0.24450384497347377),0.9878610573978008)
>
> It seems that the 'setVertices() function only changed the Local coords of
> the element, leaving Center position and orientation of the element
> unchanged, which will make the global coordinates of the element go wrong.
> Could you please help me find out a solution to correct this? Thank you
> very much!
>
>
> --
> You received this question notification because your team yade-users is
> an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Can you help with this problem?

Provide an answer of your own, or ask MikeZhao for more information if necessary.

To post a message you must log in.