Class Projection
java.lang.Object
org.flag4j.linalg.transformations.Projection
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 TypeMethodDescriptionstatic MatrixgetOrthogonal(double xMax, double yMax, double nearClip, double farClip) Creates a \( 4\times4 \) orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e. image plane).static MatrixgetOrthogonal(double xMin, double xMax, double yMin, double yMax, double nearClip, double farClip) Creates a \( 4\times4 \) orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e. image plane).static MatrixgetOrthogonal2D(double xMax, double yMax) Creates a \( 4\times4 \) orthogonal projection matrix to project a 2D point in an orthographic viewing region.static MatrixgetOrthogonal2D(double xMin, double xMax, double yMin, double yMax) Creates a \( 4\times4 \) orthogonal projection matrix to project a 2D point in an orthographic viewing region.static MatrixgetPerspective(double fov, double aspectRatio, double nearClip, double farClip) Creates a \( 4\times4 \) perspective projection matrix to transform a 3D point represented in homogeneous coordinates.static MatrixgetPerspective(double fovX, double fovY, double aspectRatio, double nearClip, double farClip) Creates a \( 4\times4 \) perspective projection matrix to transform a 3D point represented in homogeneous coordinates.
-
Method Details
-
getPerspective
public static Matrix getPerspective(double fov, double aspectRatio, double nearClip, double farClip) Creates a \( 4\times4 \) 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 thexandydirections). For distinct field of views seegetPerspective(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- IfaspectRatiois not positive.AssertionError- IfnearClip!=farClip.
-
getPerspective
public static Matrix getPerspective(double fovX, double fovY, double aspectRatio, double nearClip, double farClip) Creates a \( 4\times4 \) perspective projection matrix to transform a 3D point represented in homogeneous coordinates.- Parameters:
fovX- Field of view, in radians, in thexdirection.fovY- Field of view, in radians, in theydirection.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- IfaspectRatiois not positive.AssertionError- IfnearClip!=farClip.
-
getOrthogonal
public static Matrix getOrthogonal(double xMin, double xMax, double yMin, double yMax, double nearClip, double farClip) Creates a \( 4\times4 \) 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- Minimumxvalue of image plane to project to.xMax- Maximumxvalue of image plane to project to.yMin- Minimumyvalue of image plane to project to.yMax- Maximumyvalue 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
Creates a \( 4\times4 \) orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e. image plane). Here, the minimumxandyvalues are taken to be zero. This is an orthographic projection meaning the distance from the virtual camera will not affect the projection.- Parameters:
xMax- Maximumxvalue of image plane to project to.yMax- Maximumyvalue 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
Creates a \( 4\times4 \) orthogonal projection matrix to project a 2D point in an orthographic viewing region. Equivalent togetOrthogonal(double, double, double, double, double, double)withnearClip = -1andfarClip = 1.- Parameters:
xMin- Minimumxvalue of image plane to project to.xMax- Maximumxvalue of image plane to project to.yMin- Minimumyvalue of image plane to project to.yMax- Maximumyvalue of image plane to project to.- Returns:
- The orthogonal projection for the specified parameters.
-
getOrthogonal2D
Creates a \( 4\times4 \) orthogonal projection matrix to project a 2D point in an orthographic viewing region. The minimumxandyvalues are assumed to be zero. Equivalent togetOrthogonal(double, double, double, double)withnearClip=-1andfarClip = 1.- Parameters:
xMax- Maximumxvalue of image plane to project to.yMax- Maximumyvalue of image plane to project to.- Returns:
- The orthogonal projection for the specified parameters.
-