Skip to main content

UnityEngine::Vector3d

Represents a 3D vector with double-precision floating-point components.

Public Functions

Name
Vector3d(double x, double y, double z)
Initializes a new instance of the Vector3d struct with the given components.
Vector3d(float x, float y, float z)
Initializes a new instance of the Vector3d struct with the components converted from floats.
Vector3d(Vector3 v3)
Initializes a new instance of the Vector3d struct by converting a Vector3.
Vector3d(double x, double y)
Initializes a new instance of the Vector3d struct with the given x and y components. The z component is set to 0.
voidSet(double new_x, double new_y, double new_z)
Sets the components of the vector to new values.
voidScale(Vector3d scale)
Scales this vector by multiplying each component with the corresponding component of another vector.
voidSet(double new_x, double new_y)
Sets the components of the vector to new values.
override intGetHashCode()
Gets the hash code of the vector.
override boolEquals(object other)
Compares this vector to another object for equality.
boolEquals(Vector3d other)
Compares this vector to another Vector3d for equality.
override stringToString()
Returns a string representation of the vector.
voidNormalize()
Returns the normalized vector of this instance.
Vector3doperator+(Vector3d a, Vector3d b)
Adds two Vector3d instances and returns the result.
Vector3doperator-(Vector3d a, Vector3d b)
Subtracts one Vector3d instance from another and returns the result.
Vector3doperator-(Vector3d a)
Negates a Vector3d instance (reverses its direction).
Vector3doperator*(Vector3d a, double d)
Multiplies a Vector3d by a scalar (double) value.
Vector3doperator*(double d, Vector3d a)
Multiplies a scalar (double) value by a Vector3d.
Vector3doperator/(Vector3d a, double d)
Divides a Vector3d by a scalar (double) value.
booloperator==(Vector3d lhs, Vector3d rhs)
Checks if two Vector3d instances are approximately equal within a small epsilon value.
booloperator!=(Vector3d lhs, Vector3d rhs)
Checks if two Vector3d instances are not approximately equal within a small epsilon value.
staticoperator Vector3(Vector3d vector3d)
Converts a Vector3d to a Vector3 by casting its components to float.
Vector3dLerp(Vector3d from, Vector3d to, double t)
Linearly interpolates between two Vector3d instances.
Vector3dSlerp(Vector3d from, Vector3d to, double t)
Spherically interpolates between two Vector3d instances.
voidOrthoNormalize(ref Vector3d normal, ref Vector3d tangent)
Ortho-normalizes two vectors.
voidOrthoNormalize(ref Vector3d normal, ref Vector3d tangent, ref Vector3d binormal)
Ortho-normalizes three vectors.
Vector3dMoveTowards(Vector3d current, Vector3d target, double maxDistanceDelta)
Moves a vector towards a target vector by a specified maximum distance.
Vector3dRotateTowards(Vector3d current, Vector3d target, double maxRadiansDelta, double maxMagnitudeDelta)
Rotates a vector towards a target vector by a specified maximum angle and magnitude change.
Vector3dSmoothDamp(Vector3d current, Vector3d target, ref Vector3d currentVelocity, double smoothTime, double maxSpeed)
Applies smooth damping to move from the current vector towards the target vector.
Vector3dSmoothDamp(Vector3d current, Vector3d target, ref Vector3d currentVelocity, double smoothTime)
Applies smooth damping to move from the current vector towards the target vector.
Vector3dSmoothDamp(Vector3d current, Vector3d target, ref Vector3d currentVelocity, double smoothTime, double maxSpeed, double deltaTime)
Applies smooth damping to move from the current vector towards the target vector.
Vector3dScale(Vector3d a, Vector3d b)
Multiplies each component of this vector by the corresponding component of another vector.
Vector3dReflect(Vector3d inDirection, Vector3d inNormal)
Reflects the input direction off the plane defined by the normal.
doubleDot(Vector3d a, Vector3d b)
Calculates the dot product of two Vector3d instances.
Vector3dCross(Vector3d lhs, Vector3d rhs)
Calculates the cross product of two Vector3d instances.
Vector3dNormalize(Vector3d value)
Normalizes a vector.
Vector3dProject(Vector3d vector, Vector3d onNormal)
Projects a vector onto another vector.
Vector3dExclude(Vector3d excludeThis, Vector3d fromThat)
Removes a vector's projection onto another vector.
doubleAngle(Vector3d from, Vector3d to)
Calculates the angle between two vectors in degrees.
doubleDistance(Vector3d a, Vector3d b)
Calculates the Euclidean distance between two 3D vectors.
Vector3dClampMagnitude(Vector3d vector, double maxLength)
Clamps the magnitude of a vector to a specified maximum length.
doubleMagnitude(Vector3d a)
Calculates the magnitude (length) of a 3D vector.
doubleSqrMagnitude(Vector3d a)
Calculates the square of the magnitude (length) of a 3D vector.
Vector3dMin(Vector3d lhs, Vector3d rhs)
Returns a new vector where each component is the minimum value between the components of two input vectors.
Vector3dMax(Vector3d lhs, Vector3d rhs)
Returns a new vector where each component is the maximum value between the components of two input vectors.
doubleAngleBetween(Vector3d from, Vector3d to)
[Obsolete] Calculates the angle in degrees between two vectors. Use Angle instead.

