'd' of plane - rotation?

Started by
11 comments, last by Kalasjniekof 18 years, 10 months ago
Of course, if you use a 4x4 rotation matrix with no translation, then the normal part is rotated just like any vector and the 4th component (distance plane to origin in the direction of the normal) is unmodified. So you can rotate a plane with the "same" operator as an homogenous vector : the standard 4x4 * 1x4 matrix multiplication.

More interesting is the case of translation.

When you translate a plane (N,d) by T : you add -T*N to d.
So since it's linear, in terms of matrix, you multiply the plane considered as a vector of 4 dimensions by :
[ 1   0   0  0 ][ 0   1   0  0 ][ 0   0   1  0 ][-Tx -Ty -Tz 1 ]


You see that it does not correspond to the translation matrix used for points :
[ 1   0   0  Tx][ 0   1   0  Ty][ 0   0   1  Tz][ 0   0   0  1 ]


This means that apart pure rotations, you can not multiply a plane (seen as a 1x4 matrix) by a general transformation matrix (used for points and vectors).

In terms of code you need a special function to transform planes.

EDIT : glSmurph just gave this code. Except that he uses the convention origin to plane which gives :
dist(P, Plane) = P.x*Plane.x + P.y*Plane.z + P.x*Plane.x - Plane.d

The minus is unpractical since you can not use the 4D dot product that works so well with SIMD instruction sets. If you use the other convention (the one I use) just replace :

p.d = -_14*t[0] + -_24*t[1] + -_34*t[2] + _44*p.d;

and it's OK. Still, be conscious that this code does not work when the transfo contains scaling.

[Edited by - Charles B on May 30, 2005 5:25:19 PM]
"Coding math tricks in asm is more fun than Java"
Advertisement
ok, I'll look into it when I get back from school. tnx all!
Sorry to bother you again, but I'm having trouble understanding glSmurph's code.

I represent my matrix like this

typedef float matrix4x4[16];

so it is represented like this

| 0 4 8 12 |
| 1 5 9 13 |
| 2 6 10 14 |
| 3 7 11 15 |

Can I multiply like this then? (for both translation and rotation, as I try to avoid scaling as much as I can)

void PlaneMatMult(SPlane *plane, float *mat, SPlane *dest){	dest->a = plane->a*mat[0] + plane->b*mat[4] + plane->c*mat[8] + mat[12];	dest->b = plane->a*mat[1] + plane->b*mat[5] + plane->c*mat[9] + mat[13];	dest->c = plane->a*mat[2] + plane->b*mat[6] + plane->c*mat[10] + mat[14];  	dest->d = plane->a*mat[3] + plane->b*mat[7] + plane->c*mat[11] + mat[15];}

This topic is closed to new replies.

Advertisement