Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/gmath/src/vector3.ts>Vector3

🎮 A wasm accelerated game and graphics maths library for deno
Latest
class Vector3
implements Point3
import { Vector3 } from "https://deno.land/x/gmath@0.1.12/src/vector3.ts";

Constructors

new
Vector3()
new
Vector3(x: number)
new
Vector3(
x: number,
y: number,
z: number,
)
new
Vector3(source: Float32Array)
new
Vector3(
x?: number | Float32Array,
y?: number,
z?: number,
)

Properties

x: number
y: number
z: number
[0]: number
[1]: number
[2]: number

Methods

add(other: number | Vector3): Vector3

Adds this Vector3 to the specified Vector3 or scalar

clamp(length: number): Vector3

Returns a new Vector2 with the same direction, but clamped to the specified length

Creates a new Vector3 with the same values

Calculates the cross product of this and specified Vector3

div(other: number | Vector3): Vector3

Divides this Vector3 with the specified Vector3 or scalar

dot(other: Vector3): number

Calculates the dot product of this Vector3

eq(other: Vector3): boolean

Checks equality between two Vector3

extend(w: number): Vector4

Create a Vector4 using this x, y and z and the provided w

isFinite(): boolean

Checks if the Vector3 is finite

lerp(other: Vector3, alpha: number): Vector3

Linearly interpolates between this and the specified Vector3

mag(): number

The magnitude of this Vector3

mag2(): number

The squared magnitude of this Vector2

Calculates the midpoint between two Vector3

mul(other: number | Vector3): Vector3

Multiplies this Vector3 with the specified Vector3 or scalar

Negates the values of this Vector3

Returns a new Vector2 with the same direction, but with a magnitude of 1

Sets the x, y and z of this Vector3 to the specified Vector3 x, y and z values

sub(other: number | Vector3): Vector3

Subtracts this Vector3 from the specified Vector3 or scalar

toArray(): [number, number, number]

Converts the Vector3 to a tuple of numbers

toFloat32Array(): Float32Array

Converts the Vector to a Float32Array

Creates a new Vector4 using this x, y and z and setting w to 1

toString(): string

Converts the Vector3 to a string

Truncates this Vector3 to a Vector2 dropping the z value

truncN(n: 0 | 1 | 2): Vector2

Truncates this Vector3 to a Vector2 dropping the nth value

Static Methods

Shorthand for writing Vector3(0, 0, -1)

Shorthand for writing Vector3(0, -1, 0)

Shorthand for writing Vector3(0, 0, 1)

Shorthand for writing Vector3(-1, 0, 0)

A Vector3 with all values set to Number.NEGATIVE_INFINITY

A Vector2 with all values set to 1

A Vector3 with all values set to Number.POSITIVE_INFINITY

Shorthand for writing Vector3(1, 0, 0)

Shorthand for writing Vector3(0, 1, 0)

A Vector2 with all values set to 0