Getting the quaternion of a single triangle in a trimesh

13 views
Skip to first unread message

colm...@gmail.com

unread,
Mar 26, 2008, 12:53:00 AM3/26/08
to ode-users
I need the quaternion of a triangle in the trimesh. When there's a
collision, I can use the index and the trimesh along with the get
triangle function to get the vertices of the triangle like so:
dVector3 v0, v1, v2;
dGeomTriMeshGetTriangle( trimeshGeom, triangleIndex, &v0, &v1, &v2 );

I'm actually not concerned with the imaginary 'w' component of the
quaternion so I'm only after the x, y and z. I thought I could get
these by getting the normal of the triangle:
D3DXVECTOR3 dxV1 ( v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2] );
D3DXVECTOR3 dxV2 ( v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2] );
D3DXVec3Cross( &triNormal, &dxV1, &dxV2 );

and then using that cross product of that and the inverse normal to
get the x, y and z components I desire, but it seems I'm very wrong.

Is there an easier way of doing this?

Thanks

Rodrigo Hernandez

unread,
Mar 26, 2008, 12:20:46 PM3/26/08
to ode-...@googlegroups.com

This is the first time I ever hear of triangles inherently having
quaternions, so I don't know what you're talking about, however, I guess
that you could take the triangle normal, normalize one of the sides of
the triangle to get a perpendicular normal, get the cross product of
those to get a second "axis" and finally the cross product of the second
axis and the normal to get the third axis, stuff them in a 3x3 matrix (I
have no idea of the order though) and extract a quaternion from that.

This is of course all just thinking out loud.

Rodrigo Hernandez

unread,
Mar 26, 2008, 12:25:47 PM3/26/08
to ode-...@googlegroups.com

PS: What I described is getting an orthonormal basis.

Jon Watte

unread,
Mar 26, 2008, 2:05:57 PM3/26/08
to ode-...@googlegroups.com
colm...@gmail.com wrote:
> I need the quaternion of a triangle in the trimesh. When there's

> and then using that cross product of that and the inverse normal to


> get the x, y and z components I desire, but it seems I'm very wrong.


That's not a well-defined concept. You have to define what it is you
want better. A triangle does not, inherently, have a "rotation," any
more than it has a "translation." Those concepts can only be defined in
reference to some other state.

Also, normals don't have inverses, as they are vectors, not transforms.

Perhaps what you want is a rotation that takes the normal from the state
the triangle has in an untransformed mesh, and rotates the triangle to
match the new normal? The problem is that there is an infinity of such
rotations, because the triangle can be rotated any degree around the
normal. Perhaps what you want is the shortest circular rotation that
will make the identity normal align with the current triangle normal? Or
do you want the rotation that will make all vertices of the original
triangle align with the current triangle? In all these cases, the
assumed reference is an "untransformed" triangle, but if your triangle
mesh is static (doesn't move), then the rotation will always be identity.

So, if you can define what it is you want, then perhaps someone can help
you come up with how to get that. Or perhaps it falls out directly from
the definition.

Sincerely,

jw

Daniel K. O.

unread,
Mar 26, 2008, 2:58:56 PM3/26/08
to ode-...@googlegroups.com
colm...@gmail.com escreveu:

> I need the quaternion of a triangle in the trimesh.
[...]

> Is there an easier way of doing this?

To put what Rodrigo and John said in simpler terms:

What you said does not make much sense to us. Why don't you tell us what
you are trying to accomplish, so we can try to guide you to the
"easier"/correct solution?

Are you by any chance trying to convert between local/world coordinates?
The dGeomTriMeshGetTriangle() function returns the triangle in world
coordinates. To get local coordinates, just access the trimesh data you
provided to ODE instead of doing the inverse rotation+translation transform.


--
Daniel K. O.
"The only way to succeed is to build success yourself"

colm...@gmail.com

unread,
Mar 28, 2008, 3:37:37 PM3/28/08
to ode-users
Sorry about the late reply. Thanks for all of the feedback.

Apologies for poor explanation of what I want. I'll have another bash
at it. Here's a pic:
http://img510.imageshack.us/img510/7453/explanationce5.gif

how would I get the ray to change direction like this? I was using a
particular formula:
fluidCuboid-
>setNewWindDirection( fabs(dBodyGetQuaternion( dGeomGetBody( dSpaceGetGeom( _turbineSpace,
i )) )[1]),
fabs(dBodyGetQuaternion( dGeomGetBody( dSpaceGetGeom( _turbineSpace,
i )) )[2]),
fabs(dBodyGetQuaternion( dGeomGetBody( dSpaceGetGeom( _turbineSpace,
i )) )[3]) );

and this was working perfectly but now I've changed my setup so I no
longer have contact details (I was testing on a box but now I'm
testing on a trimesh). Any ideas?

colm...@gmail.com

unread,
Mar 28, 2008, 3:42:14 PM3/28/08
to ode-users
Sorry, I forgot to mention that my trimesh isn't static.

Gazi Alankus

unread,
Mar 28, 2008, 4:09:30 PM3/28/08
to ode-...@googlegroups.com
I think the confusion is that the orientation you are looking for
seems not to be unique and can rotate around the normal of the
triangle. Similarly, in step 2 in the image, it seems like the ray
could go to any direction that is parallel to the plane of the
triangle.

I'm just speculating, maybe you want the initial ray to have the
smallest possible angle with the bouncing ray that is constrained to
be in the plane of the triangle (and any direction would be fine if
the ray was exactly parallel to the normal). In this case you can find
the direction of the second ray by just projecting the initial ray to
the plane of the triangle. A simple way to do that is to first project
the ray on the normal and subtract that from the ray.

Hope that helps.

-Gazi

Rodrigo Hernandez

unread,
Mar 28, 2008, 4:27:15 PM3/28/08
to ode-...@googlegroups.com

You don't need to rotate anything, just project the ray on the triangle
plane, to do that, in ODE lingo:

dVector3 output, trinormal ray;
dCROSS(output,=,ray,trinormal);
dCROSS(output,=,trinormal,output);
dNormalize(output);

where trinormal is the triangle normal and ray is the ray's direction
(destination-origin if you have it in segment notation).
output will contain the normalized direction of the projected ray.

You may notice this is very similar to what I described before, getting
the orthonormal basis for the triangle.

Reply all
Reply to author
Forward
0 new messages