Public Properties

Name
doublethis[int index]
Access the components of the vector using an index.
Vector3dnormalized
Gets a normalized copy of the vector.
doublemagnitude
Gets the magnitude (length) of the vector.
doublesqrMagnitude
Gets the squared magnitude of the vector.
Vector3dzero
Shorthand for writing Vector3d(0, 0, 0).
Vector3done
Shorthand for writing Vector3d(1, 1, 1).
Vector3dright
Shorthand for writing Vector3d(1, 0, 0).
Vector3dleft
Shorthand for writing Vector3d(-1, 0, 0).
Vector3dup
Shorthand for writing Vector3d(0, 1, 0).
Vector3ddown
Shorthand for writing Vector3d(0, -1, 0).
Vector3dforward
Shorthand for writing Vector3d(0, 0, 1).
Vector3dback
Shorthand for writing Vector3d(0, 0, -1).
Vector3dfwd
Shorthand for writing Vector3d(0, 0, 1).

Public Attributes

Name
const floatkEpsilon
A small value used for approximate equality checks.
doublex
The x component of the vector.
doubley
The y component of the vector.
doublez
The z component of the vector.

Public Functions Documentation

function Vector3d

Vector3d(
double x,
double y,
double z
)

Initializes a new instance of the Vector3d struct with the given components.

Parameters:

  • x The x-component of the vector.
  • y The y-component of the vector.
  • z The z-component of the vector.

function Vector3d

Vector3d(
float x,
float y,
float z
)

Initializes a new instance of the Vector3d struct with the components converted from floats.

Parameters:

  • x The x-component of the vector as a float.
  • y The y-component of the vector as a float.
  • z The z-component of the vector as a float.

function Vector3d

Vector3d(
Vector3 v3
)

Initializes a new instance of the Vector3d struct by converting a Vector3.

Parameters:

  • v3 A Vector3 to convert into a Vector3d.

function Vector3d

Vector3d(
double x,
double y
)

Initializes a new instance of the Vector3d struct with the given x and y components. The z component is set to 0.

Parameters:

  • x The x-component of the vector.
  • y The y-component of the vector.

function Set

void Set(
double new_x,
double new_y,
double new_z
)

Sets the components of the vector to new values.

Parameters:

  • new_x The new x-component.
  • new_y The new y-component.
  • new_z The new z-component.

function Scale

void Scale(
Vector3d scale
)

Scales this vector by multiplying each component with the corresponding component of another vector.

Parameters:

  • scale The vector by which to scale this vector.

function Set

void Set(
double new_x,
double new_y
)

Sets the components of the vector to new values.

