Struct VectorD
- Namespace
- VirtualLabAPI.Core.Numerics
- Assembly
- VirtualLabAPI.dll
This struct defines a two-dimensional vector of double numbers. Operators \(a+b\), \(a-b\) and \(a|b\) (Scalar product) can be used. One operand on \(a*b\), \(a/b\) (applied separate on components) can be also a double. It is also possible to raise a VectorD to a given power (\(a^b\)). Implicit casting from \linkToDoc{Vector}{API.Core.Numerics.Vector} is supported.
[Serializable]
public struct VectorD
- Inherited Members
Constructors
VectorD(double, double)
Creates a VectorD from two double values.
public VectorD(double x, double y)
Parameters
VectorD(Vector)
Creates a new VectorD object from an existing Vector.
public VectorD(Vector vector)
Parameters
vectorVectorThe Vector object to copy.
VectorD(VectorD)
Creates a new VectorD object from an existing object.
public VectorD(VectorD vector)
Parameters
vectorVectorDThe VectorD object to copy.
Fields
UndefinedVector
A constant vector containing 2 Double.NaNs. Property IsUndefined can be used to check for being undefined.
public static readonly VectorD UndefinedVector
Field Value
UnitVectorX
A constant containing the unit vector in x-direction.
public static readonly VectorD UnitVectorX
Field Value
UnitVectorY
A constant containing the unit vector in y-direction.
public static readonly VectorD UnitVectorY
Field Value
X
x-value of this VectorD object.
[NonSerialized]
public double X
Field Value
Y
y-value of this VectorD object.
[NonSerialized]
public double Y
Field Value
ZeroVector
A constant containing the zero vector (0, 0).
public static readonly VectorD 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 VectorD object. The absolute value corresponds to the length of the vector.
public double Abs()
Returns
- double
The absolute value of this VectorD.
AngleBetweenVectors(VectorD, VectorD)
Calculates the angle between two vectors in radians.
public static double AngleBetweenVectors(VectorD vector1, VectorD vector2)
Parameters
Returns
- double
The angle between the two vectors in radian. NaN if one of the vectors is the zero vector.
AreCollinear(VectorD, VectorD)
Checks whether two VectorD objects are collinear, i.e. they are parallel or anti-parallel.
public static bool AreCollinear(VectorD v1, VectorD v2)
Parameters
v1VectorDFirst vector to be checked for collinearity to second vector.
v2VectorDSecond vector to be checked for collinearity to first vector.
Returns
- bool
trueif v1 and v2 are collinear or a zero vector is given, otherwisefalse.
Ceil()
Calculates smallest integers less than x- and y-component and creates new VectorD using them.
public VectorD Ceil()
Returns
- VectorD
Result of operation.
ComponentAbs()
Calculates the absolute values of both elements of this VectorD and creates new one using them.
public VectorD ComponentAbs()
Returns
- VectorD
Result of operation.
Equals(object)
This function compares this vector and the vector given as parameter for equality.
public override bool Equals(object obj)
Parameters
objobjectVectorD to be compared with this vector.
Returns
- bool
Returns true if both values are equal.
Floor()
Calculates smallest integers greater than x- and y-component and creates new VectorD using them.
public VectorD Floor()
Returns
- VectorD
Result of operation.
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.
IntersectionOfCollinearLineSegments((NamedPolygonVertex start, NamedPolygonVertex end), (NamedPolygonVertex start, NamedPolygonVertex end))
Method which calculates the intersection of two line segments that are collinear.
public static ((VectorD coords, string name1, string name2) start, (VectorD coords, string name1, string name2) end) IntersectionOfCollinearLineSegments((NamedPolygonVertex start, NamedPolygonVertex end) firstSegment, (NamedPolygonVertex start, NamedPolygonVertex end) secondSegment)
Parameters
firstSegment(NamedPolygonVertex start, NamedPolygonVertex end)First line segment.
secondSegment(NamedPolygonVertex start, NamedPolygonVertex end)Second line segment.
Returns
- ((VectorD coords, string name1, string name2) start, (VectorD coords, string name1, string name2) end)
The intersection line segment if it exists. If the intersection is empty, the value (null, null) will be returned. If the intersection is identical to one point P, the value (P, null) will be returned.
Max()
Returns the maximum component value.
public double Max()
Returns
- double
The maximum component value.
Max(VectorD, VectorD)
Gets the component-wise maximum of two double vectors.
public static VectorD Max(VectorD v1, VectorD v2)
Parameters
Returns
- VectorD
New VectorD with component-wise maximum.
Min()
Returns the minimum component value.
public double Min()
Returns
- double
The minimum component value.
Min(VectorD, VectorD)
Gets the component-wise minimum of two double vectors.
public static VectorD Min(VectorD v1, VectorD v2)
Parameters
Returns
- VectorD
New VectorD with component-wise minimum.
Norm()
Calculates the norm (squared absolute value) of this VectorD object.
public double Norm()
Returns
- double
The norm of this VectorD object.
Normalize()
Normalizes this VectorD object.
public void Normalize()
Exceptions
- ArgumentException
Vector to normalize has a length of zero.
Parse(string)
Parse function of the VectorD class.
public static VectorD Parse(string vectorDAsString)
Parameters
vectorDAsStringstringThe string which should be parsed.
Returns
- VectorD
The VectorD object which was parsed from the input string.
Round()
Rounds both x- and y-coordinate of a VectorD to an integer and creates new VectorD using them.
public VectorD Round()
Returns
- VectorD
Result of operation.
RoundToVector()
public Vector RoundToVector()
Returns
- Vector
This vector rounded to integer values.
Sqrt()
Calculates the square roots of the components of this VectorD object and returns a new object.
public VectorD Sqrt()
Returns
- VectorD
The square root of the components of this VectorD object.
ToString()
Converts this VectorD into a string of format (X; Y).
public override string ToString()
Returns
- string
String containing the VectorD information.
ToString(int)
Converts this VectorD into a string of format (X; Y).
public string ToString(int numberOfDigits)
Parameters
numberOfDigitsintThe number of significant digits returned for the vector components.
Returns
Operators
operator +(VectorD, VectorD)
Adds two VectorD objects.
public static VectorD operator +(VectorD a, VectorD b)
Parameters
Returns
- VectorD
Returns the sum of the two VectorD objects.
operator |(VectorD, VectorD)
Calculates the scalar product of two VectorD objects.
public static double operator |(VectorD a, VectorD b)
Parameters
Returns
- double
Scalar product of the two VectorD objects.
operator /(double, VectorD)
Performs a component-wise division of a double value and a VectorD object.
The result is defined as new VectorD(number / vector.X, number / vector.Y).
public static VectorD operator /(double number, VectorD vector)
Parameters
numberdoubleThe double value to divide by the components of the VectorD object.
vectorVectorDThe VectorD object used as divisor.
Returns
- VectorD
Returns the quotient of the double value and the VectorD object.
operator /(VectorD, double)
public static VectorD operator /(VectorD vector, double divisor)
Parameters
vectorVectorDThe VectorD object to divide by the double value.
divisordoubleThe double value used as divisor.
Returns
- VectorD
Returns the quotient of the VectorD object and the double value.
operator /(VectorD, VectorD)
Performs a component-wise division of two VectorD objects.
public static VectorD operator /(VectorD a, VectorD b)
Parameters
aVectorDThe first VectorD object to divide by parameter b.
bVectorDThe second VectorD object used as divisor.
Returns
- VectorD
Returns the quotient of the two VectorD objects.
operator ==(VectorD, VectorD)
Compares two VectorD for equality. The comparison will be done by comparing the values of the two x- and y-components, respectively.
public static bool operator ==(VectorD vector1, VectorD vector2)
Parameters
Returns
- bool
Returns true if the two objects are equal.
implicit operator VectorD((double x, double y))
Converts a tuple of two double values into a VectorD object.
public static implicit operator VectorD((double x, double y) tuple)
Parameters
Returns
- VectorD
Converted VectorD object.
implicit operator VectorD(Vector)
public static implicit operator VectorD(Vector vector)
Parameters
vectorVectorVector object to be converted.
Returns
- VectorD
Converted VectorD.
implicit operator VectorD(VectorL)
public static implicit operator VectorD(VectorL vector)
Parameters
vectorVectorLVectorL object to be converted.
Returns
- VectorD
Converted VectorD.
operator !=(VectorD, VectorD)
Compares two VectorD for inequality. The comparison will be done by comparing the values of the two x- and y-components, respectively.
public static bool operator !=(VectorD vector1, VectorD vector2)
Parameters
Returns
- bool
Returns true if the two objects are unequal.
operator *(double, VectorD)
public static VectorD operator *(double factor, VectorD vector)
Parameters
Returns
- VectorD
Returns the product of the VectorD object and the double value.
operator *(VectorD, double)
public static VectorD operator *(VectorD vector, double factor)
Parameters
Returns
- VectorD
Returns the product of the VectorD object and the double value.
operator *(VectorD, VectorD)
Multiplies two VectorD objects.
public static VectorD operator *(VectorD a, VectorD b)
Parameters
Returns
- VectorD
Returns the product of the two VectorD objects.
operator -(VectorD, VectorD)
Subtracts two VectorD objects.
public static VectorD operator -(VectorD a, VectorD b)
Parameters
aVectorDThe first VectorD object to subtract from.
bVectorDThe second VectorD object to subtract.
Returns
- VectorD
Returns the difference of the two VectorD objects.
operator -(VectorD)
Returns the negated argument.
public static VectorD operator -(VectorD a)
Parameters
aVectorDThe vector to negate.
Returns
- VectorD
The vector multiplied with -1.