Table of Contents

Struct ModOp

Namespace
CADability
Assembly
CADability.dll

A 3-dimensional modification operation implemented as a homogenous matrix 4*3. You can apply such a modification to GeoPoints or GeoVectors or you can use it for GeoObjects Modify(ModOp). If you want to move, rotate, scale reflect or generally modify a GeoObject you will need this class. Use the static methods to create ModOps that do a required modification (like Rotate(GeoVector, SweepAngle), Translate(GeoVector) etc.

[JsonVersion(serializeAsStruct = true, version = 1)]
public struct ModOp : ISerializable, IJsonSerialize
Implements
Inherited Members

Constructors

ModOp(IJsonReadStruct)

Constructor required by JSON deserialization. Reads the values written by GetObjectData(IJsonWriteData).

public ModOp(IJsonReadStruct data)

Parameters

data IJsonReadStruct

the stored values

ModOp(double, double, double, double, double, double, double, double, double, double, double, double)

Creates a modification according to the given coefficients

public ModOp(double m00, double m01, double m02, double m03, double m10, double m11, double m12, double m13, double m20, double m21, double m22, double m23)

Parameters

m00 double
m01 double
m02 double
m03 double
m10 double
m11 double
m12 double
m13 double
m20 double
m21 double
m22 double
m23 double

ModOp(double[,])

Creates a modification from an array of coefficients. A 33 array is taken as the linear part (rotation, scaling, shearing) without translation; an array with at least 3 rows and 4 columns is taken as the full 34 homogeneous matrix, where the first index is the row, the second the column and the fourth column holds the translation. Any other shape yields the identity.

public ModOp(double[,] m)

Parameters

m double[,]

the coefficients as [row, column]

ModOp(double[,], GeoVector)

Creates a modification from an array of coefficients (see ModOp(double[,])) and a translation. The translation replaces a fourth column of m if there is one.

public ModOp(double[,] m, GeoVector trans)

Parameters

m double[,]

the coefficients of the linear part as [row, column]

trans GeoVector

the translation

Properties

Determinant

Returns the determinant of the matrix of this modification.

public double Determinant { get; }

Property Value

double

Factor

Gets the scaling factor if appropriate

public double Factor { get; }

Property Value

double

Identity

Creates a modification that leaves everything unchanged.

public static ModOp Identity { get; }

Property Value

ModOp

IsIsogonal

Same as IsOrthogonal but with scaling allowed

public bool IsIsogonal { get; }

Property Value

bool

IsNull

Returns true for ModOps that are 0.0 in all components. Uninitialized ModOp objects will return true. Usually used for a test, whether it has been initialized, since a 0 ModOp shouldn't occur in normal circumstances.

public bool IsNull { get; }

Property Value

bool

IsOrthogonal

Returns true if orthogonal vectors stay orthogonal after transformation and no scaling is performed

public bool IsOrthogonal { get; }

Property Value

bool

IsValid

True, if none of the coefficients is NaN. A ModOp becomes invalid when it was computed from degenerated input, e.g. a fit through coincident points.

public bool IsValid { get; }

Property Value

bool

this[int, int]

Gets or sets a single coefficient of the 3*4 matrix: i is the row (0 to 2), j the column (0 to 3), column 3 being the translation. Indices outside the matrix throw a ModOpException. Setting a coefficient does not update the internally cached kind of the modification or its scaling factor, so prefer the static construction methods or ModOp(double[,]) to build a modification.

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 Matrix that defines this mmodification

public double[,] Matrix { get; set; }

Property Value

double[,]

Mode

Gets the kind of operation this ModOp performs.

public ModOp.ModificationMode Mode { get; }

Property Value

ModOp.ModificationMode

Null

Creates a modification that makes everythin to 0

public static ModOp Null { get; }

Property Value

ModOp

Oriented

Gets the orientation of this ModOp. True means orientation is preserved (e.g. lefthanded yields lefthanded), false means orientation is reversed (lefthanded yields righthanded and vice versa) when this ModOp is applied to vectors.

public bool Oriented { get; }

Property Value

bool

Translation

Returns the translation vector of this ModOp

public GeoVector Translation { get; set; }

Property Value

GeoVector

Methods

Fit(GeoPoint, GeoVector[], GeoPoint, GeoVector[])

Constructs the modification that maps the coordinate system given by the origin srcLoc and the three axis vectors src onto the coordinate system given by dstLoc and dst: srcLoc goes to dstLoc and each vector of src to the corresponding vector of dst. The result is in general an affine transformation (it may contain scaling and shearing). Both arrays must contain exactly three vectors and the source vectors must be linearly independent, otherwise a ModOpException is thrown.

public static ModOp Fit(GeoPoint srcLoc, GeoVector[] src, GeoPoint dstLoc, GeoVector[] dst)

Parameters

srcLoc GeoPoint

origin of the source system

src GeoVector[]

the three axis vectors of the source system

dstLoc GeoPoint

origin of the destination system

dst GeoVector[]

the three axis vectors of the destination system

Returns

ModOp

the resulting modification

Fit(GeoPoint[], GeoPoint[], bool)

Constructs a ModOp, that transforms the Src points to the Dst points. The length of Src and Dst must be equal and less than 5. 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 or 4, the resulting ModOp is any kind of an affinity, that projects the src points to the dst points.

public static ModOp Fit(GeoPoint[] Src, GeoPoint[] Dst, bool DoScale)

Parameters

Src GeoPoint[]

source points

Dst GeoPoint[]

destination points

DoScale bool

scaling if two point pairs are given

Returns

ModOp

resulting transformation

GetInverse()

Returns the inverse of this modification.

public ModOp GetInverse()

Returns

ModOp

inverse

GetObjectData(IJsonWriteData)

Implements GetObjectData(IJsonWriteData): writes the twelve matrix coefficients, the scaling factor and the mode as a list of values.

public void GetObjectData(IJsonWriteData data)

Parameters

data IJsonWriteData

the JSON writer

ReflectPlane()

Constructs a ModOp, that performs a reflection about the y/z plane

public static ModOp ReflectPlane()

Returns

ModOp

resulting transformation

ReflectPlane(Plane)

Constructs a ModOp, that performs a reflection about the given plane

public static ModOp ReflectPlane(Plane pln)

Parameters

pln Plane

plane for reflection

Returns

ModOp

resulting transformation

ReflectPoint(GeoPoint)

Constructs a ModOp, that performs a reflection about the given point

public static ModOp ReflectPoint(GeoPoint center)

Parameters

center GeoPoint

point for reflection

Returns

ModOp

resulting transformation

Rotate(GeoPoint, GeoVector, GeoVector)

Creates a rotation around the fixpoint that moves the vector from to the vector to.

public static ModOp Rotate(GeoPoint fixPoint, GeoVector from, GeoVector to)

Parameters

fixPoint GeoPoint

Fixpoint for the rotation

from GeoVector

Source vector

to GeoVector

Destination vector

Returns

ModOp

The modification that performs the rotation

Rotate(GeoPoint, GeoVector, SweepAngle)

Creates a modification that performs a rotation about an axis through the given point

public static ModOp Rotate(GeoPoint FixPoint, GeoVector Axis, SweepAngle Rotation)

Parameters

FixPoint GeoPoint

point on the axis

Axis GeoVector

direction of the axis

Rotation SweepAngle

rotation angle

Returns

ModOp

the resulting modification

Rotate(GeoVector, SweepAngle)

Creates a modification that performs a rotation about an axis through the origina

public static ModOp Rotate(GeoVector Axis, SweepAngle Rotation)

Parameters

Axis GeoVector

direction of the axis

Rotation SweepAngle

rotation angle

Returns

ModOp

the resulting modification

Rotate(GeoVector, double, double)

Creates a rotation about an axis through the origin, with the rotation angle given by its sine and cosine instead of the angle itself (see Rotate(GeoVector, SweepAngle)). Convenient when sine and cosine are already known, e.g. from a cross and a dot product of two vectors.

public static ModOp Rotate(GeoVector Axis, double sin, double cos)

Parameters

Axis GeoVector

direction of the axis, need not be normalized

sin double

sine of the rotation angle

cos double

cosine of the rotation angle

Returns

ModOp

the resulting modification

Scale(GeoPoint, GeoVector, double)

Creates a modification that performs a scaling in a given direction with a fixpoint

public static ModOp Scale(GeoPoint FixPoint, GeoVector Direction, double Factor)

Parameters

FixPoint GeoPoint

fixpoint for the scaling

Direction GeoVector

direction for the scaling

Factor double

scaling factor for the given direction

Returns

ModOp

the resulting modification

Scale(GeoPoint, double)

Creates a modification that performs a scaling about a given point

public static ModOp Scale(GeoPoint FixPoint, double Factor)

Parameters

FixPoint GeoPoint

fixpoint for the scaling

Factor double

scaling factor

Returns

ModOp

the resulting modification

Scale(GeoVector, double)

Creates a modification that performs a scaling in a given direction

public static ModOp Scale(GeoVector Direction, double Factor)

Parameters

Direction GeoVector

direction for the scaling

Factor double

scaling factor for the given direction

Returns

ModOp

the resulting modification

Scale(double)

Creates a modification that performs a scaling about the origin

public static ModOp Scale(double Factor)

Parameters

Factor double

scaling factor

Returns

ModOp

the resulting modification

Scale(double, double, double)

Creates a modification that performs a scaling with different factors in x,y and z direction

public static ModOp Scale(double FactorX, double FactorY, double FactorZ)

Parameters

FactorX double

scaling in the direction of the x-axis

FactorY double

scaling in the direction of the y-axis

FactorZ double

scaling in the direction of the z-axis

Returns

ModOp

the resulting modification

SetObjectData(IJsonReadData)

Implements SetObjectData(IJsonReadData). Does nothing, because a ModOp is serialized as a struct and read back by the ModOp(IJsonReadStruct) constructor.

public void SetObjectData(IJsonReadData data)

Parameters

data IJsonReadData

not used

To2D()

Returns the 2-dimensional modification that this modification performs in the xy-plane: the x- and y-rows of the matrix including their translation, the z-coordinate is ignored. Only meaningful for modifications that map the xy-plane onto itself. The counterpart of To3D().

public ModOp2D To2D()

Returns

ModOp2D

the corresponding ModOp2D

ToMatrix()

Returns this modification as a 44 MathNet matrix: the 34 matrix of the modification completed by the row (0,0,0,1). Used to combine the modification with a perspective matrix (see Matrix4).

public Matrix ToMatrix()

Returns

Matrix

the 4*4 matrix

Transform(CoordSys, CoordSys)

Constructs a ModOp, that maps the Src coordinate system to the Dst coordinate system

public static ModOp Transform(CoordSys Src, CoordSys Dst)

Parameters

Src CoordSys

source coordinate system

Dst CoordSys

destination coordinate system

Returns

ModOp

resulting transformation

Translate(GeoVector)

Constructs a ModOp, that performs a translation by the given offset vector

public static ModOp Translate(GeoVector offset)

Parameters

offset GeoVector

offset vector

Returns

ModOp

resulting transformation

Translate(double, double, double)

Constructs a ModOp, that performs a translation by the given offsets

public static ModOp Translate(double dx, double dy, double dz)

Parameters

dx double

offset in direction of the x-axis

dy double

offset in direction of the y-axis

dz double

offset in direction of the z-axis

Returns

ModOp

resulting transformation

Operators

operator *(ModOp, GeoPoint)

Modifies the given point by this modification.

public static GeoPoint operator *(ModOp m, GeoPoint p)

Parameters

m ModOp

modification

p GeoPoint

point

Returns

GeoPoint

modified point

operator *(ModOp, GeoPoint2D)

Modifies the given 2d point by this modification. The point is assumed in the x/y plane

public static GeoPoint operator *(ModOp m, GeoPoint2D p)

Parameters

m ModOp

modification

p GeoPoint2D

point

Returns

GeoPoint

modified point

operator *(ModOp, GeoVector)

Modifies the given vector by this modification

public static GeoVector operator *(ModOp m, GeoVector v)

Parameters

m ModOp

modification

v GeoVector

vector

Returns

GeoVector

modified vector

operator *(ModOp, GeoVector2D)

Modifies the given 2d vector by this modification, The vector is assumed in the x/y plane

public static GeoVector operator *(ModOp m, GeoVector2D v)

Parameters

m ModOp

modification

v GeoVector2D

vector

Returns

GeoVector

modified vector

operator *(ModOp, ModOp)

Combines two modification into one modification. If two modifications have to be applied to several GeoPoints or GeoVectors or to IGeoObjects it is faster to use the combination.

public static ModOp operator *(ModOp lhs, ModOp rhs)

Parameters

lhs ModOp

second modification

rhs ModOp

first modification

Returns

ModOp

the combination

operator *(ModOp, Plane)

Returns the plane transformed by the modification. Location and direction vectors of the plane are transformed and the coordinate system of the result is orthonormalized again (see Modify(ModOp)). The given plane is not changed.

public static Plane operator *(ModOp m, Plane pln)

Parameters

m ModOp

modification

pln Plane

plane

Returns

Plane

modified plane

operator *(ModOp, double)

Multiplies the double value by the scaling factor of this modification

public static double operator *(ModOp m, double d)

Parameters

m ModOp

modification

d double

input value

Returns

double

modified value