Parameters:

  • new_x The new x-component.
  • new_y The new y-component.

function GetHashCode

override int GetHashCode()

Gets the hash code of the vector.

Return: The hash code of the vector.

function Equals

override bool Equals(
object other
)

Compares this vector to another object for equality.

Parameters:

  • other The object to compare to this vector.

Return: True if the other object is a Vector3d and has the same components as this vector, false otherwise.

function Equals

bool Equals(
Vector3d other
)

Compares this vector to another Vector3d for equality.

Parameters:

  • other The vector to compare to this vector.

Return: True if the other vector has the same components as this vector, false otherwise.

function ToString

override string ToString()

Returns a string representation of the vector.

Return: A string representation of the vector in the format "(x, y, z)".

function Normalize

void Normalize()

Returns the normalized vector of this instance.

function operator+

static Vector3d operator+(
Vector3d a,
Vector3d b
)

Adds two Vector3d instances and returns the result.

Parameters:

  • a The first vector to add.
  • b The second vector to add.

Return: The result of adding the two vectors.

function operator-

static Vector3d operator-(
Vector3d a,
Vector3d b
)

Subtracts one Vector3d instance from another and returns the result.

Parameters:

  • a The vector to subtract from.
  • b The vector to subtract.

Return: The result of subtracting the second vector from the first.

function operator-

static Vector3d operator-(
Vector3d a
)

Negates a Vector3d instance (reverses its direction).

Parameters:

  • a The vector to negate.

Return: The negated vector.

function operator*

static Vector3d operator*(
Vector3d a,
double d
)

Multiplies a Vector3d by a scalar (double) value.

Parameters:

  • a The vector to multiply.
  • d The scalar value to multiply by.

Return: The result of the multiplication.

function operator*

static Vector3d operator*(
double d,
Vector3d a
)

Multiplies a scalar (double) value by a Vector3d.

Parameters:

  • d The scalar value to multiply.
  • a The vector to multiply.

Return: The result of the multiplication.

function operator/

static Vector3d operator/(
Vector3d a,
double d
)

Divides a Vector3d by a scalar (double) value.

Parameters:

  • a The vector to divide.
  • d The scalar value to divide by.

Return: The result of the division.

function operator==

static bool operator==(
Vector3d lhs,
Vector3d rhs
)

Checks if two Vector3d instances are approximately equal within a small epsilon value.

Parameters:

  • lhs The first vector to compare.
  • rhs The second vector to compare.

Return: True if the two vectors are approximately equal, false otherwise.

function operator!=

static bool operator!=(
Vector3d lhs,
Vector3d rhs
)

Checks if two Vector3d instances are not approximately equal within a small epsilon value.

Parameters:

  • lhs The first vector to compare.
  • rhs The second vector to compare.

Return: True if the two vectors are not approximately equal, false otherwise.

function operator Vector3

static explicit static operator Vector3(
Vector3d vector3d
)

Converts a Vector3d to a Vector3 by casting its components to float.

Parameters:

Return: A new Vector3 with float components.

function Lerp

static Vector3d Lerp(
Vector3d from,
Vector3d to,
double t
)

Linearly interpolates between two Vector3d instances.

Parameters:

  • from The start vector.
  • to The end vector.
  • t The interpolation parameter (0 to 1).

Return: The interpolated vector.

function Slerp

static Vector3d Slerp(
Vector3d from,
Vector3d to,
double t
)

Spherically interpolates between two Vector3d instances.

Parameters:

  • from The start vector.
  • to The end vector.
  • t The interpolation parameter (0 to 1).

Return: The spherically interpolated vector.

function OrthoNormalize

static void OrthoNormalize(
ref Vector3d normal,
ref Vector3d tangent
)

Ortho-normalizes two vectors.

Parameters:

  • normal The first vector to ortho-normalize.
  • tangent The second vector to ortho-normalize.

function OrthoNormalize

static void OrthoNormalize(
ref Vector3d normal,
ref Vector3d tangent,
ref Vector3d binormal
)

