Class Projection

java.lang.Object
org.flag4j.linalg.transformations.Projection

public final class Projection extends Object
A utility class for generating projection matrices used in 3D graphics transformations.

Supported Projections:

  • Support for creating perspective projection matrices with specified field-of-view (FOV), aspect ratio, and near/far clipping planes.
  • Support for creating orthogonal projection matrices with customizable boundaries (xMin, xMax, yMin, yMax) and clipping planes.

Examples:


 // Create a perspective projection matrix.
 Matrix perspective = Projection.getPerspective(
      Math.toRadians(60), 16.0/9.0, 0.1, 100.0
 );

 // Create an orthogonal projection matrix.
 Matrix orthogonal = Projection.getOrthogonal(
      -10, 10, -10, 10, 0.1, 100.0
 );
 
  • Method Summary

    Modifier and Type
    Method
    Description
    static Matrix
    getOrthogonal(double xMax, double yMax, double nearClip, double farClip)
    Creates a 4x4 orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e. image plane).
    static Matrix
    getOrthogonal(double xMin, double xMax, double yMin, double yMax, double nearClip, double farClip)
    Creates a 4x4 orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e. image plane).
    static Matrix
    getOrthogonal2D(double xMax, double yMax)
    Creates a 4x4 orthogonal projection matrix to project a 2D point in an orthographic viewing region. the minimum x and y values are assumed to be zero.
    static Matrix
    getOrthogonal2D(double xMin, double xMax, double yMin, double yMax)
    Creates a 4x4 orthogonal projection matrix to project a 2D point in an orthographic viewing region.
    static Matrix
    getPerspective(double fov, double aspectRatio, double nearClip, double farClip)
    Creates a 4x4 perspective projection matrix to transform a 3D point represented in homogeneous coordinates.
    static Matrix
    getPerspective(double fovX, double fovY, double aspectRatio, double nearClip, double farClip)
    Creates a 4x4 perspective projection matrix to transform a 3D point represented in homogeneous coordinates.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getPerspective

      public static Matrix getPerspective(double fov, double aspectRatio, double nearClip, double farClip)
      Creates a 4x4 perspective projection matrix to transform a 3D point represented in homogeneous coordinates.
      Parameters:
      fov - Field of view in radians (this is the fov in both the x and y directions). For distinct field of views see getPerspective(double, double, double, double, double).
      aspectRatio - Aspect ratio of the image plane to project to (i.e. width/height).
      nearClip - The distance from the camera to the near clipping plane.
      farClip - The distance from the camera to the far clipping plane.
      Returns:
      The perspective projection matrix based on the provided attributes.
      Throws:
      IllegalArgumentException - If aspectRatio is not positive.
      AssertionError - If nearClip!=farClip.
    • getPerspective

      public static Matrix getPerspective(double fovX, double fovY, double aspectRatio, double nearClip, double farClip)
      Creates a 4x4 perspective projection matrix to transform a 3D point represented in homogeneous coordinates.
      Parameters:
      fovX - Field of view, in radians, in the x direction.
      fovY - Field of view, in radians, in the y direction.
      aspectRatio - Aspect ratio of the image plane to project to (i.e. width/height).
      nearClip - The distance from the camera to the near clipping plane.
      farClip - The distance from the camera to the far clipping plane.
      Returns:
      The perspective projection matrix based on the provided attributes.
      Throws:
      IllegalArgumentException - If aspectRatio is not positive.
      AssertionError - If nearClip!=farClip.
    • getOrthogonal

      public static Matrix getOrthogonal(double xMin, double xMax, double yMin, double yMax, double nearClip, double farClip)
      Creates a 4x4 orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e. image plane). This is an orthographic projection meaning the distance from the virtual camera will not affect the projection.
      Parameters:
      xMin - Minimum x value of image plane to project to.
      xMax - Maximum x value of image plane to project to.
      yMin - Minimum y value of image plane to project to.
      yMax - Maximum y value of image plane to project to.
      nearClip - Distance from camera to near clipping plane.
      farClip - Distance from camera to far clipping plane.
      Returns:
      The orthogonal projection for the specified parameters.
    • getOrthogonal

      public static Matrix getOrthogonal(double xMax, double yMax, double nearClip, double farClip)
      Creates a 4x4 orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e. image plane). Here, the minimum x and y values are taken to be zero. This is an orthographic projection meaning the distance from the virtual camera will not affect the projection.
      Parameters:
      xMax - Maximum x value of image plane to project to.
      yMax - Maximum y value of image plane to project to.
      nearClip - Distance from camera to near clipping plane.
      farClip - Distance from camera to far clipping plane.
      Returns:
      The orthogonal projection for the specified parameters.
    • getOrthogonal2D

      public static Matrix getOrthogonal2D(double xMin, double xMax, double yMin, double yMax)
      Creates a 4x4 orthogonal projection matrix to project a 2D point in an orthographic viewing region. Equivalent to getOrthogonal(double, double, double, double, double, double) with nearClip = -1 and farClip = 1.
      Parameters:
      xMin - Minimum x value of image plane to project to.
      xMax - Maximum x value of image plane to project to.
      yMin - Minimum y value of image plane to project to.
      yMax - Maximum y value of image plane to project to.
      Returns:
      The orthogonal projection for the specified parameters.
    • getOrthogonal2D

      public static Matrix getOrthogonal2D(double xMax, double yMax)
      Creates a 4x4 orthogonal projection matrix to project a 2D point in an orthographic viewing region. the minimum x and y values are assumed to be zero. Equivalent to getOrthogonal(double, double, double, double) with nearClip=-1 and farClip = 1.
      Parameters:
      xMax - Maximum x value of image plane to project to.
      yMax - Maximum y value of image plane to project to.
      Returns:
      The orthogonal projection for the specified parameters.