Table of Contents

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

x double

x-value of new VectorD object.

y double

y-value of new VectorD object.

VectorD(Vector)

Creates a new VectorD object from an existing Vector.

public VectorD(Vector vector)

Parameters

vector Vector

The Vector object to copy.

VectorD(VectorD)

Creates a new VectorD object from an existing object.

public VectorD(VectorD vector)

Parameters

vector VectorD

The 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

VectorD

UnitVectorX

A constant containing the unit vector in x-direction.

public static readonly VectorD UnitVectorX

Field Value

VectorD

UnitVectorY

A constant containing the unit vector in y-direction.

public static readonly VectorD UnitVectorY

Field Value

VectorD

X

x-value of this VectorD object.

[NonSerialized]
public double X

Field Value

double

Y

y-value of this VectorD object.

[NonSerialized]
public double Y

Field Value

double

ZeroVector

A constant containing the zero vector (0, 0).

public static readonly VectorD ZeroVector

Field Value

VectorD

Properties

IsUndefined

Gets whether a least one component of the vector is undefined.

public bool IsUndefined { get; }

Property Value

bool

true iff at least one component of this vector is NaN.

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

vector1 VectorD

The first vector.

vector2 VectorD

The second vector.

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

v1 VectorD

First vector to be checked for collinearity to second vector.

v2 VectorD

Second vector to be checked for collinearity to first vector.

Returns

bool

true if v1 and v2 are collinear or a zero vector is given, otherwise false.

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

obj object

VectorD 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

v1 VectorD

The first VectorD.

v2 VectorD

The second VectorD.

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

v1 VectorD

The first VectorD.

v2 VectorD

The second VectorD.

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

vectorDAsString string

The 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()

Round both X and Y to int and returns a Vector.

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

numberOfDigits int

The number of significant digits returned for the vector components.

Returns

string

A string that represents this instance.

Operators

operator +(VectorD, VectorD)

Adds two VectorD objects.

public static VectorD operator +(VectorD a, VectorD b)

Parameters

a VectorD

The first VectorD object to add.

b VectorD

The second VectorD object to add.

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

a VectorD

First VectorD object.

b VectorD

Second VectorD object.

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

number double

The double value to divide by the components of the VectorD object.

vector VectorD

The VectorD object used as divisor.

Returns

VectorD

Returns the quotient of the double value and the VectorD object.

operator /(VectorD, double)

Performs a component-wise division of a VectorD object and a double value.

public static VectorD operator /(VectorD vector, double divisor)

Parameters

vector VectorD

The VectorD object to divide by the double value.

divisor double

The 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

a VectorD

The first VectorD object to divide by parameter b.

b VectorD

The 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

vector1 VectorD

First VectorD object to compare.

vector2 VectorD

Second VectorD object to compare.

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

tuple (double x, double y)

The tuple to convert into a VectorD object.

Returns

VectorD

Converted VectorD object.

implicit operator VectorD(Vector)

Converts a Vector object to a VectorD object.

public static implicit operator VectorD(Vector vector)

Parameters

vector Vector

Vector object to be converted.

Returns

VectorD

Converted VectorD.

implicit operator VectorD(VectorL)

Converts a VectorL object to a VectorD object.

public static implicit operator VectorD(VectorL vector)

Parameters

vector VectorL

VectorL 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

vector1 VectorD

First VectorD object to compare.

vector2 VectorD

Second VectorD object to compare.

Returns

bool

Returns true if the two objects are unequal.

operator *(double, VectorD)

Multiplies a VectorD object with a double value.

public static VectorD operator *(double factor, VectorD vector)

Parameters

factor double

The double value to multiply.

vector VectorD

The VectorD object to multiply.

Returns

VectorD

Returns the product of the VectorD object and the double value.

operator *(VectorD, double)

Multiplies a VectorD object with a double value.

public static VectorD operator *(VectorD vector, double factor)

Parameters

vector VectorD

The VectorD object to multiply.

factor double

The double value to multiply.

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

a VectorD

The first VectorD object to multiply.

b VectorD

The second VectorD object to multiply.

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

a VectorD

The first VectorD object to subtract from.

b VectorD

The 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

a VectorD

The vector to negate.

Returns

VectorD

The vector multiplied with -1.