Ortho-normalizes three vectors.

Parameters:

  • normal The first vector to ortho-normalize.
  • tangent The second vector to ortho-normalize.
  • binormal The third vector to ortho-normalize.

function MoveTowards

static Vector3d MoveTowards(
Vector3d current,
Vector3d target,
double maxDistanceDelta
)

Moves a vector towards a target vector by a specified maximum distance.

Parameters:

  • current The current vector.
  • target The target vector.
  • maxDistanceDelta The maximum distance to move towards the target.

Return: The resulting vector after moving towards the target.

function RotateTowards

static Vector3d RotateTowards(
Vector3d current,
Vector3d target,
double maxRadiansDelta,
double maxMagnitudeDelta
)

Rotates a vector towards a target vector by a specified maximum angle and magnitude change.

Parameters:

  • current The current vector.
  • target The target vector.
  • maxRadiansDelta The maximum angle (in radians) to rotate.
  • maxMagnitudeDelta The maximum change in magnitude.

Return: The resulting vector after rotation towards the target.

function SmoothDamp

static Vector3d SmoothDamp(
Vector3d current,
Vector3d target,
ref Vector3d currentVelocity,
double smoothTime,
double maxSpeed
)

Applies smooth damping to move from the current vector towards the target vector.

Parameters:

  • current The current vector.
  • target The target vector.
  • currentVelocity The current velocity of the vector.
  • smoothTime The time to reach the target.
  • maxSpeed The maximum speed of the vector.

Return: The resulting vector after applying smooth damping.

function SmoothDamp

static Vector3d SmoothDamp(
Vector3d current,
Vector3d target,
ref Vector3d currentVelocity,
double smoothTime
)

Applies smooth damping to move from the current vector towards the target vector.

Parameters:

  • current The current vector.
  • target The target vector.
  • currentVelocity The current velocity of the vector.
  • smoothTime The time to reach the target.

Return: The resulting vector after applying smooth damping.

function SmoothDamp

static Vector3d SmoothDamp(
Vector3d current,
Vector3d target,
ref Vector3d currentVelocity,
double smoothTime,
double maxSpeed,
double deltaTime
)

Applies smooth damping to move from the current vector towards the target vector.

Parameters:

  • current The current vector.
  • target The target vector.
  • currentVelocity The current velocity of the vector.
  • smoothTime The time to reach the target.
  • maxSpeed The maximum speed of the vector.
  • deltaTime The time interval between function calls.

Return: The resulting vector after applying smooth damping.

function Scale

static Vector3d Scale(
Vector3d a,
Vector3d b
)

Multiplies each component of this vector by the corresponding component of another vector.

Parameters:

  • a The first vector.
  • b The second vector.

Return: A new vector containing the component-wise product of the input vectors.

function Reflect

static Vector3d Reflect(
Vector3d inDirection,
Vector3d inNormal
)

Reflects the input direction off the plane defined by the normal.

Parameters:

  • inDirection The direction to reflect.
  • inNormal The normal to reflect off of.

Return: The reflected direction.

function Dot

static double Dot(
Vector3d a,
Vector3d b
)

Calculates the dot product of two Vector3d instances.

Parameters:

  • a The first vector.
  • b The second vector.

Return: The dot product of the two vectors.

function Cross

static Vector3d Cross(
Vector3d lhs,
Vector3d rhs
)

Calculates the cross product of two Vector3d instances.

Parameters:

  • lhs The first vector.
  • rhs The second vector.

Return: The cross product of the two vectors.

function Normalize

static Vector3d Normalize(
Vector3d value
)

Normalizes a vector.

Parameters:

  • value The vector to normalize.

Return: The normalized vector.

function Project

static Vector3d Project(
Vector3d vector,
Vector3d onNormal
)

Projects a vector onto another vector.

Parameters:

  • vector The vector to project.
  • onNormal The vector onto which to project.

Return: The projection of the vector onto the other vector.

function Exclude

