Vector3 Class
3-element structure that can be used to represent positions in 3D space or any other pair of numeric values.
Constructors
Vector3.__new(number,number,number)
Constructs a new with the given components.
Vector3.__new(x: number,y: number,z: number)
| Type | Name | Description |
|---|---|---|
| number | x | The vector's X component. |
| number | y | The vector's Y component. |
| number | z | The vector's Z component. |
Fields
| Type | Name | Static | Default | Description |
|---|---|---|---|---|
| number | X | The vector's X component. Also accessible by using the index position [0]. | ||
| number | Y | The vector's Y component. Also accessible by using the index position [1]. | ||
| number | Z | The vector's Z component. Also accessible by using the index position [2]. |
ReadOnly
| Type | Name | Static | Default | Description |
|---|---|---|---|---|
| Vector3 | Back | (0, 0, 1) | Back unit vector. Represents the local direction of back, and the global direction of south. | |
| Vector3 | Down | (0, -1, 0) | Down unit vector. | |
| Vector3 | Forward | (0, 0, -1) | Forward unit vector. Represents the local direction of forward, and the global direction of north. | |
| Vector3 | Inf | (Infinity, Infinity, Infinity) | Infinity vector, a vector with all components set to . | |
| Vector3 | Left | (-1, 0, 0) | Left unit vector. Represents the local direction of left, and the global direction of west. | |
| Vector3 | ModelBottom | (0, -1, 0) | Unit vector pointing towards the bottom side (down) of imported 3D assets. | |
| Vector3 | ModelFront | (0, 0, 1) | Unit vector pointing towards the front side (facing forward) of imported 3D assets. | |
| Vector3 | ModelLeft | (1, 0, 0) | Unit vector pointing towards the left side of imported 3D assets. | |
| Vector3 | ModelRear | (0, 0, -1) | Unit vector pointing towards the rear side (back) of imported 3D assets. | |
| Vector3 | ModelRight | (-1, 0, 0) | Unit vector pointing towards the right side of imported 3D assets. | |
| Vector3 | ModelTop | (0, 1, 0) | Unit vector pointing towards the top side (up) of imported 3D assets. | |
| Vector3 | One | (1, 1, 1) | One vector, a vector with all components set to 1. | |
| Vector3 | Right | (1, 0, 0) | Right unit vector. Represents the local direction of right, and the global direction of east. | |
| Vector3 | Up | (0, 1, 0) | Up unit vector. | |
| Vector3 | Zero | (0, 0, 0) | Zero vector, a vector with all components set to 0. |
Properties
| Type | Getter | Setter | Static | Default | Description |
|---|---|---|---|---|---|
| number | get_Item() | set_Item(val) |
Functions
Requires an instance!
Deconstruct(Single&,Single&,Single&)
Deconstruct(x: Single&,y: Single&,z: Single&) -> nil
| Type | Name | Description |
|---|---|---|
| Single& | x | |
| Single& | y | |
| Single& | z |
Abs
Returns a new vector with all components in absolute values (i.e. positive).
Abs() -> Vector3
AngleTo(Vector3)
Returns the unsigned minimum angle to the given vector, in radians.
AngleTo(to: Vector3) -> number
| Type | Name | Description |
|---|---|---|
| Vector3 | to | The other vector to compare this vector to. |
Bounce(Vector3)
Returns this vector “bounced off” from a plane defined by the given normal.
Bounce(normal: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | normal | The normal vector defining the plane to bounce off. Must be normalized. |
Ceil
Returns a new vector with all components rounded up (towards positive infinity).
Ceil() -> Vector3
Clamp(Vector3,Vector3)
Returns a new vector with all components clamped between the components of and using .
Clamp(min: Vector3,max: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | min | The vector with minimum allowed values. |
| Vector3 | max | The vector with maximum allowed values. |
Clamp(number,number)
Returns a new vector with all components clamped between the and using .
Clamp(min: number,max: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| number | min | The minimum allowed value. |
| number | max | The maximum allowed value. |
Cross(Vector3)
Returns the cross product of this vector and .
Cross(with: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | with | The other vector. |
CubicInterpolate(Vector3,Vector3,Vector3,number)
Performs a cubic interpolation between vectors , this vector, , and , by the given amount .
CubicInterpolate(b: Vector3,preA: Vector3,postB: Vector3,weight: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | b | The destination vector. |
| Vector3 | preA | A vector before this vector. |
| Vector3 | postB | A vector after . |
| number | weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
CubicInterpolateInTime(Vector3,Vector3,Vector3,number,number,number,number)
Performs a cubic interpolation between vectors , this vector, , and , by the given amount . It can perform smoother interpolation than by the time values.
CubicInterpolateInTime(b: Vector3,preA: Vector3,postB: Vector3,weight: number,t: number,preAT: number,postBT: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | b | The destination vector. |
| Vector3 | preA | A vector before this vector. |
| Vector3 | postB | A vector after . |
| number | weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
| number | t | |
| number | preAT | |
| number | postBT |
BezierInterpolate(Vector3,Vector3,Vector3,number)
Returns the point at the given on a one-dimensional Bezier curve defined by this vector and the given , , and points.
BezierInterpolate(control1: Vector3,control2: Vector3,end: Vector3,t: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | control1 | Control point that defines the bezier curve. |
| Vector3 | control2 | Control point that defines the bezier curve. |
| Vector3 | end | The destination vector. |
| number | t | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
BezierDerivative(Vector3,Vector3,Vector3,number)
Returns the derivative at the given on the Bezier curve defined by this vector and the given , , and points.
BezierDerivative(control1: Vector3,control2: Vector3,end: Vector3,t: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | control1 | Control point that defines the bezier curve. |
| Vector3 | control2 | Control point that defines the bezier curve. |
| Vector3 | end | The destination value for the interpolation. |
| number | t | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
DirectionTo(Vector3)
Returns the normalized vector pointing from this vector to .
DirectionTo(to: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | to | The other vector to point towards. |
DistanceSquaredTo(Vector3)
Returns the squared distance between this vector and . This method runs faster than , so prefer it if you need to compare vectors or need the squared distance for some formula.
DistanceSquaredTo(to: Vector3) -> number
| Type | Name | Description |
|---|---|---|
| Vector3 | to | The other vector to use. |
DistanceTo(Vector3)
Returns the distance between this vector and .
DistanceTo(to: Vector3) -> number
| Type | Name | Description |
|---|---|---|
| Vector3 | to | The other vector to use. |
Dot(Vector3)
Returns the dot product of this vector and .
Dot(with: Vector3) -> number
| Type | Name | Description |
|---|---|---|
| Vector3 | with | The other vector to use. |
Floor
Returns a new vector with all components rounded down (towards negative infinity).
Floor() -> Vector3
Inverse
Returns the inverse of this vector. This is the same as new Vector3(1 / v.X, 1 / v.Y, 1 / v.Z).
Inverse() -> Vector3
IsFinite
Returns if this vector is finite, by calling on each component.
IsFinite() -> boolean
IsNormalized
Returns if the vector is normalized, and otherwise.
IsNormalized() -> boolean
Length
Returns the length (magnitude) of this vector.
Length() -> number
LengthSquared
Returns the squared length (squared magnitude) of this vector. This method runs faster than , so prefer it if you need to compare vectors or need the squared length for some formula.
LengthSquared() -> number
Lerp(Vector3,number)
Returns the result of the linear interpolation between this vector and by amount .
Lerp(to: Vector3,weight: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | to | The destination vector for interpolation. |
| number | weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
LimitLength(number)
Returns the vector with a maximum length by limiting its length to .
LimitLength(length: number = 1) -> Vector3
| Type | Name | Description |
|---|---|---|
| number | length | The length to limit to. |
Max(Vector3)
Returns the result of the component-wise maximum between this vector and . Equivalent to new Vector3(Mathf.Max(X, with.X), Mathf.Max(Y, with.Y), Mathf.Max(Z, with.Z)).
Max(with: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | with | The other vector to use. |
Max(number)
Returns the result of the component-wise maximum between this vector and . Equivalent to new Vector3(Mathf.Max(X, with), Mathf.Max(Y, with), Mathf.Max(Z, with)).
Max(with: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| number | with | The other value to use. |
Min(Vector3)
Returns the result of the component-wise minimum between this vector and . Equivalent to new Vector3(Mathf.Min(X, with.X), Mathf.Min(Y, with.Y), Mathf.Min(Z, with.Z)).
Min(with: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | with | The other vector to use. |
Min(number)
Returns the result of the component-wise minimum between this vector and . Equivalent to new Vector3(Mathf.Min(X, with), Mathf.Min(Y, with), Mathf.Min(Z, with)).
Min(with: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| number | with | The other value to use. |
MaxAxisIndex
Returns the axis of the vector’s highest value. See . If all components are equal, this method returns .
MaxAxisIndex() -> Axis
MinAxisIndex
Returns the axis of the vector’s lowest value. See . If all components are equal, this method returns .
MinAxisIndex() -> Axis
MoveToward(Vector3,number)
Moves this vector toward by the fixed amount.
MoveToward(to: Vector3,delta: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | to | The vector to move towards. |
| number | delta | The amount to move towards by. |
Normalized
Returns the vector scaled to unit length. Equivalent to v / v.Length().
Normalized() -> Vector3
Outer(Vector3)
Returns the outer product with .
Outer(with: Vector3) -> Basis
| Type | Name | Description |
|---|---|---|
| Vector3 | with | The other vector. |
PosMod(number)
Returns a vector composed of the of this vector’s components and .
PosMod(mod: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| number | mod | A value representing the divisor of the operation. |
PosMod(Vector3)
Returns a vector composed of the of this vector’s components and ‘s components.
PosMod(modv: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | modv | A vector representing the divisors of the operation. |
Project(Vector3)
Returns a new vector resulting from projecting this vector onto the given vector . The resulting new vector is parallel to . See also . Note: If the vector is a zero vector, the components of the resulting new vector will be .
Project(onNormal: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | onNormal | The vector to project onto. |
Reflect(Vector3)
Returns this vector reflected from a plane defined by the given .
Reflect(normal: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | normal | The normal vector defining the plane to reflect from. Must be normalized. |
Rotated(Vector3,number)
Rotates this vector around a given vector by (in radians). The vector must be a normalized vector.
Rotated(axis: Vector3,angle: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | axis | The vector to rotate around. Must be normalized. |
| number | angle | The angle to rotate by, in radians. |
Round
Returns this vector with all components rounded to the nearest integer, with halfway cases rounded towards the nearest multiple of two.
Round() -> Vector3
Sign
Returns a vector with each component set to one or negative one, depending on the signs of this vector’s components, or zero if the component is zero, by calling on each component.
Sign() -> Vector3
SignedAngleTo(Vector3,Vector3)
Returns the signed angle to the given vector, in radians. The sign of the angle is positive in a counter-clockwise direction and negative in a clockwise direction when viewed from the side specified by the .
SignedAngleTo(to: Vector3,axis: Vector3) -> number
| Type | Name | Description |
|---|---|---|
| Vector3 | to | The other vector to compare this vector to. |
| Vector3 | axis | The reference axis to use for the angle sign. |
Slerp(Vector3,number)
Returns the result of the spherical linear interpolation between this vector and by amount . This method also handles interpolating the lengths if the input vectors have different lengths. For the special case of one or both input vectors having zero length, this method behaves like .
Slerp(to: Vector3,weight: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | to | The destination vector for interpolation. |
| number | weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
Slide(Vector3)
Returns a new vector resulting from sliding this vector along a plane with normal . The resulting new vector is perpendicular to , and is equivalent to this vector minus its projection on . See also . Note: The vector must be normalized. See also .
Slide(normal: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | normal | The normal vector of the plane to slide on. |
Snapped(Vector3)
Returns a new vector with each component snapped to the nearest multiple of the corresponding component in . This can also be used to round to an arbitrary number of decimals.
Snapped(step: Vector3) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector3 | step | A vector value representing the step size to snap to. |
Snapped(number)
Returns a new vector with each component snapped to the nearest multiple of . This can also be used to round to an arbitrary number of decimals.
Snapped(step: number) -> Vector3
| Type | Name | Description |
|---|---|---|
| number | step | The step size to snap to. |
OctahedronEncode
Returns the octahedral-encoded (oct32) form of this Vector3 as a Vector2. Since a Vector2 occupies 1/3 less memory compared to Vector3, this form of compression can be used to pass greater amounts of normalized Vector3s without increasing storage or memory requirements. See also , . Note: OctahedronEncode can only be used for normalized vectors. OctahedronEncode does not check whether this Vector3 is normalized, and will return a value that does not decompress to the original value if the Vector3 is not normalized. Note: Octahedral compression is lossy, although visual differences are rarely perceptible in real world scenarios.
OctahedronEncode() -> Vector2
Equals(Object)
Returns if the vector is exactly equal to the given object (). Note: Due to floating-point precision errors, consider using instead, which is more reliable.
Equals(obj: Object) -> boolean
| Type | Name | Description |
|---|---|---|
| Object | obj | The object to compare with. |
Equals(Vector3)
Returns if the vectors are exactly equal. Note: Due to floating-point precision errors, consider using instead, which is more reliable.
Equals(other: Vector3) -> boolean
| Type | Name | Description |
|---|---|---|
| Vector3 | other | The other vector. |
IsEqualApprox(Vector3)
Returns if this vector and are approximately equal, by running on each component.
IsEqualApprox(other: Vector3) -> boolean
| Type | Name | Description |
|---|---|---|
| Vector3 | other | The other vector to compare. |
IsZeroApprox
Returns if this vector’s values are approximately zero, by running on each component. This method is faster than using with one value as a zero vector.
IsZeroApprox() -> boolean
GetHashCode
Serves as the hash function for .
GetHashCode() -> number
ToString
Converts this to a string.
ToString() -> string
ToString(string)
Converts this to a string with the given .
ToString(format: string) -> string
| Type | Name | Description |
|---|---|---|
| string | format |
Static Functions
Do not require an instance!
OctahedronDecode(Vector2)
Returns the Vector3 from an octahedral-compressed form created using (stored as a Vector2).
OctahedronDecode(oct: Vector2) -> Vector3
| Type | Name | Description |
|---|---|---|
| Vector2 | oct | Encoded Vector2 |