Table of Contents

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

Matrix00 double
Matrix01 double
Matrix02 double
Matrix10 double
Matrix11 double
Matrix12 double

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

m double[,]

the coefficients as [row, column]

Properties

Determinant

Gets the determinant of this modification

public double Determinant { get; }

Property Value

double

Factor

Returns the scaling factor of this modification

public double Factor { get; }

Property Value

double

Identity

Creates a modification which is the identity

public static ModOp2D Identity { get; }

Property Value

ModOp2D

IsIdentity

Returns true, if this modification is the identity.

public bool IsIdentity { get; }

Property Value

bool

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

bool

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

bool

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

i int

row index

j int

column index

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

Matrix

Returns the Matrix object equivalent to this modification.

Null

Creates a modification which is null, i.e. no valid ModOp2D

public static ModOp2D Null { get; }

Property Value

ModOp2D

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

Src GeoPoint2D[]

source points

Dst GeoPoint2D[]

destination points

DoScale bool

scaling 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

src GeoVector2D[]

source vectors

dst GeoVector2D[]

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

precision double

maximum 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

FromPlane Plane

Source plane

ToPlane Plane

Destination plane

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

axisPoint GeoPoint2D

a point on the mirror axis

axisDirection GeoVector2D

the direction of the mirror axis, must not be a null vector

Returns

ModOp2D

Rotate(GeoPoint2D, SweepAngle)

Creates a rotation about a fixpoint

public static ModOp2D Rotate(GeoPoint2D Center, SweepAngle Rotation)

Parameters

Center GeoPoint2D

the fixpoint

Rotation SweepAngle

the rotation angle

Returns

ModOp2D

resulting modification

Rotate(SweepAngle)

Creates a rotation about the origin

public static ModOp2D Rotate(SweepAngle Rotation)

Parameters

Rotation SweepAngle

the 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

center GeoPoint2D

the fixpoint of the scaling

factor double

scaling 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

center GeoPoint2D

the fixpoint of the scaling

factorx double

scaling factor in x-direction

factory double

scaling factor in y-direction

Returns

ModOp2D

resulting modification

Scale(double)

Creates a uniform scaling about the origin.

public static ModOp2D Scale(double factor)

Parameters

factor double

scaling 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

factorx double

scaling factor in x-direction

factory double

scaling factor in y-direction

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

ModOp

the corresponding ModOp

Translate(GeoVector2D)

Creates a translation

public static ModOp2D Translate(GeoVector2D offset)

Parameters

offset GeoVector2D

offset vector

Returns

ModOp2D

resulting modification

Translate(double, double)

Creates a translation

public static ModOp2D Translate(double dx, double dy)

Parameters

dx double

x-offset

dy double

y-offset

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

m ModOp

3d 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

m ModOp2D

modification

p GeoPoint2D

point

Returns

GeoPoint2D

modified point

operator *(ModOp2D, GeoVector2D)

Modifies the given vector by this modification

public static GeoVector2D operator *(ModOp2D m, GeoVector2D v)

Parameters

m ModOp2D

modification

v GeoVector2D

vector

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

lhs ModOp2D

second modification

rhs ModOp2D

first modification

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

m ModOp2D

modification

d double

input value

Returns

double

modified value