Skip to main content

UnityEngine::Vector2d

A struct representing a 2D vector with double precision.

Public Functions

Name
Vector2d(double x, double y)
Creates a new Vector2d with the specified x and y components.
voidSet(double new_x, double new_y)
Sets the x and y components of this vector.
voidScale(Vector2d scale)
Scales this vector by another vector.
voidNormalize()
Normalizes this vector if it has a magnitude greater than a small epsilon value.
override stringToString()
Returns a string representation of the Vector2d.
stringToString(string format)
Returns a string representation of the Vector2d with custom format.
override intGetHashCode()
Returns a hash code for the Vector2d.
override boolEquals(object other)
Compares this Vector2d to another object for equality.
doubleSqrMagnitude()
Returns the squared magnitude of this vector.
implicitoperator Vector2d(Vector3d v)
Implicitly converts a Vector3d to a Vector2d, ignoring the z component.
implicitoperator Vector3d(Vector2d v)
Implicitly converts a Vector2d to a Vector3d, setting the z component to 0.
Vector2doperator+(Vector2d a, Vector2d b)
Adds two Vector2d vectors component-wise.
Vector2doperator-(Vector2d a, Vector2d b)
Subtracts the second Vector2d from the first vector component-wise.
Vector2doperator-(Vector2d a)
Negates a Vector2d, changing the sign of its components.
Vector2doperator*(Vector2d a, double d)
Multiplies a Vector2d by a scalar.
Vector2doperator*(double d, Vector2d a)
Multiplies a Vector2d by a scalar.
Vector2doperator/(Vector2d a, double d)
Divides a Vector2d by a scalar.
booloperator==(Vector2d lhs, Vector2d rhs)
Compares two Vector2d instances for equality within a small epsilon value.
booloperator!=(Vector2d lhs, Vector2d rhs)
Compares two Vector2d instances for inequality within a small epsilon value.
Vector2dLerp(Vector2d from, Vector2d to, double t)
Linearly interpolates between two Vector2d instances.
Vector2dMoveTowards(Vector2d current, Vector2d target, double maxDistanceDelta)
Moves a Vector2d from the current position towards a target position.
Vector2dScale(Vector2d a, Vector2d b)
Scales each component of one vector by the corresponding component of another vector.
doubleDot(Vector2d lhs, Vector2d rhs)
Calculates the dot product of two Vector2d instances.
doubleAngle(Vector2d from, Vector2d to)
Calculates the angle in degrees between two Vector2d instances.
doubleDistance(Vector2d a, Vector2d b)
Calculates the distance between two Vector2d instances.
Vector2dClampMagnitude(Vector2d vector, double maxLength)
Clamps the magnitude of the vector to a maximum length.
doubleSqrMagnitude(Vector2d a)
Returns the squared magnitude of a vector.
Vector2dMin(Vector2d lhs, Vector2d rhs)
Returns the minimum components of two Vector2d instances.
Vector2dMax(Vector2d lhs, Vector2d rhs)
Returns the maximum components of two Vector2d instances.

Public Properties

Name
doublethis[int index]
Accesses the x or y component of the vector using an index.
Vector2dnormalized
Returns a normalized version of this vector.
doublemagnitude
Returns the magnitude (length) of the vector.
doublesqrMagnitude
Returns the squared magnitude of the vector.
Vector2dzero
The zero vector (0, 0).
Vector2done
The one vector (1, 1).
Vector2dup
The up vector (0, 1).
Vector2dright
The right vector (1, 0).

Public Attributes

Name
const doublekEpsilon
A small value to compare the magnitude of vectors to. Approximately 1e-5.
doublex
The x component of the Vector2d.
doubley
The y component of the Vector2d.

Public Functions Documentation

function Vector2d

Vector2d(
double x,
double y
)

Creates a new Vector2d with the specified x and y components.

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
)

Sets the x and y components of this vector.

Parameters:

  • new_x The new value for the x component.
  • new_y The new value for the y component.

function Scale

void Scale(
Vector2d scale
)

Scales this vector by another vector.

Parameters:

  • scale The vector used for scaling.

function Normalize

void Normalize()

Normalizes this vector if it has a magnitude greater than a small epsilon value.

function ToString

override string ToString()

Returns a string representation of the Vector2d.

Return: A string representation of the vector.

function ToString

string ToString(
string format
)

Returns a string representation of the Vector2d with custom format.

Parameters:

  • format The format string to use for the components.

Return: A formatted string representation of the vector.

function GetHashCode

override int GetHashCode()

Returns a hash code for the Vector2d.

Return: A hash code based on the vector's components.

function Equals

override bool Equals(
object other
)

Compares this Vector2d to another object for equality.

Parameters:

  • other The object to compare to.

Return: True if the other object is a Vector2d and has the same components, false otherwise.

