Table of Contents

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

x double

x-value of new Vector3D object.

y double

y-value of new Vector3D object.

z double

z-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

alpha double

First angle; interpretation depends on useDirectionAngles.

beta double

Second angle; interpretation depends on useDirectionAngles.

length double

Length of new Vector3D.

useDirectionAngles bool

Parameters 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

toCopy Vector3D

Vector3D to be copied.

Fields

NegUnitVectorZ

A constant containing the unit vector in negative z-direction.

public static readonly Vector3D NegUnitVectorZ

Field Value

Vector3D

UndefinedVector

A constant vector containing 3 NaN. Property IsUndefined can be used to check for being undefined.

public static readonly Vector3D UndefinedVector

Field Value

Vector3D

UndeterminedVector

A constant containing an undetermined vector.

public static readonly Vector3D UndeterminedVector

Field Value

Vector3D

UnitVectorX

A constant containing the unit vector in x-direction.

public static readonly Vector3D UnitVectorX

Field Value

Vector3D

UnitVectorY

A constant containing the unit vector in y-direction.

public static readonly Vector3D UnitVectorY

Field Value

Vector3D

UnitVectorZ

A constant containing the unit vector in z-direction.

public static readonly Vector3D UnitVectorZ

Field Value

Vector3D

X

x-value of the Vector3D object.

public double X

Field Value

double

Y

y-value of the Vector3D object.

public double Y

Field Value

double

Z

z-value of the Vector3D object.

public double Z

Field Value

double

ZeroVector

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

public static readonly Vector3D ZeroVector

Field Value

Vector3D

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 the vector is NaN.

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

vector1 Vector3D

The first vector.

vector2 Vector3D

The second vector.

Returns

double

The angle between the two vectors. NaN if one of the vectors is the zero vector.

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

p1 Vector3D

3D point 1.

p2 Vector3D

3D point 2.

p3 Vector3D

3D point 3.

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

v1 Vector3D

First vector

v2 Vector3D

Second vector

Returns

bool

true if the two vectors are parallel or anti-parallel, otherwise false.

CrossProduct(Vector3D, Vector3D)

Calculates the cross product of two Vector3D objects.

public static Vector3D CrossProduct(Vector3D a, Vector3D b)

Parameters

a Vector3D

First operand used for cross product calculation.

b Vector3D

Second 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

vector3D object

Vector3D 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

type DirectionDefinitionType

Type 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

vector3DAsString string

The 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

axis Vector3D

The axis that shall be used for rotation.

angle double

The angle used for rotation.

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

digitPrecision int

Number 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

a Vector3D

The first Vector3D object to add.

b Vector3D

The second Vector3D object to add.

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

a Vector3D

First Vector3D object.

b Vector3D

Second Vector3D object.

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

number double

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

vector Vector3D

The Vector3D object used as divisor.

Returns

Vector3D

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

operator /(Vector3D, double)

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

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

Parameters

vector Vector3D

The Vector3D object to divide by the double value.

divisor double

The 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

a Vector3D

The first Vector3D object to divide by parameter b.

b Vector3D

The 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

vector1 Vector3D

First Vector3D object to compare.

vector2 Vector3D

Second 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

vector1 Vector3D

First Vector3D object to compare.

vector2 Vector3D

Second Vector3D object to compare.

Returns

bool

Returns true if the two objects are unequal.

operator *(double, Vector3D)

Multiplies a Vector3D object with a double value.

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

Parameters

factor double

The double value to multiply.

vector Vector3D

The Vector3D object to multiply.

Returns

Vector3D

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

operator *(Vector3D, double)

Multiplies a Vector3D object with a double value.

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

Parameters

vector Vector3D

The Vector3D object to multiply.

factor double

The double value to multiply.

Returns

Vector3D

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

operator *(Vector3D, Complex)

Multiplies a Vector3D object with a Complex value.

public static Vector3C operator *(Vector3D vector, Complex factor)

Parameters

vector Vector3D

The Vector3D object to multiply.

factor Complex

The Complex value to multiply.

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

a Vector3D

The first Vector3D object to multiply.

b Vector3D

The 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

a Vector3D

The first Vector3D object to subtract from.

b Vector3D

The 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

v Vector3D

Vector to invert.

Returns

Vector3D

Returns the inverse -v of the Vector3D object.