Struct Vector2d
- Namespace
- FixedMathSharp
- Assembly
- FixedMathSharp.dll
Represents a 2D vector with fixed-point precision, offering a range of mathematical operations and transformations such as rotation, scaling, reflection, and interpolation.
[MemoryPackable(GenerateType.Object)]
public struct Vector2d : IEquatable<Vector2d>, IComparable<Vector2d>, IEqualityComparer<Vector2d>, ISpanFormattable, IFormattable, IMemoryPackable<Vector2d>, IMemoryPackFormatterRegister
- Implements
-
IMemoryPackable<Vector2d>IMemoryPackFormatterRegister
- Inherited Members
- Extension Methods
Remarks
The Vector2d struct is designed for applications that require precise numerical operations, such as games, simulations, or physics engines. It provides methods for common vector operations like addition, subtraction, dot product, cross product, distance calculations, and rotation.
FixedMathSharp treats Vector2d as plane math: +X is right and
+Y is the named Forward direction. Polar angle helpers are separate:
ForwardDirection(Fixed64) returns +X at angle zero.
Use Cases:
- Modeling 2D positions, directions, and velocities in fixed-point math environments.
- Performing vector transformations, including rotations and reflections.
- Handling interpolation and distance calculations in physics or simulation systems.
- Useful for fixed-point math scenarios where floating-point precision is insufficient or not desired.
Constructors
Vector2d(Fixed64, Fixed64)
Initializes a new instance of the Vector2d structure with the specified X and Y components.
[JsonConstructor]
public Vector2d(Fixed64 x, Fixed64 y)
Parameters
xFixed64The value to assign to the X component of the vector.
yFixed64The value to assign to the Y component of the vector.
Vector2d(int, int)
Initializes a new instance of the Vector2d structure using integer values for the X and Y components.
public Vector2d(int xInt, int yInt)
Parameters
xIntintThe X component of the vector, specified as an integer.
yIntintThe Y component of the vector, specified as an integer.
Fields
X
The X component of the vector.
[JsonInclude]
[MemoryPackOrder(0)]
public Fixed64 X
Field Value
Y
The Y component of the vector.
[JsonInclude]
[MemoryPackOrder(1)]
public Fixed64 Y
Field Value
Properties
Backward
(0, -1)
public static Vector2d Backward { get; }
Property Value
Forward
The named 2D plane forward direction (0, 1).
public static Vector2d Forward { get; }
Property Value
Remarks
This is distinct from polar angle math: ForwardDirection(Fixed64) returns Right when its angle argument is zero.
this[int]
Gets or sets the vector component at the specified index.
[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 this[int index] { get; set; }
Parameters
indexintThe zero-based index of the component to access. Use 0 for the X component and 1 for the Y component.
Property Value
- Fixed64
The vector component at the specified index.
Remarks
This indexer provides array-like access to the vector's components. Index 0 corresponds to the X component, and index 1 corresponds to the Y component.
Exceptions
- IndexOutOfRangeException
Thrown when the index is less than 0 or greater than 1.
Left
(-1, 0)
public static Vector2d Left { get; }
Property Value
LeftHandNormal
Gets the left-hand (clockwise) normal vector.
[JsonIgnore]
[MemoryPackIgnore]
public Vector2d LeftHandNormal { get; }
Property Value
LongStateHash
Returns a long hash of the vector based on its x and y values.
[JsonIgnore]
[MemoryPackIgnore]
public long LongStateHash { get; }
Property Value
Magnitude
Returns the actual length of this vector (RO).
[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 Magnitude { get; }
Property Value
MagnitudeSquared
Returns the square magnitude of the vector (avoids calculating the square root).
[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 MagnitudeSquared { get; }
Property Value
Negative
(-1, -1)
public static Vector2d Negative { get; }
Property Value
Normalized
Normalizes the given vector, returning a unit vector with the same direction.
[JsonIgnore]
[MemoryPackIgnore]
public Vector2d Normalized { get; }
Property Value
- Vector2d
A normalized (unit) vector with the same direction.
One
(1, 1)
public static Vector2d One { get; }
Property Value
Right
The named 2D plane right direction (1, 0).
public static Vector2d Right { get; }
Property Value
RightHandNormal
Gets the right-hand (counter-clockwise) normal vector.
[JsonIgnore]
[MemoryPackIgnore]
public Vector2d RightHandNormal { get; }
Property Value
RotatedLeft
Rotates the vector to the left (90 degrees counterclockwise).
[JsonIgnore]
[MemoryPackIgnore]
public Vector2d RotatedLeft { get; }
Property Value
RotatedRight
Rotates the vector to the right (90 degrees clockwise).
[JsonIgnore]
[MemoryPackIgnore]
public Vector2d RotatedRight { get; }
Property Value
StateHash
Returns a hash of the vector based on its state.
[JsonIgnore]
[MemoryPackIgnore]
public int StateHash { get; }
Property Value
Zero
(0, 0)
public static Vector2d Zero { get; }
Property Value
Methods
Abs(Vector2d)
Returns a new Vector2d where each component is the absolute value of the corresponding input component.
public static Vector2d Abs(Vector2d value)
Parameters
valueVector2dThe input vector.
Returns
- Vector2d
A vector with absolute values for each component.
Add(Vector2d, Vector2d)
Adds two vectors component-wise.
public static Vector2d Add(Vector2d v1, Vector2d v2)
Parameters
Returns
AddInPlace(Fixed64)
Adds the specified values to the components of the vector in place and returns the modified vector.
public Vector2d AddInPlace(Fixed64 amount)
Parameters
amountFixed64The amount to add to the components.
Returns
- Vector2d
The modified vector after addition.
AddInPlace(Fixed64, Fixed64)
Adds the specified values to the components of the vector in place and returns the modified vector.
public Vector2d AddInPlace(Fixed64 xAmount, Fixed64 yAmount)
Parameters
xAmountFixed64The amount to add to the x component.
yAmountFixed64The amount to add to the y component.
Returns
AddInPlace(Vector2d)
Adds the specified values to the components of the vector in place and returns the modified vector.
public Vector2d AddInPlace(Vector2d other)
Parameters
otherVector2d
Returns
AllComponentsGreaterThanEpsilon()
Checks whether all components are strictly greater than Epsilon.
public bool AllComponentsGreaterThanEpsilon()
Returns
BarycentricCoordinates(Vector2d, Vector2d, Vector2d, Fixed64, Fixed64)
Calculates a position between three points using barycentric weights for the second and third vertices.
public static Vector2d BarycentricCoordinates(Vector2d coordA, Vector2d coordB, Vector2d coordC, Fixed64 weightB, Fixed64 weightC)
Parameters
coordAVector2dThe first vertex of the triangle.
coordBVector2dThe second vertex of the triangle.
coordCVector2dThe third vertex of the triangle.
weightBFixed64The barycentric weight for the second vertex.
weightCFixed64The barycentric weight for the third vertex.
Returns
- Vector2d
The cartesian translation represented by the barycentric coordinates within the triangle.
Clamp(Vector2d, Vector2d, Vector2d)
Clamps each component of the given vector within the specified min and max bounds.
public static Vector2d Clamp(Vector2d value, Vector2d min, Vector2d max)
Parameters
Returns
ClosestPointOnLineSegment(Vector2d, Vector2d, Vector2d)
Calculates the closest point on a finite line segment to a given point.
public static Vector2d ClosestPointOnLineSegment(Vector2d point, Vector2d start, Vector2d end)
Parameters
pointVector2dThe point to project onto the segment.
startVector2dThe start of the line segment.
endVector2dThe end of the line segment.
Returns
- Vector2d
The closest point on the segment to the given point.
Remarks
Zero-length segments deterministically return start.
CompareDistanceSquared(Vector2d, Vector2d, Vector2d, Vector2d)
Compares the exact squared distances between two pairs of points without fixed-point saturation.
public static int CompareDistanceSquared(Vector2d leftStart, Vector2d leftEnd, Vector2d rightStart, Vector2d rightEnd)
Parameters
Returns
- int
A negative value when the left distance is shorter, zero when the distances are equal, or a positive value when the left distance is longer.
CompareMagnitudeSquared(Vector2d, Vector2d)
Compares the exact squared magnitudes of two vectors without fixed-point saturation.
public static int CompareMagnitudeSquared(Vector2d left, Vector2d right)
Parameters
Returns
- int
A negative value when
leftis shorter, zero when the magnitudes are equal, or a positive value whenleftis longer.
CompareProjection(Vector2d, Vector2d, Vector2d)
Compares the exact component-difference projections of two vectors.
public static int CompareProjection(Vector2d candidate, Vector2d current, Vector2d direction)
Parameters
candidateVector2dThe candidate point.
currentVector2dThe point to compare against.
directionVector2dThe projection direction; it need not be normalized.
Returns
- int
A negative value, zero, or a positive value when the candidate projection is respectively less than, equal to, or greater than the current projection.
CompareTo(Vector2d)
Compares the current Vector2d instance with another Vector2d based on their squared magnitudes.
public int CompareTo(Vector2d other)
Parameters
otherVector2dThe Vector2d instance to compare with the current instance.
Returns
- int
A value less than zero if this instance is less than
other; zero if this instance is equal toother; or a value greater than zero if this instance is greater thanother, as determined by their squared magnitudes.
Remarks
This comparison uses the squared magnitude of each vector, which avoids the computational cost of calculating the actual magnitude. Use this method when only relative vector lengths are important.
CreateRotation(Fixed64)
Creates a vector from a given angle in radians.
public static Vector2d CreateRotation(Fixed64 angle)
Parameters
angleFixed64
Returns
CrossProduct(Fixed64, Fixed64)
Computes the cross product magnitude of this vector with another vector.
public Fixed64 CrossProduct(Fixed64 otherX, Fixed64 otherY)
Parameters
otherXFixed64The X component of the other vector.
otherYFixed64The Y component of the other vector.
Returns
- Fixed64
The cross product magnitude.
CrossProduct(Vector2d)
Computes the cross product magnitude of this vector with another vector.
public Fixed64 CrossProduct(Vector2d other)
Parameters
otherVector2d
Returns
- Fixed64
The cross product magnitude.
CrossProduct(Vector2d, Vector2d)
Cross Product of two vectors.
public static Fixed64 CrossProduct(Vector2d lhs, Vector2d rhs)
Parameters
Returns
Deconstruct(out Fixed64, out Fixed64)
Deconstructs the Vector2d into its two Fixed64 components.
public void Deconstruct(out Fixed64 x, out Fixed64 y)
Parameters
Deconstruct(out double, out double)
Deconstructs the Vector2d into its two double components.
public void Deconstruct(out double x, out double y)
Parameters
Deconstruct(out int, out int)
Deconstructs the Vector2d into its two int components.
public void Deconstruct(out int x, out int y)
Parameters
Deconstruct(out long, out long)
Deconstructs the Vector2d into its two long components.
public void Deconstruct(out long x, out long y)
Parameters
Distance(Fixed64, Fixed64)
Returns the distance between this vector and another vector specified by its components.
public Fixed64 Distance(Fixed64 otherX, Fixed64 otherY)
Parameters
Returns
Distance(Vector2d)
Returns the distance between this vector and another vector.
public Fixed64 Distance(Vector2d other)
Parameters
otherVector2d
Returns
Distance(Vector2d, Vector2d)
Computes the distance between two vectors using the Euclidean distance formula.
public static Fixed64 Distance(Vector2d start, Vector2d end)
Parameters
Returns
- Fixed64
The Euclidean distance between the two vectors.
DistanceSquared(Fixed64, Fixed64)
Calculates the squared distance between two vectors, avoiding the need for a square root operation.
public Fixed64 DistanceSquared(Fixed64 otherX, Fixed64 otherY)
Parameters
Returns
- Fixed64
The squared distance between the two vectors.
DistanceSquared(Vector2d)
Calculates the squared distance between two vectors, avoiding the need for a square root operation.
public Fixed64 DistanceSquared(Vector2d other)
Parameters
otherVector2d
Returns
- Fixed64
The squared distance between the two vectors.
DistanceSquared(Vector2d, Vector2d)
Calculates the squared distance between two vectors, avoiding the need for a square root operation.
public static Fixed64 DistanceSquared(Vector2d start, Vector2d end)
Parameters
Returns
- Fixed64
The squared distance between the two vectors.
Divide(Vector2d, Fixed64)
Divides each vector component by the specified scalar.
public static Vector2d Divide(Vector2d value, Fixed64 divisor)
Parameters
Returns
Divide(Vector2d, Vector2d)
Divides each component of the first vector by the corresponding component of the second vector.
public static Vector2d Divide(Vector2d v1, Vector2d v2)
Parameters
Returns
DivideInPlace(Fixed64)
Divides each component of the vector by the specified scalar divisor in place and returns the modified vector.
public Vector2d DivideInPlace(Fixed64 divisor)
Parameters
divisorFixed64
Returns
DivideInPlace(Fixed64, Fixed64)
Divides the components of the vector by the specified x and y divisors in place and returns the modified vector.
public Vector2d DivideInPlace(Fixed64 divisorX, Fixed64 divisorY)
Parameters
Returns
DivideInPlace(Vector2d)
Divides each component of the vector by the corresponding component of the given vector in place and returns the modified vector.
public Vector2d DivideInPlace(Vector2d divisor)
Parameters
divisorVector2d
Returns
Dot(Fixed64, Fixed64)
Returns the dot product of this vector with another vector.
public Fixed64 Dot(Fixed64 otherX, Fixed64 otherY)
Parameters
Returns
Dot(Vector2d)
Returns the dot product of this vector with another vector.
public Fixed64 Dot(Vector2d other)
Parameters
otherVector2d
Returns
Dot(Vector2d, Vector2d)
Dot Product of two vectors.
public static Fixed64 Dot(Vector2d lhs, Vector2d rhs)
Parameters
Returns
Equals(Vector2d)
public bool Equals(Vector2d other)
Parameters
otherVector2d
Returns
Equals(Vector2d, Vector2d)
public bool Equals(Vector2d x, Vector2d y)
Parameters
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
EqualsZero()
Are all components of this vector equal to zero?
public bool EqualsZero()
Returns
ForwardDirection(Fixed64)
Calculates the forward direction vector in 2D based on a yaw (angle).
public static Vector2d ForwardDirection(Fixed64 angle)
Parameters
angleFixed64The angle in radians representing the rotation in 2D space.
Returns
- Vector2d
A unit vector representing the forward direction.
Remarks
This is a polar-angle helper: angle zero points along Right.
It intentionally differs from the named Forward plane constant,
which is +Y.
FromDouble(double, double)
Initializes a new instance of the Vector2d structure using double-precision floating-point values for the X and Y components.
public static Vector2d FromDouble(double xDoub, double yDoub)
Parameters
Returns
Remarks
Components are converted through FromDouble(double), so non-finite values throw ArgumentOutOfRangeException and finite values outside the Q32.32 range throw OverflowException.
GetAverage(ReadOnlySpan<Vector2d>)
Calculates the arithmetic mean with one final round-half-to-even conversion per component.
public static Vector2d GetAverage(ReadOnlySpan<Vector2d> values)
Parameters
valuesReadOnlySpan<Vector2d>The non-empty sequence of vectors to average.
Returns
- Vector2d
The arithmetic mean of
values.
Exceptions
- ArgumentException
valuesis empty.
GetDirection(Vector2d, Vector2d)
Returns the normalized direction from start toward
end across the complete coordinate domain.
public static Vector2d GetDirection(Vector2d start, Vector2d end)
Parameters
Returns
Remarks
Equal endpoints return Zero. Endpoint differences are evaluated exactly even when a component cannot be represented by Fixed64.
GetHashCode()
Returns a hash code for this instance, which is based on the combined hash codes of the X and Y components.
public override int GetHashCode()
Returns
GetHashCode(Vector2d)
public int GetHashCode(Vector2d obj)
Parameters
objVector2d
Returns
GetMagnitude(Vector2d)
Returns the magnitude (length) of the given vector.
public static Fixed64 GetMagnitude(Vector2d vector)
Parameters
vectorVector2dThe vector to compute the magnitude of.
Returns
- Fixed64
The magnitude (length) of the vector.
GetNormalized(Vector2d)
Normalizes the given vector, returning a unit vector with the same direction.
public static Vector2d GetNormalized(Vector2d value)
Parameters
valueVector2dThe vector to normalize.
Returns
- Vector2d
A normalized (unit) vector with the same direction.
IsNormalized()
Checks whether this nonzero vector's squared magnitude is within epsilon of one.
public readonly bool IsNormalized()
Returns
Lerp(Vector2d, Fixed64)
Returns a new vector that is the result of linear interpolation toward the target by the specified amount.
public Vector2d Lerp(Vector2d target, Fixed64 amount)
Parameters
Returns
Lerp(Vector2d, Vector2d, Fixed64)
Linearly interpolates between two vectors.
public static Vector2d Lerp(Vector2d a, Vector2d b, Fixed64 amount)
Parameters
Returns
LerpInPlace(Fixed64, Fixed64, Fixed64)
Linearly interpolates this vector toward the target values by the specified amount.
public Vector2d LerpInPlace(Fixed64 targetx, Fixed64 targety, Fixed64 amount)
Parameters
Returns
LerpInPlace(Vector2d, Fixed64)
Linearly interpolates this vector toward the target vector by the specified amount.
public Vector2d LerpInPlace(Vector2d target, Fixed64 amount)
Parameters
Returns
Multiply(Vector2d, Fixed64)
Multiplies each vector component by the specified scalar.
public static Vector2d Multiply(Vector2d value, Fixed64 factor)
Parameters
Returns
Multiply(Vector2d, Vector2d)
Multiplies two vectors component-wise.
public static Vector2d Multiply(Vector2d v1, Vector2d v2)
Parameters
Returns
MultiplyInPlace(Fixed64)
Multiplies the components of the vector by the specified scalar factor in place and returns the modified vector.
public Vector2d MultiplyInPlace(Fixed64 factor)
Parameters
factorFixed64The scalar factor to multiply each component by.
Returns
MultiplyInPlace(Fixed64, Fixed64)
Multiplies the components of the vector by the specified x and y factors in place and returns the modified vector.
public Vector2d MultiplyInPlace(Fixed64 factorX, Fixed64 factorY)
Parameters
factorXFixed64The factor to multiply the x component by.
factorYFixed64The factor to multiply the y component by.
Returns
- Vector2d
The modified vector after multiplication.
MultiplyInPlace(Vector2d)
Multiplies each component of the vector by the corresponding component of the given vector in place and returns the modified vector.
public Vector2d MultiplyInPlace(Vector2d factor)
Parameters
factorVector2dThe vector containing the multiplication factors for each component.
Returns
NormalizeInPlace()
Normalizes this vector in place, making its magnitude (length) equal to 1, and returns the modified vector.
public Vector2d NormalizeInPlace()
Returns
- Vector2d
The normalized vector.
Remarks
If the vector is zero-length or already normalized, no operation is performed. This method modifies the current vector in place and supports method chaining.
NormalizeInPlace(out Fixed64)
Normalizes this vector in place and outputs its original magnitude.
public Vector2d NormalizeInPlace(out Fixed64 mag)
Parameters
magFixed64The original magnitude of the vector before normalization.
Returns
Remarks
If the vector is zero-length or already normalized, no operation is performed, but the original magnitude will still be output.
NotZero()
Determines whether the current value is not equal to zero.
public bool NotZero()
Returns
- bool
true if the value is not zero; otherwise, false.
OrientationSign(Vector2d, Vector2d, Vector2d)
Returns the exact orientation sign of the ordered points without fixed-point saturation.
public static int OrientationSign(Vector2d origin, Vector2d first, Vector2d second)
Parameters
Returns
- int
1for a counter-clockwise turn,-1for a clockwise turn, or0when the points are exactly collinear.
ReflectInPlace(Fixed64, Fixed64)
Reflects this vector across the specified x and y axis.
public Vector2d ReflectInPlace(Fixed64 axisX, Fixed64 axisY)
Parameters
Returns
ReflectInPlace(Fixed64, Fixed64, Fixed64)
Reflects this vector across the specified axis using the provided projection of this vector onto the axis.
public Vector2d ReflectInPlace(Fixed64 axisX, Fixed64 axisY, Fixed64 projection)
Parameters
axisXFixed64The x component of the axis to reflect across.
axisYFixed64The y component of the axis to reflect across.
projectionFixed64The precomputed projection of this vector onto the reflection axis.
Returns
ReflectInPlace(Vector2d)
Reflects this vector across the specified axis vector.
public Vector2d ReflectInPlace(Vector2d axis)
Parameters
axisVector2d
Returns
Reflected(Fixed64, Fixed64)
Reflects this vector across the specified x and y axis.
public Vector2d Reflected(Fixed64 axisX, Fixed64 axisY)
Parameters
Returns
- Vector2d
A new vector representing the result of the reflection.
Reflected(Vector2d)
Reflects this vector across the specified axis vector.
public Vector2d Reflected(Vector2d axis)
Parameters
axisVector2d
Returns
- Vector2d
A new vector representing the result of the reflection.
Rotate(Vector2d, Fixed64)
Rotates this vector by the specified angle (in radians).
public static Vector2d Rotate(Vector2d vec, Fixed64 angleInRadians)
Parameters
Returns
- Vector2d
The rotated vector.
RotateInPlace(Fixed64, Fixed64)
Rotates this vector by the specified cosine and sine values (counter-clockwise).
public Vector2d RotateInPlace(Fixed64 cos, Fixed64 sin)
Parameters
Returns
RotateInverse(Fixed64, Fixed64)
Rotates this vector in the inverse direction using cosine and sine values.
public void RotateInverse(Fixed64 cos, Fixed64 sin)
Parameters
RotateLeftInPlace()
Rotates this vector 90 degrees to the left (counterclockwise).
public Vector2d RotateLeftInPlace()
Returns
RotateRightInPlace()
Rotates this vector 90 degrees to the right (clockwise).
public Vector2d RotateRightInPlace()
Returns
Rotated(Fixed64, Fixed64)
Returns a new vector that is the result of rotating this vector by the specified cosine and sine values.
public Vector2d Rotated(Fixed64 cos, Fixed64 sin)
Parameters
Returns
Rotated(Vector2d)
Rotates this vector using another vector representing the cosine and sine of the rotation angle.
public Vector2d Rotated(Vector2d rotation)
Parameters
rotationVector2dThe vector containing the cosine and sine values for rotation.
Returns
- Vector2d
A new vector representing the result of the rotation.
Set(Fixed64, Fixed64)
Set x, y and z components of an existing Vector3.
public void Set(Fixed64 newX, Fixed64 newY)
Parameters
Sign(Vector2d)
Returns a new Vector2d where each component is the sign of the corresponding input component.
public static Vector2d Sign(Vector2d value)
Parameters
valueVector2dThe input vector.
Returns
- Vector2d
A vector where each component is -1, 0, or 1 based on the sign of the input.
Subtract(Vector2d, Vector2d)
Subtracts two vectors component-wise.
public static Vector2d Subtract(Vector2d v1, Vector2d v2)
Parameters
Returns
SubtractInPlace(Fixed64)
Subtracts the specified value from all components of the vector in place and returns the modified vector.
public Vector2d SubtractInPlace(Fixed64 amount)
Parameters
amountFixed64The amount to subtract from each component.
Returns
SubtractInPlace(Fixed64, Fixed64)
Subtracts the specified values from the components of the vector in place and returns the modified vector.
public Vector2d SubtractInPlace(Fixed64 xAmount, Fixed64 yAmount)
Parameters
xAmountFixed64The amount to subtract from the x component.
yAmountFixed64The amount to subtract from the y component.
Returns
SubtractInPlace(Vector2d)
Subtracts the specified vector from the components of the vector in place and returns the modified vector.
public Vector2d SubtractInPlace(Vector2d other)
Parameters
otherVector2d
Returns
ToDegrees(Vector2d)
Converts each component of the vector from radians to degrees.
public static Vector2d ToDegrees(Vector2d radians)
Parameters
radiansVector2dThe vector with components in radians.
Returns
- Vector2d
A new vector with components converted to degrees.
ToRadians(Vector2d)
Converts each component of the vector from degrees to radians.
public static Vector2d ToRadians(Vector2d degrees)
Parameters
degreesVector2dThe vector with components in degrees.
Returns
- Vector2d
A new vector with components converted to radians.
ToString()
Returns a string representation of this vector.
public override readonly string ToString()
Returns
ToString(string?, IFormatProvider?)
Returns a string representation of this vector.
public readonly string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringformatProviderIFormatProvider
Returns
ToVector3d(Fixed64)
Converts this Vector2d to a Vector3d, mapping the Y component of this vector to the Z axis in the resulting vector.
public Vector3d ToVector3d(Fixed64 z)
Parameters
Returns
- Vector3d
A new Vector3d where (X, Y) from this Vector2d become (X, Z) in the resulting vector, with the provided Z parameter assigned to Y.
ToVector4d(Fixed64, Fixed64)
public Vector4d ToVector4d(Fixed64 z, Fixed64 w)
Parameters
Returns
TryAdd(Vector2d, Vector2d, out Vector2d)
Attempts to add two vectors without component saturation.
public static bool TryAdd(Vector2d left, Vector2d right, out Vector2d result)
Parameters
leftVector2dThe left operand.
rightVector2dThe right operand.
resultVector2dThe exact component-wise sum when every component is representable; otherwise, default.
Returns
TryAddSubtract(Vector2d, Vector2d, Vector2d, out Vector2d)
Attempts to add two vectors and subtract a third component-wise without intermediate saturation.
public static bool TryAddSubtract(Vector2d firstAddend, Vector2d secondAddend, Vector2d subtrahend, out Vector2d result)
Parameters
firstAddendVector2dThe first addend.
secondAddendVector2dThe second addend.
subtrahendVector2dThe vector to subtract from the exact component-wise sum.
resultVector2dThe exact component-wise result when every component is representable; otherwise, default.
Returns
TryComposeScaledLocalPoints(Vector2d, Vector2d, Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)
Attempts to compose two component-scaled offsets in a shared frame and one rotated inner-frame displacement with one final round-half-to-even conversion per component.
public static bool TryComposeScaledLocalPoints(Vector2d outerLocalPoint, Vector2d outerScale, Vector2d innerFrameOffset, Vector2d innerFrameScale, Vector2d innerLocalDisplacement, Fixed64 innerAngleInRadians, out Vector2d result)
Parameters
outerLocalPointVector2douterScaleVector2dinnerFrameOffsetVector2dinnerFrameScaleVector2dinnerLocalDisplacementVector2dinnerAngleInRadiansFixed64resultVector2d
Returns
Remarks
Computes
outerScale * outerLocalPoint
- innerFrameScale * innerFrameOffset
- Rotate(innerLocalDisplacement) without narrowing either scaled offset or the rotated displacement independently.
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Formats this vector into the provided destination buffer.
public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
destinationSpan<char>charsWrittenintformatReadOnlySpan<char>providerIFormatProvider
Returns
TryGetDistance(Vector2d, Vector2d, out Fixed64)
Attempts to return the distance between two endpoints without saturating either component difference.
public static bool TryGetDistance(Vector2d start, Vector2d end, out Fixed64 distance)
Parameters
startVector2dThe first endpoint.
endVector2dThe second endpoint.
distanceFixed64The rounded distance, or MaxValue when it is not representable.
Returns
TryGetMagnitude(Vector2d, out Fixed64)
Attempts to return the magnitude of the given vector without saturating the result.
public static bool TryGetMagnitude(Vector2d vector, out Fixed64 magnitude)
Parameters
vectorVector2dThe vector to measure.
magnitudeFixed64The magnitude, or MaxValue when it is not representable.
Returns
TryGetMagnitudeCeiling(out Fixed64)
Attempts to return this vector's magnitude rounded outward to the smallest containing Q32.32 value.
public readonly bool TryGetMagnitudeCeiling(out Fixed64 magnitude)
Parameters
magnitudeFixed64
Returns
TryGetRelativeOffset(Vector2d, Vector2d, Fixed64, Vector2d, Vector2d, Fixed64, out Vector2d)
Attempts to obtain the exact relative offset between two transformed local points.
public static bool TryGetRelativeOffset(Vector2d firstOrigin, Vector2d firstLocalPoint, Fixed64 firstAngleInRadians, Vector2d secondOrigin, Vector2d secondLocalPoint, Fixed64 secondAngleInRadians, out Vector2d result)
Parameters
firstOriginVector2dfirstLocalPointVector2dfirstAngleInRadiansFixed64secondOriginVector2dsecondLocalPointVector2dsecondAngleInRadiansFixed64resultVector2d
Returns
Remarks
The computed relation is
firstOrigin + Rotate(firstLocalPoint, firstAngleInRadians)
- secondOrigin - Rotate(secondLocalPoint, secondAngleInRadians). Neither rotated point nor any intermediate sum is narrowed independently.
TryGetRelativeOffset(Vector2d, Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)
Attempts to obtain the exact relative offset
firstOrigin + firstOffset - secondOrigin - Rotate(secondLocalPoint).
public static bool TryGetRelativeOffset(Vector2d firstOrigin, Vector2d firstOffset, Vector2d secondOrigin, Vector2d secondLocalPoint, Fixed64 angleInRadians, out Vector2d result)
Parameters
firstOriginVector2dfirstOffsetVector2dsecondOriginVector2dsecondLocalPointVector2dangleInRadiansFixed64resultVector2d
Returns
Remarks
No rotated point or intermediate sum is narrowed independently.
TryGetWeightedAverage(ReadOnlySpan<Vector2d>, ReadOnlySpan<Fixed64>, out Vector2d)
Attempts to calculate the exact non-negative weighted average with one final round-half-to-even conversion per component.
public static bool TryGetWeightedAverage(ReadOnlySpan<Vector2d> values, ReadOnlySpan<Fixed64> weights, out Vector2d average)
Parameters
valuesReadOnlySpan<Vector2d>weightsReadOnlySpan<Fixed64>averageVector2d
Returns
Remarks
Zero-weight values are ignored. The operation returns false only when the total weight is zero.
TryInverseTransformScaledPoint(Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)
Attempts to transform a world point into a component-scaled local frame with one final round-half-to-even conversion per component.
public static bool TryInverseTransformScaledPoint(Vector2d origin, Vector2d worldPoint, Vector2d scale, Fixed64 angleInRadians, out Vector2d localPoint)
Parameters
Returns
Remarks
Computes InverseRotate(worldPoint - origin) / scale without
narrowing the world offset, rotated projection, or scale division
independently. A zero scale component or unrepresentable final
coordinate returns false and a zero result.
TryRotate(Vector2d, Fixed64, out Vector2d)
Attempts to rotate a vector by the specified angle with one final round-half-to-even conversion per component.
public static bool TryRotate(Vector2d vector, Fixed64 angleInRadians, out Vector2d result)
Parameters
Returns
TrySubtract(Vector2d, Vector2d, out Vector2d)
Attempts to subtract two vectors without component saturation.
public static bool TrySubtract(Vector2d left, Vector2d right, out Vector2d result)
Parameters
leftVector2dThe left operand.
rightVector2dThe right operand.
resultVector2dThe exact component-wise difference when every component is representable; otherwise, default.
Returns
TrySubtractSums(Vector2d, Vector2d, Vector2d, Vector2d, out Vector2d)
Attempts to compute (firstLeft + firstRight) -
(secondLeft + secondRight) component-wise without intermediate
saturation.
public static bool TrySubtractSums(Vector2d firstLeft, Vector2d firstRight, Vector2d secondLeft, Vector2d secondRight, out Vector2d result)
Parameters
Returns
TryTransformPoint(Vector2d, Vector2d, Fixed64, out Vector2d)
Attempts to transform a local point by a rotation and origin with one final round-half-to-even conversion per component.
public static bool TryTransformPoint(Vector2d origin, Vector2d localPoint, Fixed64 angleInRadians, out Vector2d result)
Parameters
Returns
- bool
true when both final world components are representable; otherwise, false and
resultis default.
TryTransformPoint(Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)
Attempts to transform a local point by a rotation and add two origins with one final round-half-to-even conversion per component.
public static bool TryTransformPoint(Vector2d firstOrigin, Vector2d secondOrigin, Vector2d localPoint, Fixed64 angleInRadians, out Vector2d result)
Parameters
firstOriginVector2dsecondOriginVector2dlocalPointVector2dangleInRadiansFixed64resultVector2d
Returns
- bool
true when both final world components are representable; otherwise, false and
resultis default.
TryTransformScaledPoint(Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)
Attempts to transform a component-scaled local point by a rotation and world origin with one final round-half-to-even conversion per component.
public static bool TryTransformScaledPoint(Vector2d origin, Vector2d localPoint, Vector2d scale, Fixed64 angleInRadians, out Vector2d result)
Parameters
Returns
TryTransformScaledPoint(Vector2d, Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)
Attempts to transform a component-scaled local point plus an unscaled local displacement by a rotation and world origin with one final round-half-to-even conversion per component.
public static bool TryTransformScaledPoint(Vector2d origin, Vector2d localPoint, Vector2d scale, Vector2d localDisplacement, Fixed64 angleInRadians, out Vector2d result)
Parameters
originVector2dlocalPointVector2dscaleVector2dlocalDisplacementVector2dangleInRadiansFixed64resultVector2d
Returns
Remarks
Computes
origin + Rotate(scale * localPoint + localDisplacement) without
narrowing the scaled point, local sum, or rotated offset independently.
Operators
operator +(Fixed64, Vector2d)
Adds a scalar value to each component of the specified vector and returns the resulting vector.
public static Vector2d operator +(Fixed64 mag, Vector2d v1)
Parameters
magFixed64The scalar value to add to each component of the vector.
v1Vector2dThe vector to which the scalar value will be added.
Returns
- Vector2d
A new Vector2d whose components are the sum of the corresponding components of the input vector and the scalar value.
operator +(Vector2d, Fixed64)
Adds a scalar value to each component of the specified vector and returns the resulting vector.
public static Vector2d operator +(Vector2d v1, Fixed64 mag)
Parameters
v1Vector2dThe vector to which the scalar value will be added.
magFixed64The scalar value to add to each component of the vector.
Returns
- Vector2d
A new Vector2d whose components are the sum of the corresponding components of the input vector and the scalar value.
operator +(Vector2d, Vector2d)
Adds two Vector2d instances component-wise.
public static Vector2d operator +(Vector2d v1, Vector2d v2)
Parameters
Returns
- Vector2d
A new Vector2d whose components are the sums of the corresponding components of v1 and v2.
operator +(Vector2d, (int x, int y))
Adds a Vector2d instance and a tuple representing X and Y components, returning a new Vector2d with the summed values.
public static Vector2d operator +(Vector2d v1, (int x, int y) v2)
Parameters
v1Vector2dThe first vector to add.
v2(int x, int y)A tuple containing the X and Y values to add to the vector.
Returns
- Vector2d
A new Vector2d whose X and Y components are the sums of the corresponding components of the input vector and tuple.
operator +((int x, int y), Vector2d)
Adds a tuple representing X and Y components and a Vector2d instance, returning a new Vector2d with the summed values.
public static Vector2d operator +((int x, int y) v2, Vector2d v1)
Parameters
v2(int x, int y)A tuple containing the X and Y values to add to the vector.
v1Vector2dThe vector to add.
Returns
- Vector2d
A new Vector2d whose X and Y components are the sums of the corresponding components of the tuple and input vector.
operator /(Vector2d, Fixed64)
Divides each component of a specified vector by a scalar value.
public static Vector2d operator /(Vector2d v1, Fixed64 div)
Parameters
v1Vector2dThe vector whose components are to be divided.
divFixed64The scalar value by which to divide each component of the vector.
Returns
- Vector2d
A new Vector2d whose components are the result of dividing the corresponding components of v1 by div.
operator ==(Vector2d, Vector2d)
Determines whether two Vector2d instances are equal.
public static bool operator ==(Vector2d left, Vector2d right)
Parameters
Returns
operator !=(Vector2d, Vector2d)
Determines whether two Vector2d instances are not equal.
public static bool operator !=(Vector2d left, Vector2d right)
Parameters
Returns
operator *(Fixed64, Vector2d)
Scales the specified vector by the given scalar value.
public static Vector2d operator *(Fixed64 mag, Vector2d v1)
Parameters
magFixed64The scalar value by which to multiply each component of the vector.
v1Vector2dThe vector to be scaled.
Returns
- Vector2d
A new Vector2d whose components are the components of v1 multiplied by mag.
operator *(Vector2d, Fixed64)
Scales the specified vector by the given scalar value.
public static Vector2d operator *(Vector2d v1, Fixed64 mag)
Parameters
v1Vector2dThe vector to be scaled.
magFixed64The scalar value by which to multiply each component of the vector.
Returns
- Vector2d
A new Vector2d whose components are the components of v1 multiplied by mag.
operator *(Vector2d, Vector2d)
Multiplies two vectors element-wise and returns the resulting vector.
public static Vector2d operator *(Vector2d v1, Vector2d v2)
Parameters
Returns
- Vector2d
A new Vector2d whose components are the products of the corresponding components of the input vectors.
Remarks
Element-wise multiplication multiplies each component of the first vector by the corresponding component of the second vector. This operation is not a dot product or cross product.
operator -(Fixed64, Vector2d)
Subtracts the specified scalar value from both components of the given vector and returns the resulting vector.
public static Vector2d operator -(Fixed64 mag, Vector2d v1)
Parameters
magFixed64The scalar value to subtract from each component of the vector.
v1Vector2dThe vector from which to subtract the scalar value.
Returns
- Vector2d
A new Vector2d whose components are the result of subtracting the scalar value from the corresponding components of the input vector.
operator -(Vector2d, Fixed64)
Subtracts the specified scalar value from both components of the given vector and returns the resulting vector.
public static Vector2d operator -(Vector2d v1, Fixed64 mag)
Parameters
v1Vector2dThe vector from which to subtract the scalar value.
magFixed64The scalar value to subtract from each component of the vector.
Returns
- Vector2d
A new Vector2d whose components are the result of subtracting the scalar value from the corresponding components of the input vector.
operator -(Vector2d, Vector2d)
Subtracts the components of one Vector2d from another and returns the resulting vector.
public static Vector2d operator -(Vector2d v1, Vector2d v2)
Parameters
Returns
- Vector2d
A Vector2d whose components are the result of subtracting the corresponding components of v2 from v1.
operator -(Vector2d, (int x, int y))
Subtracts the specified tuple from the given vector and returns the resulting vector.
public static Vector2d operator -(Vector2d v1, (int x, int y) v2)
Parameters
v1Vector2dThe vector from which to subtract the tuple values.
v2(int x, int y)A tuple containing the x and y values to subtract from the vector.
Returns
- Vector2d
A new Vector2d representing the result of subtracting the tuple values from the original vector.
operator -((int x, int y), Vector2d)
Subtracts the specified Vector2d from the given integer tuple and returns the resulting vector.
public static Vector2d operator -((int x, int y) v1, Vector2d v2)
Parameters
v1(int x, int y)A tuple containing the x and y components to subtract from.
v2Vector2dThe vector whose components are subtracted from the tuple.
Returns
- Vector2d
A Vector2d representing the result of subtracting the components of v2 from v1.
operator -(Vector2d)
Negates the specified vector by reversing the sign of each of its components.
public static Vector2d operator -(Vector2d v1)
Parameters
v1Vector2dThe vector to negate.
Returns
- Vector2d
A new Vector2d whose components are the negated values of the input vector.