Transform3D Struct
A transformation of space, as the 4x4 matrices of CSS transforms: translations, scalings and rotations in three dimensions, and perspective. A drawing is the plane z = 0; Transform3D.ToProjectiveTransform gives what the transformation does to it.
public readonly struct Transform3D : IEquatable<Transform3D>Remarks
A point (x, y, z) becomes (X / W, Y / W, Z / W), with X = x M11 + y M21 + z M31 + M41, Y = x M12 + y M22 + z M32 + M42, Z = x M13 + y M23 + z M33 + M43 and W = x M14 + y M24 + z M34 + M44: the coefficients have the names of the DOMMatrix of the web platform, and of AffineTransform in two dimensions. The default value is the identity.
The coordinate system is the one of the canvas and of CSS: x to the right, y downward, z toward the viewer. Angles are in degrees and their sines and cosines come from additions, multiplications and divisions only, as for AffineTransform: a rotation by a multiple of 90 degrees is exact.
Transformations are combined in three dimensions (Transform3D.Then), so that what one of them does to z reaches the next one: a rotation around the y axis, then a perspective, shows the side of the plane that comes closer larger. Inside DrawingCanvas.Transform, a transformation of a callback started inside another one is combined that way too.
- Implements
Constructors
| Name | Description |
|---|---|
| Transform3D(double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double) | Initializes a new instance of the Transform3D struct from its coefficients, row by row. |
Transform3D(double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double)
Transform3D.csInitializes a new instance of the Transform3D struct from its coefficients, row by row.
public Transform3D(double m11, double m12, double m13, double m14, double m21, double m22, double m23, double m24, double m31, double m32, double m33, double m34, double m41, double m42, double m43, double m44)Parameters
m11double- The factor of x in X.
m12double- The factor of x in Y.
m13double- The factor of x in Z.
m14double- The factor of x in W.
m21double- The factor of y in X.
m22double- The factor of y in Y.
m23double- The factor of y in Z.
m24double- The factor of y in W.
m31double- The factor of z in X.
m32double- The factor of z in Y.
m33double- The factor of z in Z.
m34double- The factor of z in W.
m41double- The constant of X: the translation along x.
m42double- The constant of Y: the translation along y.
m43double- The constant of Z: the translation along z.
m44double- The constant of W.
Exceptions
ArgumentException- A coefficient is not a finite number.
Properties
| Name | Description |
|---|---|
| Identity | Gets the transformation that changes nothing. |
| IsIdentity | Gets a value indicating whether the transformation changes nothing. |
| M11 | Gets the factor of x in X. |
| M12 | Gets the factor of x in Y. |
| M13 | Gets the factor of x in Z. |
| M14 | Gets the factor of x in W. |
| M21 | Gets the factor of y in X. |
| M22 | Gets the factor of y in Y. |
| M23 | Gets the factor of y in Z. |
| M24 | Gets the factor of y in W. |
| M31 | Gets the factor of z in X. |
| M32 | Gets the factor of z in Y. |
| M33 | Gets the factor of z in Z. |
| M34 | Gets the factor of z in W. |
| M41 | Gets the constant of X: the translation along x. |
| M42 | Gets the constant of Y: the translation along y. |
| M43 | Gets the constant of Z: the translation along z. |
| M44 | Gets the constant of W. |
Identity
Transform3D.csGets the transformation that changes nothing.
public static Transform3D Identity { get; }Property value
IsIdentity
Transform3D.csMethods
| Name | Description |
|---|---|
| CreatePerspective(double) | Creates a perspective, as perspective of CSS: the viewer is at a distance from the plane z = 0, on the z axis. |
| CreateRotation(double, double, double, double) | Creates a rotation around an axis through the origin, as rotate3d of CSS. |
| CreateRotationX(double) | Creates a rotation around the x axis, as rotateX of CSS. |
| CreateRotationY(double) | Creates a rotation around the y axis, as rotateY of CSS. |
| CreateRotationZ(double) | Creates a rotation around the z axis, as rotateZ of CSS: the rotation of AffineTransform.CreateRotation. |
| CreateScale(double, double, double) | Creates a scaling around the origin. |
| CreateTranslation(double, double, double) | Creates a translation. |
| Equals(Transform3D) | Indicates whether the current object is equal to another object of the same type. |
| Equals(object?) | Indicates whether this instance and a specified object are equal. |
| GetHashCode() | Returns the hash code for this instance. |
| Multiply(Transform3D, Transform3D) | Gets the transformation that applies a first one, then a second one. |
| Then(Transform3D) | Gets the transformation that applies this one first, then another one. |
| ToProjectiveTransform() | Gets what the transformation does to the plane z = 0, seen from the viewer: the point (x, y) becomes ((x M11 + y M21 + M41) / W, (x M12 + y M22 + M42) / W) with W = x M14 + y M24 + M44. |
| ToString() | Returns the coefficients row by row, formatted as [M11 M12 ... M44]. |
CreatePerspective(double)
Transform3D.csCreates a perspective, as perspective of CSS: the viewer is at a distance from the plane z = 0, on the z axis.
public static Transform3D CreatePerspective(double distance)Parameters
distancedouble- The distance from the viewer to the plane
z = 0, in pixels. Must be positive.
Returns
Transform3D The transformation: what comes closer to the viewer is larger, and what reaches the viewer has no image.
Exceptions
ArgumentOutOfRangeExceptiondistanceis not a positive finite number.
CreateRotation(double, double, double, double)
Transform3D.csCreates a rotation around an axis through the origin, as rotate3d of CSS.
public static Transform3D CreateRotation(double axisX, double axisY, double axisZ, double degrees)Parameters
axisXdouble- The x component of the direction of the axis.
axisYdouble- The y component of the direction of the axis.
axisZdouble- The z component of the direction of the axis.
degreesdouble- The angle, in degrees, clockwise when the axis points toward the viewer.
Returns
Transform3D The transformation; the identity when the direction has no length.
Exceptions
ArgumentException- A component of the axis, or
degrees, is not a finite number.
CreateRotationX(double)
Transform3D.csCreates a rotation around the x axis, as rotateX of CSS.
public static Transform3D CreateRotationX(double degrees)Parameters
degreesdouble- The angle, in degrees: a positive angle brings the bottom of the plane toward the viewer.
Returns
Transform3D The transformation.
Exceptions
ArgumentExceptiondegreesis not a finite number.
CreateRotationY(double)
Transform3D.csCreates a rotation around the y axis, as rotateY of CSS.
public static Transform3D CreateRotationY(double degrees)Parameters
degreesdouble- The angle, in degrees: a positive angle moves the right of the plane away from the viewer.
Returns
Transform3D The transformation.
Exceptions
ArgumentExceptiondegreesis not a finite number.
CreateRotationZ(double)
Transform3D.csCreates a rotation around the z axis, as rotateZ of CSS: the rotation of AffineTransform.CreateRotation.
public static Transform3D CreateRotationZ(double degrees)Parameters
degreesdouble- The angle, in degrees. A positive angle turns clockwise on the image.
Returns
Transform3D The transformation.
Exceptions
ArgumentExceptiondegreesis not a finite number.
CreateScale(double, double, double)
Transform3D.csCreates a scaling around the origin.
public static Transform3D CreateScale(double x, double y, double z)Parameters
Returns
Transform3D The transformation.
Exceptions
ArgumentException- A factor is not a finite number.
CreateTranslation(double, double, double)
Transform3D.csCreates a translation.
public static Transform3D CreateTranslation(double x, double y, double z)Parameters
xdouble- The distance along x.
ydouble- The distance along y.
zdouble- The distance along z, toward the viewer when positive.
Returns
Transform3D The transformation.
Exceptions
ArgumentException- A distance is not a finite number.
Equals overloads
Equals(Transform3D)
Transform3D.csIndicates whether the current object is equal to another object of the same type.
public bool Equals(Transform3D other)Parameters
otherTransform3D- An object to compare with this object.
Returns
bool true if the current object is equal to the other parameter; otherwise, false.
Equals(object?)
Transform3D.csGetHashCode()
Transform3D.csMultiply(Transform3D, Transform3D)
Transform3D.csGets the transformation that applies a first one, then a second one.
public static Transform3D Multiply(Transform3D first, Transform3D second)Parameters
firstTransform3D- The transformation applied first.
secondTransform3D- The transformation applied to the result of the first one.
Returns
Transform3D The combined transformation.
Exceptions
ArgumentException- A coefficient of the result is not a finite number.
Then(Transform3D)
Transform3D.csGets the transformation that applies this one first, then another one.
public Transform3D Then(Transform3D next)Parameters
nextTransform3D- The transformation applied after this one.
Returns
Transform3D The combined transformation.
Exceptions
ArgumentException- A coefficient of the result is not a finite number.
ToProjectiveTransform()
Transform3D.csGets what the transformation does to the plane z = 0, seen from the viewer: the point (x, y) becomes ((x M11 + y M21 + M41) / W, (x M12 + y M22 + M42) / W) with W = x M14 + y M24 + M44.
public ProjectiveTransform ToProjectiveTransform()Returns
ProjectiveTransform The projective transformation of the plane.
ToString()
Transform3D.csOperators
| Name | Description |
|---|---|
| operator ==(Transform3D, Transform3D) | Compares two transformations for equality. |
| implicit operator Transform3D(AffineTransform) | Converts a transformation of the plane: it moves the points of each plane z = constant in that plane. |
| implicit operator Transform3D(ProjectiveTransform) | Converts a projective transformation of the plane: z is kept, and divided by W as x and y are. |
| operator !=(Transform3D, Transform3D) | Compares two transformations for inequality. |
| operator *(Transform3D, Transform3D) | Gets the transformation that applies a first one, then a second one. |
operator ==(Transform3D, Transform3D)
Transform3D.csCompares two transformations for equality.
public static bool operator ==(Transform3D left, Transform3D right)Parameters
leftTransform3D- The first transformation.
rightTransform3D- The second transformation.
Returns
bool true if every coefficient is equal; otherwise false.
op_Implicit overloads
implicit operator Transform3D(AffineTransform)
Transform3D.csConverts a transformation of the plane: it moves the points of each plane z = constant in that plane.
public static implicit operator Transform3D(AffineTransform transform)implicit operator Transform3D(ProjectiveTransform)
Transform3D.csConverts a projective transformation of the plane: z is kept, and divided by W as x and y are.
public static implicit operator Transform3D(ProjectiveTransform transform)operator !=(Transform3D, Transform3D)
Transform3D.csCompares two transformations for inequality.
public static bool operator !=(Transform3D left, Transform3D right)Parameters
leftTransform3D- The first transformation.
rightTransform3D- The second transformation.
Returns
bool true if a coefficient differs; otherwise false.
operator *(Transform3D, Transform3D)
Transform3D.csGets the transformation that applies a first one, then a second one.
public static Transform3D operator *(Transform3D left, Transform3D right)Parameters
leftTransform3D- The transformation applied first.
rightTransform3D- The transformation applied to the result of the first one.
Returns
Transform3D The combined transformation.
Exceptions
ArgumentException- A coefficient of the result is not a finite number.