Struct Vector3D
- Namespace
- VirtualLabAPI.Core.Numerics
- Assembly
- VirtualLabAPI.dll
This struct defines a three-dimensional vector of double numbers. Operators \(a+b\), \(a-b\) and \(a|b\) (Scalar product) can be used. Second operand on \(a*b\), \(a/b\) and \(a^b\) (applied separate on components) can be a double too.
[Serializable]
public struct Vector3D
- Inherited Members
Constructors
Vector3D(double, double, double)
Creates a Vector3D from three double values.
public Vector3D(double x, double y, double z)
Parameters
xdoublex-value of new Vector3D object.
ydoubley-value of new Vector3D object.
zdoublez-value of new Vector3D object.
Vector3D(double, double, double, bool)
Creates a Vector3D using given angles and length.
public Vector3D(double alpha, double beta, double length, bool useDirectionAngles)
Parameters
alphadoubleFirst angle; interpretation depends on useDirectionAngles.
betadoubleSecond angle; interpretation depends on useDirectionAngles.
lengthdoubleLength of new Vector3D.
useDirectionAnglesboolParameters can be interpreted in two different ways: true → Cartesian angles; false → sphere angles.
Vector3D(Vector3D)
Creates a copy of given Vector3D.
public Vector3D(Vector3D toCopy)
Parameters
toCopyVector3DVector3D to be copied.
Fields
NegUnitVectorZ
A constant containing the unit vector in negative z-direction.
public static readonly Vector3D NegUnitVectorZ
Field Value
UndefinedVector
A constant vector containing 3 NaN. Property IsUndefined can be used to check for being undefined.
public static readonly Vector3D UndefinedVector
Field Value
UndeterminedVector
A constant containing an undetermined vector.
public static readonly Vector3D UndeterminedVector
Field Value
UnitVectorX
A constant containing the unit vector in x-direction.
public static readonly Vector3D UnitVectorX
Field Value
UnitVectorY
A constant containing the unit vector in y-direction.
public static readonly Vector3D UnitVectorY
Field Value
UnitVectorZ
A constant containing the unit vector in z-direction.
public static readonly Vector3D UnitVectorZ
Field Value
X
x-value of the Vector3D object.
public double X
Field Value
Y
y-value of the Vector3D object.
public double Y
Field Value
Z
z-value of the Vector3D object.
public double Z
Field Value
ZeroVector
A constant containing the zero vector (0, 0, 0).
public static readonly Vector3D ZeroVector
Field Value
Properties
IsUndefined
Gets whether a least one component of the vector is undefined.
public bool IsUndefined { get; }
Property Value
Methods
Abs()
Calculates the absolute value of this Vector3D object. The absolute value corresponds to the length of the vector.
public double Abs()
Returns
- double
The absolute value of this Vector3D.
AngleBetweenVectors(Vector3D, Vector3D)
Calculates the angle between two between vectors.
public static double AngleBetweenVectors(Vector3D vector1, Vector3D vector2)
Parameters
Returns
ArePointsCollinear(Vector3D, Vector3D, Vector3D)
Static method to check if three 3D-points lie on a line (i. e. being collinear).
public static bool ArePointsCollinear(Vector3D p1, Vector3D p2, Vector3D p3)
Parameters
Returns
- bool
True, iff all three points lie on a line or at least two points are equal.
AreVectorsCollinear(Vector3D, Vector3D)
Static method to check (with numerical tolerance) whether two vectors are parallel or anti-parallel.
public static bool AreVectorsCollinear(Vector3D v1, Vector3D v2)
Parameters
Returns
CrossProduct(Vector3D, Vector3D)
Calculates the cross product of two Vector3D objects.
public static Vector3D CrossProduct(Vector3D a, Vector3D b)
Parameters
aVector3DFirst operand used for cross product calculation.
bVector3DSecond operand used for cross product calculation.
Returns
- Vector3D
A Vector3D object containing the cross product.
Equals(object)
This function compares the values of this vector and the vector given as parameter.
public override bool Equals(object vector3D)
Parameters
vector3DobjectVector3D to be compared.
Returns
- bool
Returns true if both object values are equal.
GetDirection(DirectionDefinitionType)
Gets the direction of this, described by a DirectionDefinition of a given type.
public DirectionDefinitionBase GetDirection(DirectionDefinitionType type)
Parameters
typeDirectionDefinitionTypeType of the DirectionDefinition.
Returns
- DirectionDefinitionBase
Orientation of this as DirectionDefinition of a given type.
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
IsZeroVector()
Checks if the vector is the zero vector within a certain epsilon.
public bool IsZeroVector()
Returns
- bool
True, if vector is the zero vector within a certain epsilon.
Norm()
Calculates the squared absolute value of this Vector3D object.
public double Norm()
Returns
- double
The squared length of this Vector3D object.
Normalize()
Normalizes this Vector3D object.
public void Normalize()
Exceptions
- ArgumentException
Vector to normalize has a length of zero.
Parse(string)
Function to parse a vector 3D from given string.
public static Vector3D Parse(string vector3DAsString)
Parameters
vector3DAsStringstringThe string that should be parsed.
Returns
- Vector3D
The parsed Vector3D object.
Rotate(Vector3D, double)
Rotates this vector by a given angle about a given axis.
public Vector3D Rotate(Vector3D axis, double angle)
Parameters
Returns
- Vector3D
The rotated vector.
ToString()
Converts a Vector3D into a string of format (X; Y; Z). For the creation of the string the default number of digits specified in NumberOfDigits will be used.
public override string ToString()
Returns
- string
String containing the vector information.
ToString(int)
Converts a Vector3D into a string of format (X, Y, Z).
public string ToString(int digitPrecision)
Parameters
digitPrecisionintNumber of digits the values are rounded to.
Returns
- string
String containing the vector information.
Operators
operator +(Vector3D, Vector3D)
Adds two Vector3D objects.
public static Vector3D operator +(Vector3D a, Vector3D b)
Parameters
Returns
- Vector3D
Returns the sum of the two Vector3D objects.
operator |(Vector3D, Vector3D)
Calculates the scalar product of two Vector3D objects.
public static double operator |(Vector3D a, Vector3D b)
Parameters
Returns
- double
Scalar product of the two Vector3D objects.
operator /(double, Vector3D)
Performs a component-wise division of a double value and a Vector3D object.
The result is defined as new VectorD(number / vector.X, number / vector.Y).
public static Vector3D operator /(double number, Vector3D vector)
Parameters
numberdoubleThe double value to divide by the components of the Vector3D object.
vectorVector3DThe Vector3D object used as divisor.
Returns
- Vector3D
Returns the quotient of the double value and the Vector3D object.
operator /(Vector3D, double)
public static Vector3D operator /(Vector3D vector, double divisor)
Parameters
vectorVector3DThe Vector3D object to divide by the double value.
divisordoubleThe double value used as divisor.
Returns
- Vector3D
Returns the quotient of the Vector3D object and the double value.
operator /(Vector3D, Vector3D)
Performs a component-wise division of two Vector3D objects.
public static Vector3D operator /(Vector3D a, Vector3D b)
Parameters
aVector3DThe first Vector3D object to divide by parameter b.
bVector3DThe second Vector3D object used as divisor.
Returns
- Vector3D
Returns the quotient of the two Vector3D objects.
operator ==(Vector3D, Vector3D)
Compares two Vector3D for equality. The comparison will be done by comparing the values of the x-, y- and z-components respectively.
public static bool operator ==(Vector3D vector1, Vector3D vector2)
Parameters
vector1Vector3DFirst Vector3D object to compare.
vector2Vector3DSecond Vector3D object to compare.
Returns
- bool
Returns true if the two objects are equal.
operator !=(Vector3D, Vector3D)
Compares two Vector3D for inequality. The comparison will be done by comparing the values of the x-, y- and z-components respectively.
public static bool operator !=(Vector3D vector1, Vector3D vector2)
Parameters
vector1Vector3DFirst Vector3D object to compare.
vector2Vector3DSecond Vector3D object to compare.
Returns
- bool
Returns true if the two objects are unequal.
operator *(double, Vector3D)
public static Vector3D operator *(double factor, Vector3D vector)
Parameters
Returns
- Vector3D
Returns the product of the Vector3D object and the double value.
operator *(Vector3D, double)
public static Vector3D operator *(Vector3D vector, double factor)
Parameters
Returns
- Vector3D
Returns the product of the Vector3D object and the double value.
operator *(Vector3D, Complex)
public static Vector3C operator *(Vector3D vector, Complex factor)
Parameters
Returns
- Vector3C
Returns the product of the Vector3D object and the Complex value.
operator *(Vector3D, Vector3D)
Multiplies two Vector3D objects.
public static Vector3D operator *(Vector3D a, Vector3D b)
Parameters
aVector3DThe first Vector3D object to multiply.
bVector3DThe second Vector3D object to multiply.
Returns
- Vector3D
Returns the product of the two Vector3D objects.
operator -(Vector3D, Vector3D)
Subtracts two Vector3D objects.
public static Vector3D operator -(Vector3D a, Vector3D b)
Parameters
aVector3DThe first Vector3D object to subtract from.
bVector3DThe second Vector3D object to subtract.
Returns
- Vector3D
Returns the difference of the two Vector3D objects.
operator -(Vector3D)
Inverts a Vector3D object.
public static Vector3D operator -(Vector3D v)
Parameters
vVector3DVector to invert.
Returns
- Vector3D
Returns the inverse -v of the Vector3D object.