ProjectiveTransform Struct
A transformation of the plane that keeps straight lines straight, but not parallel lines parallel: a plane seen in perspective. An AffineTransform is the projective transformation whose third column is (0, 0, 1).
public readonly struct ProjectiveTransform : IEquatable<ProjectiveTransform>Remarks
A point (x, y) becomes (X / W, Y / W), with X = x M11 + y M21 + M31, Y = x M12 + y M22 + M32 and W = x M13 + y M23 + M33: the convention of AffineTransform, whose offsets are M31 and M32. The default value is the identity.
The points where W is positive are in front of the viewer; those where it is zero or negative have no image, and are not drawn: a drawing that crosses that line (the horizon of the plane) is cut there. Multiplying every coefficient by the same positive number does not change the transformation.
- Implements
Constructors
| Name | Description |
|---|---|
| ProjectiveTransform(double, double, double, double, double, double, double, double, double) | Initializes a new instance of the ProjectiveTransform struct from its coefficients. |
ProjectiveTransform(double, double, double, double, double, double, double, double, double)
ProjectiveTransform.csInitializes a new instance of the ProjectiveTransform struct from its coefficients.
public ProjectiveTransform(double m11, double m12, double m13, double m21, double m22, double m23, double m31, double m32, double m33)Parameters
m11double- The factor of x in X.
m12double- The factor of x in Y.
m13double- 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 W.
m31double- The constant of X: the horizontal translation of an affine transformation.
m32double- The constant of Y: the vertical translation of an affine transformation.
m33double- The constant of W.
Exceptions
ArgumentException- A coefficient is not a finite number.
Properties
| Name | Description |
|---|---|
| Determinant | Gets the determinant of the nine coefficients: zero when the transformation flattens the plane to a line or a point. |
| Identity | Gets the transformation that changes nothing. |
| IsAffine | Gets a value indicating whether the transformation is affine: W is the same positive number everywhere, so parallel lines stay parallel and every point has an image. |
| 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 W. |
| M21 | Gets the factor of y in X. |
| M22 | Gets the factor of y in Y. |
| M23 | Gets the factor of y in W. |
| M31 | Gets the constant of X. |
| M32 | Gets the constant of Y. |
| M33 | Gets the constant of W. |
Determinant
ProjectiveTransform.csIdentity
ProjectiveTransform.csGets the transformation that changes nothing.
public static ProjectiveTransform Identity { get; }Property value
IsAffine
ProjectiveTransform.csIsIdentity
ProjectiveTransform.csMethods
| Name | Description |
|---|---|
| CreateFromQuadrilateral(RectangleD, PointD, PointD, PointD, PointD) | Creates the transformation that maps the corners of a rectangle to the corners of a quadrilateral: the rectangle seen in perspective. |
| Equals(ProjectiveTransform) | 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(ProjectiveTransform, ProjectiveTransform) | Gets the transformation that applies a first one, then a second one. |
| Then(ProjectiveTransform) | Gets the transformation that applies this one first, then another one. |
| ToString() | Returns the coefficients formatted as [M11 M12 M13 M21 M22 M23 M31 M32 M33]. |
| TryInvert(ProjectiveTransform) | Gets the transformation that undoes this one. |
| TryTransform(PointD, PointD) | Transforms a point. |
CreateFromQuadrilateral(RectangleD, PointD, PointD, PointD, PointD)
ProjectiveTransform.csCreates the transformation that maps the corners of a rectangle to the corners of a quadrilateral: the rectangle seen in perspective.
public static ProjectiveTransform CreateFromQuadrilateral(RectangleD source, PointD topLeft, PointD topRight, PointD bottomRight, PointD bottomLeft)Parameters
sourceRectangleD- The rectangle. Must not be empty.
topLeftPointD- Where the top-left corner of the rectangle goes.
topRightPointD- Where the top-right corner goes.
bottomRightPointD- Where the bottom-right corner goes.
bottomLeftPointD- Where the bottom-left corner goes.
Returns
ProjectiveTransform The transformation; W is positive inside the quadrilateral.
Exceptions
ArgumentException- A coordinate is not a finite number, the rectangle is empty, or the points are not the corners of a convex quadrilateral, in order around it.
Equals overloads
Equals(ProjectiveTransform)
ProjectiveTransform.csIndicates whether the current object is equal to another object of the same type.
public bool Equals(ProjectiveTransform other)Parameters
otherProjectiveTransform- An object to compare with this object.
Returns
bool true if the current object is equal to the other parameter; otherwise, false.
Equals(object?)
ProjectiveTransform.csGetHashCode()
ProjectiveTransform.csMultiply(ProjectiveTransform, ProjectiveTransform)
ProjectiveTransform.csGets the transformation that applies a first one, then a second one.
public static ProjectiveTransform Multiply(ProjectiveTransform first, ProjectiveTransform second)Parameters
firstProjectiveTransform- The transformation applied first.
secondProjectiveTransform- The transformation applied to the result of the first one.
Returns
ProjectiveTransform The combined transformation.
Exceptions
ArgumentException- A coefficient of the result is not a finite number.
Then(ProjectiveTransform)
ProjectiveTransform.csGets the transformation that applies this one first, then another one.
public ProjectiveTransform Then(ProjectiveTransform next)Parameters
nextProjectiveTransform- The transformation applied after this one.
Returns
ProjectiveTransform The combined transformation.
Exceptions
ArgumentException- A coefficient of the result is not a finite number.
ToString()
ProjectiveTransform.csTryInvert(ProjectiveTransform)
ProjectiveTransform.csGets the transformation that undoes this one.
public bool TryInvert(out ProjectiveTransform inverse)Parameters
inverseProjectiveTransform- The inverse transformation, or the identity when there is none.
Returns
bool false when the transformation flattens the plane to a line or a point: nothing undoes it.
Remarks
The inverse keeps the sign of W: a point in front of the viewer comes back with a positive W.
TryTransform(PointD, PointD)
ProjectiveTransform.csOperators
| Name | Description |
|---|---|
| operator ==(ProjectiveTransform, ProjectiveTransform) | Compares two transformations for equality. |
| implicit operator ProjectiveTransform(AffineTransform) | Converts an affine transformation. |
| operator !=(ProjectiveTransform, ProjectiveTransform) | Compares two transformations for inequality. |
| operator *(ProjectiveTransform, ProjectiveTransform) | Gets the transformation that applies a first one, then a second one. |
operator ==(ProjectiveTransform, ProjectiveTransform)
ProjectiveTransform.csCompares two transformations for equality.
public static bool operator ==(ProjectiveTransform left, ProjectiveTransform right)Parameters
leftProjectiveTransform- The first transformation.
rightProjectiveTransform- The second transformation.
Returns
bool true if every coefficient is equal; otherwise false.
implicit operator ProjectiveTransform(AffineTransform)
ProjectiveTransform.csConverts an affine transformation.
public static implicit operator ProjectiveTransform(AffineTransform transform)operator !=(ProjectiveTransform, ProjectiveTransform)
ProjectiveTransform.csCompares two transformations for inequality.
public static bool operator !=(ProjectiveTransform left, ProjectiveTransform right)Parameters
leftProjectiveTransform- The first transformation.
rightProjectiveTransform- The second transformation.
Returns
bool true if a coefficient differs; otherwise false.
operator *(ProjectiveTransform, ProjectiveTransform)
ProjectiveTransform.csGets the transformation that applies a first one, then a second one.
public static ProjectiveTransform operator *(ProjectiveTransform left, ProjectiveTransform right)Parameters
leftProjectiveTransform- The transformation applied first.
rightProjectiveTransform- The transformation applied to the result of the first one.
Returns
ProjectiveTransform The combined transformation.
Exceptions
ArgumentException- A coefficient of the result is not a finite number.