Table of Contents

Struct Vector3

Namespace
Xui.Core.Math3D
Assembly
Xui.Core.dll

Represents a 3D vector with X, Y, and Z components. Commonly used for geometric operations, physics, lighting, and 3D movement.

public struct Vector3
Inherited Members

Remarks

The struct is laid out sequentially as three 32-bit floats (12 bytes), making it directly compatible with SIMD operations and GPU shader inputs. Use Vector3 for hardware-accelerated batch processing.

Constructors

Vector3(float, float, float)

Initializes a new Vector3 with the specified components.

public Vector3(float x, float y, float z)

Parameters

x float

The X component.

y float

The Y component.

z float

The Z component.

Fields

Back

A unit vector pointing backward along the positive Z axis (0, 0, 1).

public static readonly Vector3 Back

Field Value

Vector3

Down

A unit vector pointing down along the negative Y axis (0, -1, 0).

public static readonly Vector3 Down

Field Value

Vector3

Forward

A unit vector pointing forward along the negative Z axis (0, 0, -1) in a right-handed coordinate system.

public static readonly Vector3 Forward

Field Value

Vector3

Left

A unit vector pointing left along the negative X axis (-1, 0, 0).

public static readonly Vector3 Left

Field Value

Vector3

One

A unit vector (1, 1, 1).

public static readonly Vector3 One

Field Value

Vector3

Right

A unit vector pointing right along the positive X axis (1, 0, 0).

public static readonly Vector3 Right

Field Value

Vector3

Up

A unit vector pointing up along the positive Y axis (0, 1, 0).

public static readonly Vector3 Up

Field Value

Vector3

X

The X component of the vector.

public float X

Field Value

float

Y

The Y component of the vector.

public float Y

Field Value

float

Z

The Z component of the vector.

public float Z

Field Value

float

Zero

A zero vector (0, 0, 0).

public static readonly Vector3 Zero

Field Value

Vector3

Properties

Magnitude

Returns the magnitude (length) of the vector.

public float Magnitude { get; }

Property Value

float

MagnitudeSquared

Returns the squared magnitude of the vector, avoiding a square root computation. Useful for distance comparisons where the exact length is not needed.

public float MagnitudeSquared { get; }

Property Value

float

Normalized

Returns a normalized (unit length) copy of this vector. Returns Zero if the vector has zero magnitude.

public Vector3 Normalized { get; }

Property Value

Vector3

Methods

Angle(Vector3, Vector3)

Returns the angle in radians between two vectors. Returns 0 if either vector has zero magnitude.

public static float Angle(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3

The first vector.

rhs Vector3

The second vector.

Returns

float

Cross(Vector3, Vector3)

Returns the cross product of two vectors. The result is a vector perpendicular to both inputs, with direction determined by the right-hand rule.

public static Vector3 Cross(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3

The left-hand vector.

rhs Vector3

The right-hand vector.

Returns

Vector3

Dot(Vector3, Vector3)

Returns the dot product of two vectors.

public static float Dot(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3

The left-hand vector.

rhs Vector3

The right-hand vector.

Returns

float

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.

Equals(Vector3)

Returns true if this vector equals another Vector3.

public bool Equals(Vector3 other)

Parameters

other Vector3

Returns

bool

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(Vector3, Vector3, float)

Linearly interpolates between two vectors by the factor t.

public static Vector3 Lerp(Vector3 start, Vector3 end, float t)

Parameters

start Vector3

The start vector at t = 0.

end Vector3

The end vector at t = 1.

t float

The interpolation factor, typically in the range [0, 1].

Returns

Vector3

Max(Vector3, Vector3)

Returns the component-wise maximum of two vectors.

public static Vector3 Max(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3
rhs Vector3

Returns

Vector3

Min(Vector3, Vector3)

Returns the component-wise minimum of two vectors.

public static Vector3 Min(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3
rhs Vector3

Returns

Vector3

Project(Vector3, Vector3)

Projects lhs onto rhs. Returns Zero if rhs has zero magnitude.

public static Vector3 Project(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3

The vector to project.

rhs Vector3

The target direction vector.

Returns

Vector3

Reflect(Vector3, Vector3)

Reflects the vector across the given surface normal. The normal is assumed to be unit length.

public static Vector3 Reflect(Vector3 vector, Vector3 normal)

Parameters

vector Vector3

The incident vector to reflect.

normal Vector3

The surface normal (should be normalized).

Returns

Vector3

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Operators

operator +(Vector3, Vector3)

Adds two vectors.

public static Vector3 operator +(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3
rhs Vector3

Returns

Vector3

operator /(Vector3, float)

Divides a vector by a scalar.

public static Vector3 operator /(Vector3 v, float f)

Parameters

v Vector3
f float

Returns

Vector3

operator ==(Vector3, Vector3)

Returns true if two vectors have equal components.

public static bool operator ==(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3
rhs Vector3

Returns

bool

implicit operator Vector3(Vector3)

Implicitly converts a Vector3 to a Vector3.

public static implicit operator Vector3(Vector3 v)

Parameters

v Vector3

Returns

Vector3

implicit operator Vector3((float x, float y, float z))

Implicitly converts a tuple to a Vector3.

public static implicit operator Vector3((float x, float y, float z) t)

Parameters

t (float x, float y, float z)

Returns

Vector3

implicit operator Vector3(Point3)

Implicitly converts a Point3 to a Vector3.

public static implicit operator Vector3(Point3 p)

Parameters

p Point3

Returns

Vector3

implicit operator Vector3(Vector3)

Implicitly converts this vector to a Vector3 for use with SIMD-accelerated operations.

public static implicit operator Vector3(Vector3 v)

Parameters

v Vector3

Returns

Vector3

operator !=(Vector3, Vector3)

Returns true if any component of two vectors differs.

public static bool operator !=(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3
rhs Vector3

Returns

bool

operator *(float, Vector3)

Multiplies a scalar by a vector.

public static Vector3 operator *(float f, Vector3 v)

Parameters

f float
v Vector3

Returns

Vector3

operator *(Vector3, float)

Multiplies a vector by a scalar.

public static Vector3 operator *(Vector3 v, float f)

Parameters

v Vector3
f float

Returns

Vector3

operator *(Vector3, Vector3)

Multiplies two vectors component-wise.

public static Vector3 operator *(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3
rhs Vector3

Returns

Vector3

operator -(Vector3, Vector3)

Subtracts one vector from another.

public static Vector3 operator -(Vector3 lhs, Vector3 rhs)

Parameters

lhs Vector3
rhs Vector3

Returns

Vector3

operator -(Vector3)

Negates a vector.

public static Vector3 operator -(Vector3 v)

Parameters

v Vector3

Returns

Vector3