Table of Contents

Struct Vector

Namespace
NCalc.Domain
Assembly
NCalc.dll
public struct Vector : IEquatable<Vector>, IFormattable
Implements
Inherited Members

Constructors

Vector(BigDecimal[], MathHelperOptions)

public Vector(BigDecimal[] components, MathHelperOptions options = default)

Parameters

components BigDecimal[]
options MathHelperOptions

Vector(IEnumerable<BigDecimal>, MathHelperOptions)

public Vector(IEnumerable<BigDecimal> components, MathHelperOptions options = default)

Parameters

components IEnumerable<BigDecimal>
options MathHelperOptions

Vector(IEnumerable<object>, MathHelperOptions)

public Vector(IEnumerable<object> components, MathHelperOptions options = default)

Parameters

components IEnumerable<object>
options MathHelperOptions

Properties

Components

public IReadOnlyList<BigDecimal> Components { get; }

Property Value

IReadOnlyList<BigDecimal>

Dimensions

public int Dimensions { get; }

Property Value

int

IsZero

public bool IsZero { get; }

Property Value

bool

this[int]

public BigDecimal this[int index] { get; }

Parameters

index int

Property Value

BigDecimal

Magnitude

Euclidean length (magnitude) of the vector.

public BigDecimal Magnitude { get; }

Property Value

BigDecimal

MagnitudeSquared

Square of the Euclidean magnitude — cheaper than Magnitude (no square root).

public BigDecimal MagnitudeSquared { get; }

Property Value

BigDecimal

Tolerance

public static double Tolerance { get; set; }

Property Value

double

Methods

Abs(Vector)

Element-wise absolute value.

public static Vector Abs(Vector v)

Parameters

v Vector

Returns

Vector

AngleBetween(Vector, Vector, MathHelperOptions)

Angle (in radians) between two vectors.

public static BigDecimal AngleBetween(Vector a, Vector b, MathHelperOptions options)

Parameters

a Vector
b Vector
options MathHelperOptions

Returns

BigDecimal

Ceiling(Vector)

Element-wise ceiling.

public static Vector Ceiling(Vector v)

Parameters

v Vector

Returns

Vector

Cross(Vector, Vector)

Cross product — defined only for 3-dimensional vectors.

