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
dataIJsonReadStructthe 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
m00doublem01doublem02doublem03doublem10doublem11doublem12doublem13doublem20doublem21doublem22doublem23double
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
mdouble[,]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
Properties
Determinant
Returns the determinant of the matrix of this modification.
public double Determinant { get; }
Property Value
Factor
Gets the scaling factor if appropriate
public double Factor { get; }
Property Value
Identity
Creates a modification that leaves everything unchanged.
public static ModOp Identity { get; }
Property Value
IsIsogonal
Same as IsOrthogonal but with scaling allowed
public bool IsIsogonal { get; }
Property Value
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
IsOrthogonal
Returns true if orthogonal vectors stay orthogonal after transformation and no scaling is performed
public bool IsOrthogonal { get; }
Property Value
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
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
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
Null
Creates a modification that makes everythin to 0
public static ModOp Null { get; }
Property Value
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
Translation
Returns the translation vector of this ModOp
public GeoVector Translation { get; set; }
Property Value
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
srcLocGeoPointorigin of the source system
srcGeoVector[]the three axis vectors of the source system
dstLocGeoPointorigin of the destination system
dstGeoVector[]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
SrcGeoPoint[]source points
DstGeoPoint[]destination points
DoScaleboolscaling 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
dataIJsonWriteDatathe 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
plnPlaneplane 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
centerGeoPointpoint 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
fixPointGeoPointFixpoint for the rotation
fromGeoVectorSource vector
toGeoVectorDestination 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
FixPointGeoPointpoint on the axis
AxisGeoVectordirection of the axis
RotationSweepAnglerotation 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
AxisGeoVectordirection of the axis
RotationSweepAnglerotation 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
AxisGeoVectordirection of the axis, need not be normalized
sindoublesine of the rotation angle
cosdoublecosine 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
FixPointGeoPointfixpoint for the scaling
DirectionGeoVectordirection for the scaling
Factordoublescaling 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
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
Returns
- ModOp
the resulting modification
Scale(double)
Creates a modification that performs a scaling about the origin
public static ModOp Scale(double Factor)
Parameters
Factordoublescaling 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
FactorXdoublescaling in the direction of the x-axis
FactorYdoublescaling in the direction of the y-axis
FactorZdoublescaling 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
dataIJsonReadDatanot 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
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
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
offsetGeoVectoroffset 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
dxdoubleoffset in direction of the x-axis
dydoubleoffset in direction of the y-axis
dzdoubleoffset 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
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
mModOpmodification
pGeoPoint2Dpoint
Returns
- GeoPoint
modified point
operator *(ModOp, GeoVector)
Modifies the given vector by this modification
public static GeoVector operator *(ModOp m, GeoVector v)
Parameters
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
mModOpmodification
vGeoVector2Dvector
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
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
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
Returns
- double
modified value