Vector3

Has 3 number components that can represent a position in space or a Euler rotation

Summary

Constructors

Vector3.new(x: number, y: number, z: number): Vector3

Creates a new Vector3 with the provided components.

Properties

zero: Vector3
one: Vector3
unitX: Vector3
unitY: Vector3
unitZ: Vector3
X: number
Y: number
Z: number
Length: number
Unit: Vector3

Methods

Vector3:Cross(other: Vector3): Vector3
Vector3:Dot(other: Vector3): number
Vector3:DistanceFrom(to: Vector3): number
Vector3:Angle(to: Vector3): number
Vector3:Lerp(to: Vector3, t: number): Vector3
Vector3:Min(min: Vector3): Vector3
Vector3:Max(max: Vector3): Vector3
Vector3:Clamp(min: Vector3, max: Vector3): Vector3
Vector3:Project(a: Vector3, b: Vector3): Vector3
Vector3:Reject(a: Vector3, b: Vector3): Vector3
Vector3:RotateByAxisAngle(v: Vector3, axis: Vector3, angle: number): Vector3
Vector3:Reflect(v: Vector3, normal: Vector3): Vector3
Vector3:Refract(v: Vector3, normal: Vector3, r: number): Vector3

Constructors

Vector3.new()

Creates a new Vector3 from the given components

Vector3.new(x: number, y: number, z: number)

Properties

Vector3.zero

A Vector3 with all components set to 0

Vector3.one

A Vector3 with all components set to 1

Vector3.unitX

A Vector3 with the X component set to 1

Vector3.unitY

A Vector3 with the Y component set to 1

Vector3.unitZ

A Vector3 with the Z component set to 1

Vector3.X

The X component of the Vector3

Vector3.Y

The Y component of the Vector3

Vector3.Z

The Z component of the Vector3

Vector3.Length

The Length of the Vector3 given with sqrt(Vector3.X^2 + Vector3.Y^2 + Vector3.Z^2)

This property can be directly set to scale the Vector3 to the provided length.

local vec = Vector3.new(2, 0, 0)
print(vec) -- Vector3(2, 0, 0)
vec.Length = 5
print(vec) -- Vector3(5, 0, 0)

Methods

Vector3.Unit

A normalized copy of the Vector3 with the same direction but Length at exactly 1

Methods

Vector3:Cross()

Returns the cross product of the two vectors

Vector3:Cross(other: Vector3): Vector3

Vector3:Dot()

Returns the dot product of the two vectors

Vector3:Dot(other: Vector3): number

Vector3:DistanceFrom()

Returns the distance from the other vector assuming both vectors are a coordinate in 3D space

Vector3:DistanceFrom(other: Vector3): number

Vector3:Angle()

Returns the angle in radians between the two vectors

Vector3:Angle(angle: Vector3): number

Vector3:Lerp()

Returns a Vector3 linearly interpolated between this Vector3 and the given goal by the given amount

Vector3:Lerp(to: Vector3, t: number): Vector3

Vector3:Min()

Returns a Vector3 with each component as the lowest values among the respective components

Vector3:Min(min: Vector3): Vector3

Vector3:Max()

Returns a Vector3 with each component as the highest values among the respective components

Vector3:Max(min: Vector3): Vector3

Vector3:Clamp()

Returns a Vector3 with each component clamped between the lowest and highest values among the respective min and max components

Vector3:Clamp(min: Vector3, max: Vector3): Vector3

Vector3:Project()

Calculates the projection of the Vector3 on to the provided Vector3

Vector3:Project(a: Vector3, b: Vector3): Vector3
Parameters Description
a : Vector3 The Vector3 to project.
b : Vector3 The Vector3 to calculate the projection on.

Vector3:Reject()

Calculates the rejection of the Vector3 on to the provided Vector3

Vector3:Reject(a: Vector3, b: Vector3): Vector3
Parameters Description
a : Vector3 The Vector3 to reject.
b : Vector3 The Vector3 to calculate the rejection on.

Vector3:RotateByAxisAngle()

Rotates the Vector3 around a given axis

Vector3:RotateByAxisAngle(v: Vector3, axis: Vector3, angle: number): Vector3
Parameters Description
v : Vector3 The Vector3 to be rotated.
axis : Vector3 The axis to rotate around.
angle : number The rotation around the axis. Assumed to be in Radians

Vector3:Reflect()

Calculates the direction of a reflected ray

Vector3:Reflect(v: Vector3, normal: Vector3): Vector3
Parameters Description
v : Vector3 The incoming ray.
normal : Vector3 The normal of the plane to reflect the ray off of.

Vector3:Refract()

Calculates the direction of a refracted ray

Vector3:Refract(v: Vector3, normal: Vector3, r: number): Vector3
Parameters Description
v : Vector3 The incoming ray. Assumed to be normalized
normal : Vector3 Normalized normal vector of the interface of two optical media
r : number Ratio of the refractive index from where the ray comes to the refractive index of the medium on the other side of the surface