public static Vector Cross(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

Distance(Vector, Vector)

Euclidean distance between two vectors (treated as points).

public static BigDecimal Distance(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

BigDecimal

DistanceSquared(Vector, Vector)

Squared Euclidean distance — cheaper than Distance (no square root).

public static BigDecimal DistanceSquared(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

BigDecimal

Dot(Vector, Vector)

Dot (inner) product of two vectors.

public static BigDecimal Dot(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

BigDecimal

Equals(Vector)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Vector other)

Parameters

other Vector

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Floor(Vector)

Element-wise floor.

public static Vector Floor(Vector v)

Parameters

v Vector

Returns

Vector

FromSystemVector<T>(Vector<T>, MathHelperOptions)

Creates an NCalc Vector from a Vector<T>. All Count elements are converted to ExtendedNumerics.BigDecimal via double.

public static Vector FromSystemVector<T>(Vector<T> v, MathHelperOptions options = default) where T : struct

Parameters

v Vector<T>
options MathHelperOptions

Returns

Vector

Type Parameters

T

A numeric primitive supported by Vector<T> (e.g. float, double, int, long).

FromVector2(Vector2, MathHelperOptions)

Creates an NCalc Vector from a Vector2.

public static Vector FromVector2(Vector2 v, MathHelperOptions options = default)

Parameters

v Vector2
options MathHelperOptions

Returns

Vector

FromVector3(Vector3, MathHelperOptions)

Creates an NCalc Vector from a Vector3.

public static Vector FromVector3(Vector3 v, MathHelperOptions options = default)

Parameters

v Vector3
options MathHelperOptions

Returns

Vector

FromVector4(Vector4, MathHelperOptions)

Creates an NCalc Vector from a Vector4.

public static Vector FromVector4(Vector4 v, MathHelperOptions options = default)

Parameters

v Vector4
options MathHelperOptions

Returns

Vector

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Lerp(Vector, Vector, BigDecimal)

Linear interpolation: (1-t)a + tb.

public static Vector Lerp(Vector a, Vector b, BigDecimal t)

Parameters

a Vector
b Vector
t BigDecimal

Returns

Vector

Max(Vector, Vector)

Element-wise maximum.

public static Vector Max(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

MaxByMagnitude(Vector, Vector)

Returns the vector with the largest magnitude.

public static Vector MaxByMagnitude(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

Min(Vector, Vector)

Element-wise minimum.

public static Vector Min(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

MinByMagnitude(Vector, Vector)

Returns the vector with the smallest magnitude.

public static Vector MinByMagnitude(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

Normalize()

Returns a unit vector in the same direction as this vector.

public Vector Normalize()

Returns

Vector

Project(Vector, Vector)

Vector projection of a onto b.

public static Vector Project(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

Reject(Vector, Vector)

Component of a perpendicular to b (vector rejection).

public static Vector Reject(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

Round(Vector)

Element-wise rounding (away from zero at midpoint).

public static Vector Round(Vector v)

Parameters

v Vector

Returns

Vector

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

ToString(string?, IFormatProvider?)

Formats the value of the current instance using the specified format.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

formatProvider IFormatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns

string

The value of the current instance in the specified format.

ToSystemVector<T>()

Converts this vector to a Vector<T>. The number of dimensions must equal Count on the current hardware; otherwise an InvalidOperationException is thrown. Component values are narrowed from ExtendedNumerics.BigDecimal to T via double, so values are accurate to double precision.

public Vector<T> ToSystemVector<T>() where T : struct

Returns

Vector<T>

Type Parameters

T

A numeric primitive supported by Vector<T> (e.g. float, double, int, long).

Exceptions

InvalidOperationException

The vector's dimension count does not match Count.

ToVector2()

Converts this vector to a Vector2. Requires exactly 2 dimensions; components are narrowed to float.

public Vector2 ToVector2()

Returns

Vector2

Exceptions

InvalidOperationException

The vector does not have exactly 2 dimensions.

ToVector3()

Converts this vector to a Vector3. Requires exactly 3 dimensions; components are narrowed to float.

public Vector3 ToVector3()

Returns

Vector3

Exceptions

InvalidOperationException

The vector does not have exactly 3 dimensions.

ToVector4()

Converts this vector to a Vector4. Requires exactly 4 dimensions; components are narrowed to float.

public Vector4 ToVector4()

Returns

Vector4

Exceptions

InvalidOperationException

The vector does not have exactly 4 dimensions.

Unit(int, int, MathHelperOptions)

public static Vector Unit(int dimensions, int axis, MathHelperOptions options = default)

Parameters

dimensions int
axis int
options MathHelperOptions

Returns

Vector

Zero(int, MathHelperOptions)

public static Vector Zero(int dimensions, MathHelperOptions options = default)

Parameters

dimensions int
options MathHelperOptions

Returns

Vector

Operators

operator +(Vector, Vector)

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

Parameters

a Vector
b Vector

Returns

Vector

operator &(Vector, Vector)

Element-wise bitwise AND of two same-dimension vectors.

public static Vector operator &(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

operator |(Vector, Vector)

Element-wise bitwise OR of two same-dimension vectors.

public static Vector operator |(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

operator /(Vector, BigDecimal)

public static Vector operator /(Vector v, BigDecimal scalar)

Parameters

v Vector
scalar BigDecimal

Returns

Vector

operator /(Vector, double)

public static Vector operator /(Vector v, double scalar)

Parameters

v Vector
scalar double

Returns

Vector

operator ==(Vector, Vector)

public static bool operator ==(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

bool

operator ^(Vector, Vector)

Element-wise bitwise XOR of two same-dimension vectors.

public static Vector operator ^(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

explicit operator Vector2(Vector)

Explicitly converts an NCalc Vector to a Vector2.

public static explicit operator Vector2(Vector v)

Parameters

v Vector

Returns

Vector2

explicit operator Vector3(Vector)

Explicitly converts an NCalc Vector to a Vector3.

public static explicit operator Vector3(Vector v)

Parameters

v Vector

Returns

Vector3

explicit operator Vector4(Vector)

Explicitly converts an NCalc Vector to a Vector4.

public static explicit operator Vector4(Vector v)

Parameters

v Vector

Returns

Vector4

explicit operator Vector(Vector2)

Explicitly converts a Vector2 to an NCalc Vector.

public static explicit operator Vector(Vector2 v)

Parameters

v Vector2

Returns

Vector

explicit operator Vector(Vector3)

Explicitly converts a Vector3 to an NCalc Vector.

public static explicit operator Vector(Vector3 v)

Parameters

v Vector3

Returns

Vector

explicit operator Vector(Vector4)

Explicitly converts a Vector4 to an NCalc Vector.

public static explicit operator Vector(Vector4 v)

Parameters

v Vector4

Returns

Vector

operator !=(Vector, Vector)

public static bool operator !=(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

bool

operator <<(Vector, int)

Element-wise left shift of each component by shift bits.

public static Vector operator <<(Vector v, int shift)

Parameters

v Vector
shift int

Returns

Vector

operator %(Vector, BigDecimal)

Element-wise modulo: each component mod a scalar (integer semantics).

public static Vector operator %(Vector v, BigDecimal scalar)

Parameters

v Vector
scalar BigDecimal

Returns

Vector

operator %(Vector, Vector)

Element-wise modulo between two vectors of the same dimension (integer semantics).

public static Vector operator %(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

operator *(BigDecimal, Vector)

public static Vector operator *(BigDecimal scalar, Vector v)

Parameters

scalar BigDecimal
v Vector

Returns

Vector

operator *(Vector, BigDecimal)

public static Vector operator *(Vector v, BigDecimal scalar)

Parameters

v Vector
scalar BigDecimal

Returns

Vector

operator *(Vector, double)

public static Vector operator *(Vector v, double scalar)

Parameters

v Vector
scalar double

Returns

Vector

operator *(double, Vector)

public static Vector operator *(double scalar, Vector v)

Parameters

scalar double
v Vector

Returns

Vector

operator ~(Vector)

Element-wise bitwise NOT (ones complement) of each component.

public static Vector operator ~(Vector v)

Parameters

v Vector

Returns

Vector

operator >>(Vector, int)

Element-wise right shift of each component by shift bits.

public static Vector operator >>(Vector v, int shift)

Parameters

v Vector
shift int

Returns

Vector

operator -(Vector, Vector)

public static Vector operator -(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

operator -(Vector)

public static Vector operator -(Vector a)

Parameters

a Vector

Returns

Vector