Consider the plane in three dimensional space defined by a point and a normal vector :
Mirroring a point
Mirroring a point with this plane is very straightforward.We calculate the distance from the point to the plane (covered in plane equation in 3D ) and then we use this distance and the calculated normal toget the point pm
.
Important : this formula only works if the normal is a unit vector.
Matrix form
In a 3D application the mirror operation is used to calculate planar reflections (ordinary mirrors or the surface of a lake). To plug the mirror operation into the application it is necessary to represent the mirror operation as a matrix :
p | origin of the plane , a const ant |
p1 | point to mirror |
pm | result of the mirror operation |
We start from the original equation :
OpenGL matrix form
OpenGL stores matrices in column major order and the matrix is simply formed by extracting p1x, p1y and p1zfrom the equations :
DirectX matrix form
DirectX stores matrices in row major order and the matrix is the transpose (switch columns and rows) of the OpenGLmatrix form :
In OpenGL, a 3D point in eye space is projected onto the near plane (projection plane). The following diagrams shows how a point (x, y, z) in eye space is projected to (xp, yp, zp) on the near plane.
ReplyDeleteI liked how linear algebra is applied. Nice post.
ReplyDeleteIt is interesting how you can create a mirror image in three-dimensional space using matrix form. I think it can be simply done using AutoCad program for civil engineers! Mniha Garo Hala Madrid :)!
ReplyDeleteThis aroused my curiosity to know more about Matrices and how they can be used in real life. This post is an interesting one. But i still believe that this is just the beginning of Matrices.
ReplyDeleteHala Madrid
Excellent post Garo!!!!!!!
ReplyDeleteThanks!