Struct Vector
public struct Vector : IEquatable<Vector>, IFormattable
- Implements
- Inherited Members
Constructors
Vector(BigDecimal[], MathHelperOptions)
public Vector(BigDecimal[] components, MathHelperOptions options = default)
Parameters
componentsBigDecimal[]optionsMathHelperOptions
Vector(IEnumerable<BigDecimal>, MathHelperOptions)
public Vector(IEnumerable<BigDecimal> components, MathHelperOptions options = default)
Parameters
componentsIEnumerable<BigDecimal>optionsMathHelperOptions
Vector(IEnumerable<object>, MathHelperOptions)
public Vector(IEnumerable<object> components, MathHelperOptions options = default)
Parameters
componentsIEnumerable<object>optionsMathHelperOptions
Properties
Components
public IReadOnlyList<BigDecimal> Components { get; }
Property Value
- IReadOnlyList<BigDecimal>
Dimensions
public int Dimensions { get; }
Property Value
IsZero
public bool IsZero { get; }
Property Value
this[int]
public BigDecimal this[int index] { get; }
Parameters
indexint
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
Methods
Abs(Vector)
Element-wise absolute value.
public static Vector Abs(Vector v)
Parameters
vVector
Returns
AngleBetween(Vector, Vector, MathHelperOptions)
Angle (in radians) between two vectors.
public static BigDecimal AngleBetween(Vector a, Vector b, MathHelperOptions options)
Parameters
aVectorbVectoroptionsMathHelperOptions
Returns
- BigDecimal
Ceiling(Vector)
Element-wise ceiling.
public static Vector Ceiling(Vector v)
Parameters
vVector
Returns
Cross(Vector, Vector)
Cross product — defined only for 3-dimensional vectors.
public static Vector Cross(Vector a, Vector b)
Parameters
Returns
Distance(Vector, Vector)
Euclidean distance between two vectors (treated as points).
public static BigDecimal Distance(Vector a, Vector b)
Parameters
Returns
- BigDecimal
DistanceSquared(Vector, Vector)
Squared Euclidean distance — cheaper than Distance (no square root).
public static BigDecimal DistanceSquared(Vector a, Vector b)
Parameters
Returns
- BigDecimal
Dot(Vector, Vector)
Dot (inner) product of two vectors.
public static BigDecimal Dot(Vector a, Vector b)
Parameters
Returns
- BigDecimal
Equals(Vector)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Vector other)
Parameters
otherVectorAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
vVector
Returns
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
vVector<T>optionsMathHelperOptions
Returns
Type Parameters
TA numeric primitive supported by Vector<T> (e.g.
float,double,int,long).
FromVector2(Vector2, MathHelperOptions)
public static Vector FromVector2(Vector2 v, MathHelperOptions options = default)
Parameters
vVector2optionsMathHelperOptions
Returns
FromVector3(Vector3, MathHelperOptions)
public static Vector FromVector3(Vector3 v, MathHelperOptions options = default)
Parameters
vVector3optionsMathHelperOptions
Returns
FromVector4(Vector4, MathHelperOptions)
public static Vector FromVector4(Vector4 v, MathHelperOptions options = default)
Parameters
vVector4optionsMathHelperOptions
Returns
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
Returns
Max(Vector, Vector)
Element-wise maximum.
public static Vector Max(Vector a, Vector b)
Parameters
Returns
MaxByMagnitude(Vector, Vector)
Returns the vector with the largest magnitude.
public static Vector MaxByMagnitude(Vector a, Vector b)
Parameters
Returns
Min(Vector, Vector)
Element-wise minimum.
public static Vector Min(Vector a, Vector b)
Parameters
Returns
MinByMagnitude(Vector, Vector)
Returns the vector with the smallest magnitude.
public static Vector MinByMagnitude(Vector a, Vector b)
Parameters
Returns
Normalize()
Returns a unit vector in the same direction as this vector.
public Vector Normalize()
Returns
Project(Vector, Vector)
Vector projection of a onto b.
public static Vector Project(Vector a, Vector b)
Parameters
Returns
Reject(Vector, Vector)
Component of a perpendicular to b (vector rejection).
public static Vector Reject(Vector a, Vector b)
Parameters
Returns
Round(Vector)
Element-wise rounding (away from zero at midpoint).
public static Vector Round(Vector v)
Parameters
vVector
Returns
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
formatstringThe format to use.
-or-
A null reference (
Nothingin Visual Basic) to use the default format defined for the type of the IFormattable implementation.formatProviderIFormatProviderThe provider to use to format the value.
-or-
A null reference (
Nothingin 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
TA 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
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
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
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
dimensionsintaxisintoptionsMathHelperOptions
Returns
Zero(int, MathHelperOptions)
public static Vector Zero(int dimensions, MathHelperOptions options = default)
Parameters
dimensionsintoptionsMathHelperOptions
Returns
Operators
operator +(Vector, Vector)
public static Vector operator +(Vector a, Vector b)
Parameters
Returns
operator &(Vector, Vector)
Element-wise bitwise AND of two same-dimension vectors.
public static Vector operator &(Vector a, Vector b)
Parameters
Returns
operator |(Vector, Vector)
Element-wise bitwise OR of two same-dimension vectors.
public static Vector operator |(Vector a, Vector b)
Parameters
Returns
operator /(Vector, BigDecimal)
public static Vector operator /(Vector v, BigDecimal scalar)
Parameters
vVectorscalarBigDecimal
Returns
operator /(Vector, double)
public static Vector operator /(Vector v, double scalar)
Parameters
Returns
operator ==(Vector, Vector)
public static bool operator ==(Vector a, Vector b)
Parameters
Returns
operator ^(Vector, Vector)
Element-wise bitwise XOR of two same-dimension vectors.
public static Vector operator ^(Vector a, Vector b)
Parameters
Returns
explicit operator Vector2(Vector)
public static explicit operator Vector2(Vector v)
Parameters
vVector
Returns
explicit operator Vector3(Vector)
public static explicit operator Vector3(Vector v)
Parameters
vVector
Returns
explicit operator Vector4(Vector)
public static explicit operator Vector4(Vector v)
Parameters
vVector
Returns
explicit operator Vector(Vector2)
public static explicit operator Vector(Vector2 v)
Parameters
vVector2
Returns
explicit operator Vector(Vector3)
public static explicit operator Vector(Vector3 v)
Parameters
vVector3
Returns
explicit operator Vector(Vector4)
public static explicit operator Vector(Vector4 v)
Parameters
vVector4
Returns
operator !=(Vector, Vector)
public static bool operator !=(Vector a, Vector b)
Parameters
Returns
operator <<(Vector, int)
Element-wise left shift of each component by shift bits.
public static Vector operator <<(Vector v, int shift)
Parameters
Returns
operator %(Vector, BigDecimal)
Element-wise modulo: each component mod a scalar (integer semantics).
public static Vector operator %(Vector v, BigDecimal scalar)
Parameters
vVectorscalarBigDecimal
Returns
operator %(Vector, Vector)
Element-wise modulo between two vectors of the same dimension (integer semantics).
public static Vector operator %(Vector a, Vector b)
Parameters
Returns
operator *(BigDecimal, Vector)
public static Vector operator *(BigDecimal scalar, Vector v)
Parameters
scalarBigDecimalvVector
Returns
operator *(Vector, BigDecimal)
public static Vector operator *(Vector v, BigDecimal scalar)
Parameters
vVectorscalarBigDecimal
Returns
operator *(Vector, double)
public static Vector operator *(Vector v, double scalar)
Parameters
Returns
operator *(double, Vector)
public static Vector operator *(double scalar, Vector v)
Parameters
Returns
operator ~(Vector)
Element-wise bitwise NOT (ones complement) of each component.
public static Vector operator ~(Vector v)
Parameters
vVector
Returns
operator >>(Vector, int)
Element-wise right shift of each component by shift bits.
public static Vector operator >>(Vector v, int shift)
Parameters
Returns
operator -(Vector, Vector)
public static Vector operator -(Vector a, Vector b)
Parameters
Returns
operator -(Vector)
public static Vector operator -(Vector a)
Parameters
aVector