Package org.djutils.draw
Class Transform3d
java.lang.Object
org.djutils.draw.Transform3d
- All Implemented Interfaces:
Cloneable
Transform3d contains a MUTABLE transformation object that can transform points (x,y,z) based on e.g, rotation and
translation. It uses an affine transform matrix that can be built up from different components (translation, rotation,
scaling, reflection, shearing).
Copyright (c) 2020-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
- Author:
- Alexander Verbraeck, Peter Knoppers
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
double[]
getMat()
Get a safe copy of the affine transformation matrix.int
hashCode()
protected static double[]
mulMatMat
(double[] m1, double[] m2) Multiply a 4x4 matrix (stored as a 16-value array by row) with another 4x4-matrix.protected static double[]
mulMatVec
(double[] m, double[] v) Multiply a 4x4 matrix (stored as a 16-value array by row) with a 4-value vector.protected static double[]
mulMatVec3
(double[] m, double[] v) Multiply a 4x4 matrix (stored as a 16-value array by row) with a 3-value vector and a 1 for the 4th value.reflectX()
The reflection of the x-coordinate, by mirroring it in the yz-plane (the plane with x=0).reflectY()
The reflection of the y-coordinate, by mirroring it in the xz-plane (the plane with y=0).reflectZ()
The reflection of the z-coordinate, by mirroring it in the xy-plane (the plane with z=0).rotX
(double angle) The Euler rotation around the x-axis with an angle in radians.rotY
(double angle) The Euler rotation around the y-axis with an angle in radians.rotZ
(double angle) The Euler rotation around the z-axis with an angle in radians.scale
(double sx, double sy, double sz) Scale all coordinates with a factor for x, y, and z.shearXY
(double sx, double sy) The xy-shear leaves the xy-coordinate plane for z=0 untouched.shearXZ
(double sx, double sz) The xz-shear leaves the xz-coordinate plain for y=0 untouched.shearYZ
(double sy, double sz) The yz-shear leaves the yz-coordinate plain for x=0 untouched.toString()
double[]
transform
(double[] xyz) Apply the stored transform on the xyz-vector and return the transformed vector.Apply the stored transform on the points generated by the provided pointIterator.Apply the stored transform on the provided Bounds3d and return a new Bounds3d with the bounds of the transformed coordinates.Apply the stored transform on the provided point and return a point with the transformed coordinate.translate
(double tx, double ty, double tz) Transform coordinates by a vector (tx, ty, tz).Translate coordinates by a the x, y, and z values contained in a Point.
-
Constructor Details
-
Transform3d
public Transform3d()
-
-
Method Details
-
mulMatVec
protected static double[] mulMatVec(double[] m, double[] v) Multiply a 4x4 matrix (stored as a 16-value array by row) with a 4-value vector.- Parameters:
m
- double[]; the matrixv
- double[]; the vector- Returns:
- double[4]; the result of m x v
-
mulMatVec3
protected static double[] mulMatVec3(double[] m, double[] v) Multiply a 4x4 matrix (stored as a 16-value array by row) with a 3-value vector and a 1 for the 4th value.- Parameters:
m
- double[]; the matrixv
- double[]; the vector- Returns:
- double[3]; the result of m x (v1, v2, v3, 1), with the last value left out
-
mulMatMat
protected static double[] mulMatMat(double[] m1, double[] m2) Multiply a 4x4 matrix (stored as a 16-value array by row) with another 4x4-matrix.- Parameters:
m1
- double[]; the first matrixm2
- double[]; the second matrix- Returns:
- double[16]; the result of m1 x m2
-
getMat
public double[] getMat()Get a safe copy of the affine transformation matrix.- Returns:
- double[]; a safe copy of the affine transformation matrix
-
translate
Transform coordinates by a vector (tx, ty, tz). Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Parameters:
tx
- double; the translation value for the x-coordinatesty
- double; the translation value for the y-coordinatestz
- double; the translation value for the z-coordinates- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
translate
Translate coordinates by a the x, y, and z values contained in a Point. Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Parameters:
point
- Point3d; the point containing the x, y, and z translation values- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
scale
Scale all coordinates with a factor for x, y, and z. A scale factor of 1 leaves the coordinate unchanged. Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Parameters:
sx
- double; the scale factor for the x-coordinatessy
- double; the scale factor for the y-coordinatessz
- double; the scale factor for the z-coordinates- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
rotX
The Euler rotation around the x-axis with an angle in radians. Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Parameters:
angle
- double; the angle to rotate the coordinates with with around the x-axis- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
rotY
The Euler rotation around the y-axis with an angle in radians. Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Parameters:
angle
- double; the angle to rotate the coordinates with with around the y-axis- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
rotZ
The Euler rotation around the z-axis with an angle in radians. Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Parameters:
angle
- double; the angle to rotate the coordinates with with around the z-axis- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
shearXY
The xy-shear leaves the xy-coordinate plane for z=0 untouched. Coordinates on z=1 are translated by a vector (sx, sy, 0). Coordinates for points with other z-values are translated by a vector (z.sx, z.sy, 0), where z is the z-coordinate of the point. Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Parameters:
sx
- double; the shear factor in the x-direction for z=1sy
- double; the shear factor in the y-direction for z=1- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
shearYZ
The yz-shear leaves the yz-coordinate plain for x=0 untouched. Coordinates on x=1 are translated by a vector (0, sy, sz). Coordinates for points with other x-values are translated by a vector (0, x.sy, x.sz), where x is the x-coordinate of the point. Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Parameters:
sy
- double; the shear factor in the y-direction for x=1sz
- double; the shear factor in the z-direction for x=1- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
shearXZ
The xz-shear leaves the xz-coordinate plain for y=0 untouched. Coordinates on y=1 are translated by a vector (sx, 0, sz). Coordinates for points with other y-values are translated by a vector (y.sx, 0, y.sz), where y is the y-coordinate of the point. Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Parameters:
sx
- double; the shear factor in the y-direction for y=1sz
- double; the shear factor in the z-direction for y=1- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
reflectX
The reflection of the x-coordinate, by mirroring it in the yz-plane (the plane with x=0). Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
reflectY
The reflection of the y-coordinate, by mirroring it in the xz-plane (the plane with y=0). Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
reflectZ
The reflection of the z-coordinate, by mirroring it in the xy-plane (the plane with z=0). Note that to carry out multiple operations, the steps have to be built in the OPPOSITE order since matrix multiplication operates from RIGHT to LEFT.- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
transform
public double[] transform(double[] xyz) Apply the stored transform on the xyz-vector and return the transformed vector. For speed reasons, no checks on correct size of the vector is done.- Parameters:
xyz
- double[]; double[3] the provided vector- Returns:
- double[3]; the transformed vector
-
transform
Apply the stored transform on the provided point and return a point with the transformed coordinate.- Parameters:
point
- Point3d; the point to be transformed- Returns:
- Point3d; a point with the transformed coordinates
-
transform
Apply the stored transform on the points generated by the provided pointIterator.- Parameters:
pointIterator
- Iterator<Point3d>; generates the points to be transformed- Returns:
- Iterator<Point3d>; an iterator that will generator all transformed points
-
transform
Apply the stored transform on the provided Bounds3d and return a new Bounds3d with the bounds of the transformed coordinates. All 8 corner points have to be transformed, since we do not know which of the 8 points will result in the lowest and highest x, y, and z coordinates.- Parameters:
boundingBox
- Bounds3d; the bounds to be transformed- Returns:
- Bounds3d; the new bounds based on the transformed coordinates
-
hashCode
public int hashCode() -
equals
-
toString
-