function SqrMagnitude

double SqrMagnitude()

Returns the squared magnitude of this vector.

Return: The squared magnitude of the vector.

function operator Vector2d

static implicit operator Vector2d(
Vector3d v
)

Implicitly converts a Vector3d to a Vector2d, ignoring the z component.

Parameters:

function operator Vector3d

static implicit operator Vector3d(
Vector2d v
)

Implicitly converts a Vector2d to a Vector3d, setting the z component to 0.

Parameters:

function operator+

static Vector2d operator+(
Vector2d a,
Vector2d b
)

Adds two Vector2d vectors component-wise.

Parameters:

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

Return: The result of adding the two vectors.

function operator-

static Vector2d operator-(
Vector2d a,
Vector2d b
)

Subtracts the second Vector2d from the first vector component-wise.

Parameters:

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

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

function operator-

static Vector2d operator-(
Vector2d a
)

Negates a Vector2d, changing the sign of its components.

Parameters:

  • a The vector to negate.

Return: The negated vector.

function operator*

static Vector2d operator*(
Vector2d a,
double d
)

Multiplies a Vector2d by a scalar.

Parameters:

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

Return: The result of the multiplication.

function operator*

static Vector2d operator*(
double d,
Vector2d a
)

Multiplies a Vector2d by a scalar.

Parameters:

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

Return: The result of the multiplication.

function operator/

static Vector2d operator/(
Vector2d a,
double d
)

Divides a Vector2d by a scalar.

Parameters:

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

Return: The result of the division.

function operator==

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

Compares two Vector2d instances for equality within a small epsilon value.

Parameters:

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

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

function operator!=

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

Compares two Vector2d instances for inequality within a small epsilon value.

Parameters:

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

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

function Lerp

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

Linearly interpolates between two Vector2d instances.

Parameters:

  • from The starting vector.
  • to The ending vector.
  • t The interpolation parameter. Should be in the range [0, 1].

Return: The interpolated vector.

function MoveTowards

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

Moves a Vector2d from the current position towards a target position.

Parameters:

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

Return: The new position after moving.

function Scale

static Vector2d Scale(
Vector2d a,
Vector2d b
)

Scales each component of one vector by the corresponding component of another vector.

Parameters:

  • a The first vector.
  • b The second vector used for scaling.

Return: The scaled vector.

function Dot

static double Dot(
Vector2d lhs,
Vector2d rhs
)

Calculates the dot product of two Vector2d instances.

Parameters:

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

Return: The dot product of the two vectors.

function Angle

static double Angle(
Vector2d from,
Vector2d to
)

Calculates the angle in degrees between two Vector2d instances.

Parameters:

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

Return: The angle in degrees between the two vectors.

function Distance

static double Distance(
Vector2d a,
Vector2d b
)

Calculates the distance between two Vector2d instances.

Parameters:

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

Return: The Euclidean distance between the two vectors.

function ClampMagnitude

static Vector2d ClampMagnitude(
Vector2d vector,
double maxLength
)

Clamps the magnitude of the vector to a maximum length.

Parameters:

  • vector The vector to clamp.
  • maxLength The maximum length to clamp to.

Return: The vector clamped to the specified maximum length.

function SqrMagnitude

static double SqrMagnitude(
Vector2d a
)

Returns the squared magnitude of a vector.

Return: The squared magnitude of a vector.

function Min

static Vector2d Min(
Vector2d lhs,
Vector2d rhs
)

Returns the minimum components of two Vector2d instances.

Parameters:

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

Return: A vector with the minimum components of the input vectors.

function Max

static Vector2d Max(
Vector2d lhs,
Vector2d rhs
)

Returns the maximum components of two Vector2d instances.

Parameters:

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

Return: A vector with the maximum components of the input vectors.

Public Property Documentation

property this[int index]

double this[int index];

Accesses the x or y component of the vector using an index.

Parameters:

  • index The index, where 0 corresponds to x, and 1 corresponds to y.

Exceptions:

  • IndexOutOfRangeException Thrown if the index is not 0 or 1.

Return: The value of the specified component.

property normalized

Vector2d normalized;

Returns a normalized version of this vector.

property magnitude

double magnitude;

Returns the magnitude (length) of the vector.

property sqrMagnitude

double sqrMagnitude;

Returns the squared magnitude of the vector.

property zero

static Vector2d zero;

The zero vector (0, 0).

property one

static Vector2d one;

The one vector (1, 1).

property up

static Vector2d up;

The up vector (0, 1).

property right

static Vector2d right;

The right vector (1, 0).

Public Attributes Documentation

variable kEpsilon

static const double kEpsilon = 1E-05d;

A small value to compare the magnitude of vectors to. Approximately 1e-5.

variable x

double x;

The x component of the Vector2d.

variable y

double y;

The y component of the Vector2d.