[ODE] Vector in world coordinates

Remi Ricard remi.ricard at simlog.com
Thu Mar 15 17:14:40 MST 2007


Hi,

> That sounds like an idea Jon, might give that a go. But in the mean time,
> the following seems to work (although if anyone could explain why or how,
> that would be great) :-):
> 
> Given the points in the form:
> 
> dReal points[]= // points for a cube
>  {
>    0.25f,0.25f,0.25f,  //  point 0
>    -0.25f,0.25f,0.25f, //  point 1
> 
>    0.25f,-0.25f,0.25f, //  point 2
>    -0.25f,-0.25f ,0.25f,//  point 3
> 
>    0.25f,0.25f,-0.25f, //  point 4
>    -0.25f,0.25f,-0.25f,//  point 5
> 
>    0.25f,-0.25f,-0.25f,//  point 6
>    -0.25f,-0.25f,-0.25f,// point 7
>  };


> 
> The following seems to work: (taken from test_boxstack and convex.cpp by
> Rodrigo Hernandez)
> 
> j loops through number of points
> dMULTIPLY0_331 (aPoint,cvx2.final_posr->R,cvx2.points+(j*3));
>            aPoint[0]+=cvx2.final_posr->pos[0];
>            aPoint[1]+=cvx2.final_posr->pos[1];
>            aPoint[2]+=cvx2.final_posr->pos[2];
> 
> 
> I don't get why or how it works though. The code for the macro is below, 
> and
> seems to make aPoint equal to the dot product of various parts of the
> rotation matrix of cvx2.final_posr in the direction of each point...I'm
> getting awfully lost with it.
> 
> #define dMULTIPLYOP0_331(A,op,B,C) \
> do { \
>  (A)[0] op dDOT((B),(C)); \
>  (A)[1] op dDOT((B+4),(C)); \
>  (A)[2] op dDOT((B+8),(C)); \
> }
> 
> 
> Lewis

This is working since dMatrix3 (or dMatrix I don't remember) and
dVector3 are really array of 4
So the matrix can be seen as 3 rows of 4 dReals and dVector3 is an array
of 4 real and usually the the 4th item is neglected.

So the function dMultiplyOP0_331 is equivalent to
transforming a vector by the rotation matrix of the geometry

B is really
B = {a1,a2,a3,dummy,
      b1,b2,b3,dummy,
      c1,c2,c3,dummy};

So this is what is really done:
do { \
>  (A)[0] op dDOT((B),(C));  // A[0]=B[0]*C[0] + B[1]*C[1] +  B[2]*C[2]
                              // Skip to second row or B[4+i]
>  (A)[1] op dDOT((B+4),(C)); // A[1]=B[4]*C[0] + B[5]*C[1] +  B[6]*C[2]
>  (A)[2] op dDOT((B+8),(C)); \
> }


or
for j ... number of points
aPoint[0] = cvx2.final_posr->R[0][0] * cvx2.points[j*3 + 0] +
             cvx2.final_posr->R[0][1] * cvx2.points[j*3 + 1] +
             cvx2.final_posr->R[0][2] * cvx2.points[j*3 + 2];

aPoint[1] = cvx2.final_posr->R[1][0] * cvx2.points[j*3 + 0] +
             cvx2.final_posr->R[1][1] * cvx2.points[j*3 + 1] +
             cvx2.final_posr->R[1][2] * cvx2.points[j*3 + 2];

aPoint[2] = cvx2.final_posr->R[1][0] * cvx2.points[j*3 + 0] +
             cvx2.final_posr->R[1][1] * cvx2.points[j*3 + 1] +
             cvx2.final_posr->R[1][2] * cvx2.points[j*3 + 2];


Remi



More information about the ODE mailing list