NodeWorld

Vector3

La référence est en anglais : elle est générée à partir des commentaires du code, écrits en anglais.

csharp
public struct Vector3 : IEquatable<Vector3>, IFormattable

Namespace NodeWorld.Flux.

A point or a direction in 3D, as Unity's Vector3: x right, y up, z forward.

Constants

kEpsilon

csharp
public const float kEpsilon = 0.00001f

The tolerance of == and of Normalize (0.00001).

kEpsilonNormalSqrt

csharp
public const float kEpsilonNormalSqrt = 1e-15f

When the product of the two lengths is below this, Angle gives 0 (1e-15).

Fields

x

csharp
public float x

The x component.

y

csharp
public float y

The y component.

z

csharp
public float z

The z component.

Constructors

Vector3

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

A vector of these components.

csharp
public Vector3(float x, float y)

A vector of x and y, z at 0.

Properties

this[]

csharp
public float this[int index] { get; set; }

x, y, z by index 0 to 2.

zero

csharp
public static Vector3 zero { get; }

(0, 0, 0).

one

csharp
public static Vector3 one { get; }

(1, 1, 1).

up

csharp
public static Vector3 up { get; }

(0, 1, 0): up.

down

csharp
public static Vector3 down { get; }

(0, -1, 0): down.

left

csharp
public static Vector3 left { get; }

(-1, 0, 0): left.

csharp
public static Vector3 right { get; }

(1, 0, 0): right.

forward

csharp
public static Vector3 forward { get; }

(0, 0, 1): forward.

back

csharp
public static Vector3 back { get; }

(0, 0, -1): back.

positiveInfinity

csharp
public static Vector3 positiveInfinity { get; }

Every component at positive infinity.

negativeInfinity

csharp
public static Vector3 negativeInfinity { get; }

Every component at negative infinity.

magnitude

csharp
public float magnitude { get; }

Length of the vector.

sqrMagnitude

csharp
public float sqrMagnitude { get; }

Squared length: quicker than magnitude, to compare lengths.

normalized

csharp
public Vector3 normalized { get; }

The vector at length 1 (zero when it is too short).

Methods

Normalize

csharp
public void Normalize()

Brings the vector to length 1 (zero when it is too short).

csharp
public static Vector3 Normalize(Vector3 value)

value at length 1 (zero when its length is under kEpsilon).

Set

csharp
public void Set(float newX, float newY, float newZ)

Sets the three components.

Scale

csharp
public void Scale(Vector3 scale)

Multiplies each component by the one of scale.

csharp
public static Vector3 Scale(Vector3 a, Vector3 b)

a and b multiplied component by component.

Dot

csharp
public static float Dot(Vector3 lhs, Vector3 rhs)

Dot product.

Cross

csharp
public static Vector3 Cross(Vector3 lhs, Vector3 rhs)

Cross product: a vector at right angles to both.

Distance

csharp
public static float Distance(Vector3 a, Vector3 b)

Distance between two points.

SqrMagnitude

csharp
public static float SqrMagnitude(Vector3 vector)

Squared length of vector.

Magnitude

csharp
public static float Magnitude(Vector3 vector)

Length of vector.

Lerp

csharp
public static Vector3 Lerp(Vector3 a, Vector3 b, float t)

From a (t = 0) to b (t = 1); t is kept between 0 and 1.

LerpUnclamped

csharp
public static Vector3 LerpUnclamped(Vector3 a, Vector3 b, float t)

From a (t = 0) to b (t = 1); t is not limited.

MoveTowards

csharp
public static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta)

current moved towards target by maxDistanceDelta at most.

RotateTowards

csharp
public static Vector3 RotateTowards(Vector3 current, Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta)

Turns "current" towards "target" by at most maxRadiansDelta, and moves its length towards target's by at most maxMagnitudeDelta (as Unity).

Angle

csharp
public static float Angle(Vector3 from, Vector3 to)

Angle in degrees between two vectors (0 to 180).

SignedAngle

csharp
public static float SignedAngle(Vector3 from, Vector3 to, Vector3 axis)

Angle in degrees from "from" to "to", signed by the rotation around axis.

Project

csharp
public static Vector3 Project(Vector3 vector, Vector3 onNormal)

vector projected on the line of onNormal (zero for a zero onNormal).

ProjectOnPlane

csharp
public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal)

vector projected on the plane whose normal is planeNormal.

Reflect

csharp
public static Vector3 Reflect(Vector3 inDirection, Vector3 inNormal)

inDirection reflected off the plane whose normal is inNormal (of length 1).

ClampMagnitude

csharp
public static Vector3 ClampMagnitude(Vector3 vector, float maxLength)

vector shortened to maxLength when it is longer.

Min

csharp
public static Vector3 Min(Vector3 a, Vector3 b)

The smaller component of a and b, on each axis.

Max

csharp
public static Vector3 Max(Vector3 a, Vector3 b)

The larger component of a and b, on each axis.

Equals

csharp
public bool Equals(Vector3 other)

The components are exactly equal.

csharp
public override bool Equals(object other)

other is a Vector3 with exactly the same components.

GetHashCode

csharp
public override int GetHashCode()

A hash of the components.

ToString

csharp
public override string ToString()

"(x, y, z)" with 2 decimals.

csharp
public string ToString(string format)

The same text with the numbers in format.

csharp
public string ToString(string format, IFormatProvider formatProvider)

The same text with the numbers in format (F2 when empty) and formatProvider (the invariant culture when null).

Operators

operator +

csharp
public static Vector3 operator +(Vector3 a, Vector3 b)

Sum.

operator -

csharp
public static Vector3 operator -(Vector3 a, Vector3 b)

Difference.

csharp
public static Vector3 operator -(Vector3 a)

The opposite vector.

operator *

csharp
public static Vector3 operator *(Vector3 a, float d)

Each component times d.

csharp
public static Vector3 operator *(float d, Vector3 a)

Each component times d.

operator /

csharp
public static Vector3 operator /(Vector3 a, float d)

Each component divided by d.

operator ==

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

Approximately equal: the squared distance is below 1e-10.

operator !=

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

Not approximately equal (see ==).

implicit operator Vector2

csharp
public static implicit operator Vector2(Vector3 v)

x and y of the vector.

implicit operator Vector3

csharp
public static implicit operator Vector3(Vector2 v)

x and y of the vector, z at 0.