Class Projection


  • public final class Projection
    extends Object
    Project each Vertex of a Model from camera coordinates to the Camera's image plane z = -1.

    Let us derive the formulas for the perspective projection transformation (the formulas for the parallel projection transformation are pretty obvious). We will derive the x-coordinate formula; the y-coordinate formula is similar.

    Let (x_c, y_c, z_c) denote a point in the 3-dimensional camera coordinate system. Let (x_p, y_p, -1) denote the point's perspective projection into the image plane, z = -1. Here is a "picture" of just the xz-plane from camera space. This picture shows the point (x_c, z_c) and its projection to the point (x_p, -1) in the image plane.

    
               x
               |                             /
               |                           /
           x_c +                         + (x_c, z_c)
               |                       / |
               |                     /   |
               |                   /     |
               |                 /       |
               |               /         |
               |             /           |
           x_p +           +             |
               |         / |             |
               |       /   |             |
               |     /     |             |
               |   /       |             |
               | /         |             |
               +-----------+-------------+------------> -z
            (0,0)         -1            z_c
    

    We are looking for a formula that computes x_p in terms of x_c and z_c. There are two similar triangles in this picture that share a vertex at the origin. Using the properties of similar triangles we have the following ratios. (Remember that these are ratios of positive lengths, so we write -z_c, since z_c is on the negative z-axis).

    
                     x_p       x_c
                    -----  =  -----
                      1       -z_c
    

    If we solve this ratio for the unknown, x_p, we get the projection formula,

    
                     x_p = -x_c / z_c.
    

    The equivalent formula for the y-coordinate is

    
                     y_p = -y_c / z_c.
    
    • Method Detail

      • project

        public static Model project​(Model model,
                                    Camera camera)
        Project each Vertex from a Model to the Camera's image plane z = -1.

        This pipeline stage assumes that the model's vertices have all been transformed to the camera coordinate system.

        Parameters:
        model - Model whose Vertex objects are to be projected onto the image plane
        camera - a reference to the Scene's Camera object
        Returns:
        a new Model object holding the projected Vertex objects