Class CartesianCoordinateSystem
- Namespace
- VirtualLabAPI.Core.Numerics
- Assembly
- VirtualLabAPI.dll
Class for right-handed Cartesian coordinate systems.
[Serializable]
public class CartesianCoordinateSystem : ManualSerialization, IEquatable<IObjectBase>, ISerializable, IDeserializationCallback, ICloneable
- Inheritance
-
ObjectBaseSerializableObjectBaseManualSerializationCartesianCoordinateSystem
- Implements
-
IEquatable<IObjectBase>
- Inherited Members
Constructors
CartesianCoordinateSystem()
Default constructor, creating a new CartesianCoordinateSystem that is defined absolutely, and identical to the global coordinate system.
public CartesianCoordinateSystem()
CartesianCoordinateSystem(CartesianCoordinateSystem)
Copy constructor.
public CartesianCoordinateSystem(CartesianCoordinateSystem cs)
Parameters
csCartesianCoordinateSystemCoordinate system to be copied.
CartesianCoordinateSystem(IProvidesPositioningReferences, string)
Constructor, creating a new CartesianCoordinateSystem that is defined in reference to a given reference cs, it lies at (0,0,0) and is not rotated to this reference.
public CartesianCoordinateSystem(IProvidesPositioningReferences positioningReferenceProvider, string positioningReferenceKey)
Parameters
positioningReferenceProviderIProvidesPositioningReferencesObject which provides the coordinate system that serves as reference for this position.
positioningReferenceKeystringKey for the coordinate system (contained by PositioningReferenceProvider) which shall serve as reference for this position.
Exceptions
- PositionigReferenceKeyUnknownException
CartesianCoordinateSystem(Position)
Constructor for a Cartesian coordinate system that is translated but not rotated with respect to the reference coordinate system. The pointer to the reference coordinate system is stored in variable origin.
public CartesianCoordinateSystem(Position origin)
Parameters
originPositionPosition of the origin with respect to the reference coordinate system, that is set via origin.ReferenceCoordinateSystem.
CartesianCoordinateSystem(Position, CoordinateSystemBaseVectors)
Constructor that uses a Position and a SystemBaseVectors
public CartesianCoordinateSystem(Position origin, CoordinateSystemBaseVectors axes)
Parameters
originPositionPosition of origin
axesCoordinateSystemBaseVectorsDirections of the axes
CartesianCoordinateSystem(Position, Quaternion)
Constructor that uses a position for the origin and which creates the base vectors from a quaternion.
public CartesianCoordinateSystem(Position origin, Quaternion quaternionOfBase)
Parameters
originPositionPosition of the origin.
quaternionOfBaseQuaternionQuaternion that describes the Cartesian base.
CartesianCoordinateSystem(Position, Vector3D, Vector3D, CoordinatePlane)
Constructor which gets the origin and only two base vectors. This may be helpful if one of the base vectors has already been created from a cross product, so creating the third base vector also by a cross product may produce large numerical problems.
public CartesianCoordinateSystem(Position origin, Vector3D axis1, Vector3D axis2, CoordinatePlane plane)
Parameters
originPositionPosition of the origin.
axis1Vector3DFirst base vector (meaning is set by planeIndex).
axis2Vector3DSecond base vector (meaning is set by planeIndex).
planeCoordinatePlaneSets the meaning of axis1 and axis2 by defining which plane is spanned by the given axes.
CartesianCoordinateSystem(Position, Vector3D, Vector3D, Vector3D)
Constructor that uses a position for the origin and the new axes, which must be orthogonal and should be normalized. This constructor is not recommended, because there's a significant probability for numerical inaccuracies which cause orthogonality problems. Better options may be the constructors getting a OrientationDefinitionBase or getting two axes and a plane index.
public CartesianCoordinateSystem(Position origin, Vector3D xAxis, Vector3D yAxis, Vector3D zAxis)
Parameters
originPositionPosition of the origin.
xAxisVector3DDirection cosine of the x-axis.
yAxisVector3DDirection cosine of the y-axis.
zAxisVector3DDirection cosine of the z-axis.
Properties
Axes
Gets or sets the axes or base vectors of the coordinate system
public CoordinateSystemBaseVectors Axes { get; set; }
Property Value
GetAllCoordinateSystemChangedEventTargets
Auxiliary method for finding all targets for the invocation of this element's CoordinateSystemChanged event
public List<object> GetAllCoordinateSystemChangedEventTargets { get; }
Property Value
GetPositioningReference
Property to get the coordinate system that serves as reference for this object
public CartesianCoordinateSystem GetPositioningReference { get; }
Property Value
IsDefinedAbsolutely
Are the origin's position and the axes directions defined absolutely?
public bool IsDefinedAbsolutely { get; }
Property Value
IsUndefined
Gets whether the coordinate system is undefined.
public bool IsUndefined { get; }
Property Value
- bool
trueiff the Origin member is undefined.
Origin
Gets or sets the origin of the coordinate system
public Position Origin { get; set; }
Property Value
PositioningReferenceKey
Get the key of the reference coordinate system for this
public string PositioningReferenceKey { get; }
Property Value
PositioningReferenceProvider
Get the object that provides the reference coordinate system for this
public IProvidesPositioningReferences PositioningReferenceProvider { get; }
Property Value
Methods
AxisAsPositionedLine(AxisDirection)
Extracts one axis as positioned line
public PositionedLine AxisAsPositionedLine(AxisDirection chosenAxis)
Parameters
chosenAxisAxisDirectionAxis to extract
Returns
- PositionedLine
Positioned line with the direction of the given axis and the position of this coordinate system.
Clone()
Deep copy
public override object Clone()
Returns
- object
Copy of this
Equals(object?, EqualityIntent)
Method which checks for equal objects.
public override bool Equals(object? obj, EqualityIntent equalityIntent)
Parameters
objobjectObject to compare with this.
equalityIntentEqualityIntentDefines what kind of equality you want to check when comparing two objects, for example all values or physical equality.
Returns
- bool
trueif obj and this are equal.
GetCSForReflection(CartesianCoordinateSystem, OrientedPlane)
Gets the coordinate system reflected, that means mirrored, on a given plane.
public static CartesianCoordinateSystem GetCSForReflection(CartesianCoordinateSystem coordinateSystemInput, OrientedPlane mirrorPlane)
Parameters
coordinateSystemInputCartesianCoordinateSystemThe coordinate system from the coordinate system for reflection is being generated.
mirrorPlaneOrientedPlaneThe plane the
coordinateSystemInputis mirrored on.
Returns
- CartesianCoordinateSystem
The input coordinate system, mirrored at
mirrorPlane.
GetCSFromAxisRotationsSequence(Position, AxisRotationSequence)
Constructs a new Cartesian coordinate system via axis rotation sequence
public static CartesianCoordinateSystem GetCSFromAxisRotationsSequence(Position origin, AxisRotationSequence sequence)
Parameters
originPositionOrigin of coordinate system in reference coordinates.
sequenceAxisRotationSequenceAxisRotationSequence that determines how to get the new coordinate system starting from its reference system.
Returns
- CartesianCoordinateSystem
New Cartesian coordinate system.
GetCSFromCartesianAnglesOfZAxis(Position, double, double, double, bool)
Constructs a new Cartesian coordinate system with respect to the reference cs (stored in origin) via z-rotation and Cartesian angles for the z-axis: The orientation of the coordinate system results from the reference cs in 2 steps and a certain order. A) inclinationFirst = false: (i) Rotation about z-axis with angle zeta - using the right-hand-rule, (ii) Inclination of z-axis specified by Cartesian angles. B) inclinationFirst = true: (i) Inclination of z-axis specified by Cartesian angles, (ii) Rotation about inclined z-axis by angle zeta - using the right-hand-rule.
public static CartesianCoordinateSystem GetCSFromCartesianAnglesOfZAxis(Position origin, double zeta, double alpha, double beta, bool inclinationFirst)
Parameters
originPositionOrigin of coordinate system in reference coordinates.
zetadoubleAngle (radian) of rotation about z-axis by using the right-hand-rule.
alphadoubleAngle between the z-axis and the projection of the z-axis onto the x-z-plane
betadoubleAngle between the z-axis and the projection of the z-axis onto the y-z-plane
inclinationFirstboolFlag to signal if z-axis is inclined first (true) or after rotation of z-axis (false).
Returns
- CartesianCoordinateSystem
New Cartesian coordinate system.
GetCSFromDirectionAnglesOfZAxis(Position, double, double, double, double, bool)
Constructs a new Cartesian coordinate system with respect to the reference cs (stored in origin) via z-rotation and direction angles: The orientation of the coordinate system results from the reference cs in 2 steps and a certain order. A) inclinationFirst=false: (i) Rotation about z-axis with angle zeta - using the right-hand-rule, (ii) Inclination of z-axis specified by direction angles rho, sigma, tau with the positive x-, y- and z-axis. B) inclinationFirst = true: (i) Inclination of z-axis via rho, sigma, tau, (ii) Rotation about inclined z-axis by angle zeta - using the right-hand-rule.
public static CartesianCoordinateSystem GetCSFromDirectionAnglesOfZAxis(Position origin, double zeta, double rho, double sigma, double tau, bool inclinationFirst)
Parameters
originPositionOrigin of coordinate system in reference coordinates.
zetadoubleAngle (in radian) of rotation about z-axis by using the right-hand-rule.
rhodoubleDirection cosine angle alpha in radian: angle of new z-axis with positive x-axis.
sigmadoubleDirection cosine beta in radian: angle of new z-axis with positive y-axis.
taudoubleDirection cosine beta in radian: angle of new z-axis with positive z-axis.
inclinationFirstboolFlag to signal if z-axis is inclined first (true) or after rotation of z-axis (false).
Returns
- CartesianCoordinateSystem
New Cartesian coordinate system.
GetCSFromDirectionOfZAxis(Position, double, Vector3D, bool)
Constructs a new Cartesian coordinate system with respect to the reference cs (stored in origin) via z-rotation and the direction vector of the z-axis: The orientation of the coordinate system results from the reference cs in 2 steps and a certain order . A) inclinationFirst = false: (i) Rotation about z-axis with angle zeta - using the right-hand-rule, (ii) Inclination of z-axis specified by new direction axis. B) inclinationFirst = true: (i) Inclination of z-axis specified by direction vector, (ii) Rotation about inclined z-axis by angle zeta - using the right-hand-rule.
public static CartesianCoordinateSystem GetCSFromDirectionOfZAxis(Position origin, double zeta, Vector3D directionOfZAxis, bool inclinationFirst)
Parameters
originPositionOrigin of coordinate system in reference coordinates.
zetadoubleAngle (radian) of rotation about z-axis by using the right-hand-rule.
directionOfZAxisVector3DDirection vector of new z-axis
inclinationFirstboolFlag to signal if z-axis is inclined first (true) or after rotation of z-axis (false).
Returns
- CartesianCoordinateSystem
New Cartesian coordinate system.
GetCSFromEulerAngles(Position, double, double, double)
Constructs a new Cartesian coordinate system from Euler angles. As our Euler angles definition follows the Z-X'-Z'-convention, the angles define a the rotation sequence consisting of exactly three simple rotations:
- rotation by Psi about the original Z axis,
- rotation by Theta about the new (intermediate) X' axis, which is also called 'line of nodes'
- rotation by Phi about the new Z' axis.
public static CartesianCoordinateSystem GetCSFromEulerAngles(Position origin, double eulerPsi, double eulerTheta, double eulerPhi)
Parameters
originPositionOrigin of coordinate system in reference coordinates.
eulerPsidoubleEuler angle Psi (about original z-axis).
eulerThetadoubleEuler angle Theta (about new x'-axis).
eulerPhidoubleEuler angle Phi (about the new z'-axis).
Returns
- CartesianCoordinateSystem
New Cartesian coordinate system.
GetCSFromOrientationDefinition(Position, OrientationDefinitionBase)
Constructs a new Cartesian coordinate system via any IOrientationDefinition
public static CartesianCoordinateSystem GetCSFromOrientationDefinition(Position origin, OrientationDefinitionBase orientationDefinition)
Parameters
originPositionOrigin of coordinate system in reference coordinates.
orientationDefinitionOrientationDefinitionBaseIOrientationDefinition that determines how to get the new coordinate system starting from its reference system.
Returns
- CartesianCoordinateSystem
New Cartesian coordinate system.
GetCSFromSphericalAnglesOfZAxis(Position, double, double, double, bool)
Constructs a new Cartesian coordinate system with respect to the reference cs (stored in origin) via z-rotation and spherical angles: The orientation of the coordinate system results from the reference cs in 2 steps and a certain order. A) inclinationFirst = false: (i) Rotation about z-axis with angle zeta - using the right-hand-rule, (ii) Inclination of z-axis by spherical angles phi and theta. B) inclinationFirst = true: (i) Inclination of z-axis by spherical angles phi and theta, (ii) Rotation about inclined z-axis by angle zeta - using the right-hand-rule.
public static CartesianCoordinateSystem GetCSFromSphericalAnglesOfZAxis(Position origin, double zeta, double zPhi, double zTheta, bool inclinationFirst)
Parameters
originPositionOrigin of coordinate system in reference coordinates.
zetadoubleAngle (radian) of rotation about z-axis by using the right-hand-rule.
zPhidoubleSpherical angle phi in radian for inclination of z-axis. This angle starts at the x-axis (zPhi = 0), while the y-axis corresponds to zPhi = 90°
zThetadoubleSpherical angle theta in radian for inclination of z-axis.
inclinationFirstboolFlag to signal if z-axis is inclined first (true) or after rotation about z-axis (false).
Returns
- CartesianCoordinateSystem
New Cartesian coordinate system, created from the given spherical angles.
GetCSMirroredAtOwnXYPlane(CartesianCoordinateSystem)
Returns a coordinate system that is mirrored at its own x-y-plane.
public static CartesianCoordinateSystem GetCSMirroredAtOwnXYPlane(CartesianCoordinateSystem coordinateSystemInput)
Parameters
coordinateSystemInputCartesianCoordinateSystemCoordinate system to mirror at own x-y-plane.
Returns
GetGlobalTransformationParameters(out Quaternion, out Vector3D)
Get the coordinate transformation parameters (rotation matrix and the origin position) with respect to the global coordinate system. A coordinate transformation from this coordinate system (x') to the global coordinate system (x) can be done by \(x = Rx' + o\) and vice versa: \(x' = R^T(x - o)\)
public void GetGlobalTransformationParameters(out Quaternion globalRotationMatrix, out Vector3D globalOriginPos)
Parameters
globalRotationMatrixQuaternionGlobal rotation matrix \(R\).
globalOriginPosVector3DOrigin \(o\) of this coordinate system in global (absolute) coordinates.
GetHashCode()
Just override
public override int GetHashCode()
Returns
GetReferenceHierarchy()
Gets the complete reference hierarchy of this. The global CS (null, "") will always be element 0 in the return list.
public List<(IProvidesPositioningReferences referenceProvider, string key)> GetReferenceHierarchy()
Returns
- List<(IProvidesPositioningReferences referenceProvider, string key)>
The reference hierarchy of this as a list. Element 0 will be the global CS while element [Count - 1] will be the immediate reference of this.
GetRotatedAndTranslatedCoordinateSystem(Vector3D, Quaternion)
Returns a new coordinate system that is rotated and translated by given values in reference to this and defined to the same reference like this.
public CartesianCoordinateSystem GetRotatedAndTranslatedCoordinateSystem(Vector3D offset, Quaternion rotation)
Parameters
offsetVector3DTranslation distance, defined in the external CS
rotationQuaternionQuaternion describing the rotation.
Returns
- CartesianCoordinateSystem
The transformed coordinate system.
GetRotationAsSphericalAnglesOfZAxis(out double, out double)
Gets the orientation of this by calculating the sphere angles theta and phi for the z axis
public void GetRotationAsSphericalAnglesOfZAxis(out double theta, out double phi)
Parameters
thetadoubleSphere angle theta, i.e. the inclination of the z axis to the z axis of the reference CS.
phidoubleSphere angle phi, i.e. the azimuth angle of the z axis to the x axis of the reference CS
GetTransformationParametersToCommonReference(CartesianCoordinateSystem?, CartesianCoordinateSystem?, out (Quaternion globalRotationMatrix, Vector3D globalOriginPos), out (Quaternion globalRotationMatrix, Vector3D globalOriginPos))
Method which calculates the transformation parameters for transforming from two coordinates systems to their common reference cs. See e.g. the constructor of TransformationsForCartesianCoordinateSystems for an example how to use the returned parameters.
public static void GetTransformationParametersToCommonReference(CartesianCoordinateSystem? cs1, CartesianCoordinateSystem? cs2, out (Quaternion globalRotationMatrix, Vector3D globalOriginPos) trafoFor1, out (Quaternion globalRotationMatrix, Vector3D globalOriginPos) trafoFor2)
Parameters
cs1CartesianCoordinateSystemCoordinate system 1 to calculate transformation parameters for.
cs2CartesianCoordinateSystemCoordinate system 2 to calculate transformation parameters for.
trafoFor1(Quaternion globalRotationMatrix, Vector3D globalOriginPos)The transformation parameters for transforming from the first cs to the common reference cs with the second cs.
trafoFor2(Quaternion globalRotationMatrix, Vector3D globalOriginPos)The transformation parameters for transforming from the second cs to the common reference cs with the first cs.
OnCoordinateSystemChanged()
Event throwing method
public void OnCoordinateSystemChanged()
SetPositioningReference(IProvidesPositioningReferences, string)
Method to set the PositioningReferenceProvider and the key for the coordinate system that serves as positioning reference
public void SetPositioningReference(IProvidesPositioningReferences referenceProvider, string key)
Parameters
referenceProviderIProvidesPositioningReferencesObject which provides the coordinate system that serves as reference for this position.
keystringKey for the coordinate system (contained by PositioningReferenceProvider) which shall serve as reference for this position
ToString()
method to generate a string description of the object
public override string ToString()
Returns
- string
the string description
TransformInternalPosition2PositionInReferenceCS(Vector3D)
Transforms a given position in this CS to the reference CS.
public Vector3D TransformInternalPosition2PositionInReferenceCS(Vector3D internalPos)
Parameters
internalPosVector3DPosition to transform
Returns
- Vector3D
Transformed position in reference CS
TransformPositionInReferenceCS2InternalPosition(Vector3D)
Transforms a given position from the reference coordinate system to this CS.
public Vector3D TransformPositionInReferenceCS2InternalPosition(Vector3D externalPos)
Parameters
externalPosVector3DPosition in the reference CS to transform
Returns
- Vector3D
Transformed internal position
Events
CoordinateSystemChanged
Event that is thrown if the Coordinate System is changed
public event EventHandler CoordinateSystemChanged
Event Type
Operators
operator ==(CartesianCoordinateSystem, CartesianCoordinateSystem)
Overloaded equality operator
public static bool operator ==(CartesianCoordinateSystem cs1, CartesianCoordinateSystem cs2)
Parameters
cs1CartesianCoordinateSystemFirst CartesianCoordinateSystem to compare
cs2CartesianCoordinateSystemSecond CartesianCoordinateSystem to compare
Returns
- bool
Are both CartesianCoordinateSystem equal?
operator !=(CartesianCoordinateSystem, CartesianCoordinateSystem)
Overloaded inequality operator
public static bool operator !=(CartesianCoordinateSystem cs1, CartesianCoordinateSystem cs2)
Parameters
cs1CartesianCoordinateSystemFirst CartesianCoordinateSystem to compare
cs2CartesianCoordinateSystemSecond CartesianCoordinateSystem to compare
Returns
- bool
Are both CartesianCoordinateSystem unequal?