Struct ModOp2D
- Namespace
- CADability
- Assembly
- CADability.dll
A 2-dimensional modification operation implemented as a homogenous matix 3*2. You can apply such modificaion to GeoVector2D and GeoPoint2D points or to ICurve2D implementing objects.
public struct ModOp2D : ISerializable
- Implements
- Inherited Members
Constructors
ModOp2D(double, double, double, double, double, double)
Creates a modification according to the given coefficients
public ModOp2D(double Matrix00, double Matrix01, double Matrix02, double Matrix10, double Matrix11, double Matrix12)
Parameters
ModOp2D(double[,])
Creates a modification from an array of coefficients. A 22 array is taken as the linear part (rotation, scaling, shearing) without translation; an array with at least 2 rows and 3 columns is taken as the full 23 homogeneous matrix, where the first index is the row, the second the column and the third column holds the translation. Any other shape yields the Null modification.
public ModOp2D(double[,] m)
Parameters
mdouble[,]the coefficients as [row, column]
Properties
Determinant
Gets the determinant of this modification
public double Determinant { get; }
Property Value
Factor
Returns the scaling factor of this modification
public double Factor { get; }
Property Value
Identity
Creates a modification which is the identity
public static ModOp2D Identity { get; }
Property Value
IsIdentity
Returns true, if this modification is the identity.
public bool IsIdentity { get; }
Property Value
IsIsogonal
True, if this modification preserves angles, i.e. it is composed of translation, rotation, uniform scaling and possibly a reflection (a reflection is included when the Determinant is negative). The images of the x- and y-axis must be perpendicular and of equal length within the angular precision epsa. 2d curves like Circle2D use it to decide whether they stay circles under the modification or must become ellipses.
public bool IsIsogonal { get; }
Property Value
IsNull
True, if all coefficients are zero, i.e. this is the Null modification. Used to test whether a ModOp2D has been initialized at all, because a zero matrix does not occur as a real modification.
public bool IsNull { get; }
Property Value
this[int, int]
Gets or sets a single coefficient of the 2*3 matrix: i is the row (0 or 1), j
the column (0 to 2), column 2 being the translation. Indices outside the matrix throw a ModOpException.
public double this[int i, int j] { get; set; }
Parameters
Property Value
- double
the coefficient
Matrix
Gets or sets the 3*2 Matrix that defines this mmodification
public double[,] Matrix { get; set; }
Property Value
- double[,]
Matrix2D
Converts this modification to a GDI+ Matrix with the same coefficients (in single precision), e.g. to apply it when drawing with GDI+.
public Matrix Matrix2D { get; }
Property Value
Null
Creates a modification which is null, i.e. no valid ModOp2D
public static ModOp2D Null { get; }
Property Value
Methods
Fit(GeoPoint2D[], GeoPoint2D[], bool)
Constructs a modification, that transforms the Src points to the Dst points. The length of Src and Dst must be equal and less than 4. If the length is 1, the resulting ModOp is a translation, if the length is 2, the parameter DoScale decides whether the resulting ModOp is a translation and rotation (DoScale==false) or translation, rotation and scaling (DoScale==true). If the length is 3, the resulting modification is any kind of an affinity, that projects the src points to the dst points.
public static ModOp2D Fit(GeoPoint2D[] Src, GeoPoint2D[] Dst, bool DoScale)
Parameters
SrcGeoPoint2D[]source points
DstGeoPoint2D[]destination points
DoScaleboolscaling if two point pairs are given
Returns
- ModOp2D
resulting transformation
Fit(GeoVector2D[], GeoVector2D[])
Constructs a modification, that transforms the src vectors to the dst vectors. The length of src and dst must be 2. The resulting modification is any kind of an affinity, that projects the src vectors to the dst vectors. The origin (0,0) remains fixed.
public static ModOp2D Fit(GeoVector2D[] src, GeoVector2D[] dst)
Parameters
srcGeoVector2D[]source vectors
dstGeoVector2D[]destination vectors
Returns
- ModOp2D
resulting transformation
GetInverse()
Returns the inverse of this modification.
public ModOp2D GetInverse()
Returns
- ModOp2D
inverse
IsAlmostIdentity(double)
Checks whether this modification is the identity within a tolerance: the origin and the points (1,0) and (0,1)
are transformed and none of them may move farther than precision. In contrast to
IsIdentity this tolerates rounding errors, e.g. in a modification computed as the product of a
transformation and its inverse.
public bool IsAlmostIdentity(double precision)
Parameters
precisiondoublemaximum distance the test points may move
Returns
- bool
true, if the modification moves none of the test points farther than
precision
PlaneToplane(Plane, Plane)
Returns a 2d modification, that transforms from the coordinate system of the first plane to the coordinate system of the second plane. If the planes ar not coincident, the first plane is projected onto the second plane.
public static ModOp2D PlaneToplane(Plane FromPlane, Plane ToPlane)
Parameters
Returns
- ModOp2D
See above
Reflect(GeoPoint2D, GeoVector2D)
The reflection about the line through axisPoint with the direction
axisDirection. Points on that line stay where they are.
public static ModOp2D Reflect(GeoPoint2D axisPoint, GeoVector2D axisDirection)
Parameters
axisPointGeoPoint2Da point on the mirror axis
axisDirectionGeoVector2Dthe direction of the mirror axis, must not be a null vector
Returns
Rotate(GeoPoint2D, SweepAngle)
Creates a rotation about a fixpoint
public static ModOp2D Rotate(GeoPoint2D Center, SweepAngle Rotation)
Parameters
CenterGeoPoint2Dthe fixpoint
RotationSweepAnglethe rotation angle
Returns
- ModOp2D
resulting modification
Rotate(SweepAngle)
Creates a rotation about the origin
public static ModOp2D Rotate(SweepAngle Rotation)
Parameters
RotationSweepAnglethe rotation angle
Returns
- ModOp2D
resulting modification
Scale(GeoPoint2D, double)
Creates a uniform scaling about the given fixpoint: center stays where it is, all other points
move away from it (factor > 1) or towards it (factor < 1).
public static ModOp2D Scale(GeoPoint2D center, double factor)
Parameters
centerGeoPoint2Dthe fixpoint of the scaling
factordoublescaling factor for both axes
Returns
- ModOp2D
resulting modification
Scale(GeoPoint2D, double, double)
Creates a scaling about the given fixpoint with different factors in x and y. center stays
where it is.
public static ModOp2D Scale(GeoPoint2D center, double factorx, double factory)
Parameters
centerGeoPoint2Dthe fixpoint of the scaling
factorxdoublescaling factor in x-direction
factorydoublescaling factor in y-direction
Returns
- ModOp2D
resulting modification
Scale(double)
Creates a uniform scaling about the origin.
public static ModOp2D Scale(double factor)
Parameters
factordoublescaling factor for both axes
Returns
- ModOp2D
resulting modification
Scale(double, double)
Creates a scaling about the origin with different factors in x and y. Unless both factors have the same absolute value the result is not isogonal (see IsIsogonal), i.e. circles become ellipses.
public static ModOp2D Scale(double factorx, double factory)
Parameters
Returns
- ModOp2D
resulting modification
To3D()
Returns the 3-dimensional modification that performs this 2-dimensional modification in the xy-plane and leaves the z-coordinate unchanged. The counterpart of To2D().
public ModOp To3D()
Returns
Translate(GeoVector2D)
Creates a translation
public static ModOp2D Translate(GeoVector2D offset)
Parameters
offsetGeoVector2Doffset vector
Returns
- ModOp2D
resulting modification
Translate(double, double)
Creates a translation
public static ModOp2D Translate(double dx, double dy)
Parameters
Returns
- ModOp2D
resulting modification
XYPart(ModOp)
Returns a 2d ModOp which represents the 2d part of a 3d ModOp.
public static ModOp2D XYPart(ModOp m)
Parameters
mModOp3d ModOp
Returns
- ModOp2D
2d ModOp
Operators
operator *(ModOp2D, GeoPoint2D)
Modifies the given point by this modification.
public static GeoPoint2D operator *(ModOp2D m, GeoPoint2D p)
Parameters
mModOp2Dmodification
pGeoPoint2Dpoint
Returns
- GeoPoint2D
modified point
operator *(ModOp2D, GeoVector2D)
Modifies the given vector by this modification
public static GeoVector2D operator *(ModOp2D m, GeoVector2D v)
Parameters
mModOp2Dmodification
vGeoVector2Dvector
Returns
- GeoVector2D
modified vector
operator *(ModOp2D, ModOp2D)
Combines two modification into one modification. If two modifications have to be applied to several GeoPoint2Ds or GeoVector2Ds it is faster to use the combination.
public static ModOp2D operator *(ModOp2D lhs, ModOp2D rhs)
Parameters
Returns
- ModOp2D
the combination
operator *(ModOp2D, double)
Multiplies the double value by the scaling factor of this modification
public static double operator *(ModOp2D m, double d)
Parameters
Returns
- double
modified value