static Vector3d Exclude(
Vector3d excludeThis,
Vector3d fromThat
)

Removes a vector's projection onto another vector.

Parameters:

  • excludeThis The vector to exclude from.
  • fromThat The vector to remove the projection from.

Return: The vector with the projection removed.

function Angle

static double Angle(
Vector3d from,
Vector3d to
)

Calculates the angle between two vectors in degrees.

Parameters:

  • from The first vector.
  • to The second vector.

Return: The angle between the two vectors in degrees.

function Distance

static double Distance(
Vector3d a,
Vector3d b
)

Calculates the Euclidean distance between two 3D vectors.

Parameters:

  • a The first vector.
  • b The second vector.

Return: The distance between the two vectors.

function ClampMagnitude

static Vector3d ClampMagnitude(
Vector3d vector,
double maxLength
)

Clamps the magnitude of a vector to a specified maximum length.

Parameters:

  • vector The vector to clamp.
  • maxLength The maximum length to which the vector will be clamped.

Return: If the magnitude of the input vector is greater than maxLength , it returns a vector with the same direction as the original but with a magnitude of maxLength . If the magnitude of the input vector is less than or equal to maxLength , it returns the original vector.

function Magnitude

static double Magnitude(
Vector3d a
)

Calculates the magnitude (length) of a 3D vector.

Parameters:

  • a The input vector.

Return: The magnitude of the vector.

function SqrMagnitude

static double SqrMagnitude(
Vector3d a
)

Calculates the square of the magnitude (length) of a 3D vector.

Parameters:

  • a The input vector.

Return: The square of the magnitude of the vector.

function Min

static Vector3d Min(
Vector3d lhs,
Vector3d rhs
)

Returns a new vector where each component is the minimum value between the components of two input vectors.

Parameters:

  • lhs The first vector.
  • rhs The second vector.

Return: The vector with components equal to the minimum values of the input vectors.

function Max

static Vector3d Max(
Vector3d lhs,
Vector3d rhs
)

Returns a new vector where each component is the maximum value between the components of two input vectors.

Parameters:

  • lhs The first vector.
  • rhs The second vector.

Return: The vector with components equal to the maximum values of the input vectors.

function AngleBetween

static double AngleBetween(
Vector3d from,
Vector3d to
)

[Obsolete] Calculates the angle in degrees between two vectors. Use Angle instead.

Parameters:

  • from The first vector.
  • to The second vector.

Return: The angle in degrees between the two vectors.

Public Property Documentation

property this[int index]

double this[int index];

Access the components of the vector using an index.

Parameters:

  • index The index (0 for x, 1 for y, 2 for z).

Return: The value of the component at the specified index.

property normalized

Vector3d normalized;

Gets a normalized copy of the vector.

property magnitude

double magnitude;

Gets the magnitude (length) of the vector.

property sqrMagnitude

double sqrMagnitude;

Gets the squared magnitude of the vector.

property zero

static Vector3d zero;

Shorthand for writing Vector3d(0, 0, 0).

property one

static Vector3d one;

Shorthand for writing Vector3d(1, 1, 1).

property right

static Vector3d right;

Shorthand for writing Vector3d(1, 0, 0).

property left

static Vector3d left;

Shorthand for writing Vector3d(-1, 0, 0).

property up

static Vector3d up;

Shorthand for writing Vector3d(0, 1, 0).

property down

static Vector3d down;

Shorthand for writing Vector3d(0, -1, 0).

property forward

static Vector3d forward;

Shorthand for writing Vector3d(0, 0, 1).

property back

static Vector3d back;

Shorthand for writing Vector3d(0, 0, -1).

property fwd

static Vector3d fwd;

Shorthand for writing Vector3d(0, 0, 1).

Public Attributes Documentation

variable kEpsilon

static const float kEpsilon = 1E-05f;

A small value used for approximate equality checks.

variable x

double x;

The x component of the vector.

variable y

double y;

The y component of the vector.

variable z

double z;

The z component of the vector.