Search code examples
3dprojectionperspectiveplane

Perspective projection of an object on a plane in 3D


Imagine there is plane in between a virtual person and an object. The object is a box with a certain xyz scaling and rotation. The plane is like a glass window. The person is looking at the object through the plane. The camera is looking at the whole scene from a different angle.

I would like to draw the outline of the object onto the plane the way the person would see it, as if he were drawing on the window the outline of the object on the other side.

How can I transform the object so that its vertices end up on the plane correctly?

I know how to do a orthogonal projection of a point to a plane, but in this case I need perspective projection I guess. When the object moves further away its projection also needs to be adjusted in size and position according to the viewers perspective.

I think I can figure out the code if only someone would explain the steps I need to take.


Solution

    1. Create a 3D coordinate system centered on human’s eye. Write function to transform points from one system to another. You might also have another system tied to the object. Remember that creating a system is nothing but writing coordinate of system origin and axes in some other default coordinate system. For example: System_human_eye = {Point3f Origin(10, 0, 3), Xaxis(1, 0, 0), Yaxis(0, 1, 0), Zaxis(0, 0, 1) }

    2. In the human eye system, find coordinates of the object vertices and plane normal. Plane equation is p.normal=D, where D is the distance to the plane, p is plane point and normal is plane normal. Ray from human eye to the vertex is k*[x, y, z]; as k changes you travel along the ray. All you need to do now is to travel along the ray till it intersect plane, that is

      k*[x, y, z] . normal = D; find k, restore point p=k*[x, y, z] and this will give you the intersection of the ray with the plane;

    3. Transform all the intersections from the human's eye system to the camera system;

    4. Project these coordinates on screen using openGL or ray tracing. Since straight lines remain straight after perspective projection you may just use them if your object consists of lines. So all you need is to project line endpoints and reconnect them as lines on screen.