Package org.djutils.draw
Class Transform3d
- java.lang.Object
-
- org.djutils.draw.Transform3d
-
- All Implemented Interfaces:
Cloneable
public class Transform3d extends Object implements 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-2021 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
Constructors Constructor Description Transform3d()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
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.Transform3d
reflectX()
The reflection of the x-coordinate, by mirroring it in the yz-plane (the plane with x=0).Transform3d
reflectY()
The reflection of the y-coordinate, by mirroring it in the xz-plane (the plane with y=0).Transform3d
reflectZ()
The reflection of the z-coordinate, by mirroring it in the xy-plane (the plane with z=0).Transform3d
rotX(double angle)
The Euler rotation around the x-axis with an angle in radians.Transform3d
rotY(double angle)
The Euler rotation around the y-axis with an angle in radians.Transform3d
rotZ(double angle)
The Euler rotation around the z-axis with an angle in radians.Transform3d
scale(double sx, double sy, double sz)
Scale all coordinates with a factor for x, y, and z.Transform3d
shearXY(double sx, double sy)
The xy-shear leaves the xy-coordinate plane for z=0 untouched.Transform3d
shearXZ(double sx, double sz)
The xz-shear leaves the xz-coordinate plain for y=0 untouched.Transform3d
shearYZ(double sy, double sz)
The yz-shear leaves the yz-coordinate plain for x=0 untouched.String
toString()
double[]
transform(double[] xyz)
Apply the stored transform on the xyz-vector and return the transformed vector.Iterator<Point3d>
transform(Iterator<Point3d> pointIterator)
Apply the stored transform on the provided point and return a point with the transformed coordinate.Bounds3d
transform(Bounds3d boundingBox)
Apply the stored transform on the provided Bounds3d and return a new Bounds3d with the bounds of the transformed coordinates.Point3d
transform(Point3d point)
Apply the stored transform on the provided point and return a point with the transformed coordinate.Transform3d
translate(double tx, double ty, double tz)
Transform coordinates by a vector (tx, ty, tz).Transform3d
translate(Point3d point)
Translate coordinates by a the x, y, and z values contained in a Point.
-
-
-
Method Detail
-
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
public Transform3d translate(double tx, double ty, double tz)
Transform coordinates by a vector (tx, ty, tz).- 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
public Transform3d translate(Point3d point)
Translate coordinates by a the x, y, and z values contained in a Point.- Parameters:
point
- Point3d; the point containing the x, y, and z translation values- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
scale
public Transform3d scale(double sx, double sy, double sz)
Scale all coordinates with a factor for x, y, and z. A scale factor of 1 leaves the coordinate unchanged.- 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
public Transform3d rotX(double angle)
The Euler rotation around the x-axis with an angle in radians.- 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
public Transform3d rotY(double angle)
The Euler rotation around the y-axis with an angle in radians.- 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
public Transform3d rotZ(double angle)
The Euler rotation around the z-axis with an angle in radians.- 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
public Transform3d shearXY(double sx, double sy)
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.- 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
public Transform3d shearYZ(double sy, double sz)
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.- 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
public Transform3d shearXZ(double sx, double sz)
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.- 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
public Transform3d reflectX()
The reflection of the x-coordinate, by mirroring it in the yz-plane (the plane with x=0).- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
reflectY
public Transform3d reflectY()
The reflection of the y-coordinate, by mirroring it in the xz-plane (the plane with y=0).- Returns:
- Transform3d; the new transformation matrix after applying this transform
-
reflectZ
public Transform3d reflectZ()
The reflection of the z-coordinate, by mirroring it in the xy-plane (the plane with z=0).- 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
public Point3d transform(Point3d point)
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
public Iterator<Point3d> transform(Iterator<Point3d> pointIterator)
Apply the stored transform on the provided point and return a point with the transformed coordinate.- Parameters:
pointIterator
- Iterator<Point3d>; generates the points to be transformed- Returns:
- Iterator<Point3d>; an iterator that will generator all transformed points
-
transform
public Bounds3d transform(Bounds3d boundingBox)
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
-
-