Skip to main content

Vector3f

TypeNameInterface Description
Variablesx: number

Function: The X coordinate component of the vector.

Variablesy: number

Function: The Y coordinate component of the vector.

Variablesz: number

Function: The Z coordinate component of the vector.

Functionsconstructor()

Function: Creates a default three-dimensional vector with x, y, and z all initialized to 0.

Functionsconstructor(x: number, y: number, z: number)

Function: Creates a three-dimensional vector with specified x, y, and z values.

Functionsset(x: number, y: number, z: number): this

Function: Sets the x, y, and z components of the vector.

Examples

x: number

let x = vec.x

y: number

let y = vec.y

z: number

let z = vec.z
let z = thing.z

constructor()

let vec = new Vector3f();

constructor(x: number, y: number, z: number)

let vec = new Vector3f(1, 2, 3);

set(x: number, y: number, z: number): this

let vec = new Vector3f();
vec.set(3, 4, 5);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;

onStart() {
let vec1 = new APJS.Vector3f();
vec1.set(1,2,3);
console.log(vec1.x,vec1.y,vec1.z);
vec1.y = 1;

let vec2 = new APJS.Vector3f(2,2,2)
console.log(vec2);

}
onUpdate(deltaTime: number) {
}
}

DemoVector3fConstruction.zip

TypeNameInterface Description
Functionsmagnitude(): number

Function: Returns the length (magnitude) of the vector.

FunctionssqrMagnitude(): number

Function: Returns the square of the vector length.

Functionsadd(other: Vector3f): this

Function: Add another vector to the current vector.

FunctionsangleTo(other: Vector3f): number

Function: Calculate the angle in radians between the current vector and another vector.

FunctionsclampLength(length: number): this

Function: Limit the length of the current vector.

Functionsclone(): Vector3f

Function: Clone the current vector.

Examples

magnitude(): number

let vec = new Vector3f(3, 4, 0);
console.log(vec.magnitude()); // 5

sqrMagnitude(): number

let vec = new Vector3f(3, 4, 0);
console.log(vec.sqrMagnitude()); // 25

add(other: Vector3f): this

let vec1 = new Vector3f(1, 2, 3);
let vec2 = new Vector3f(4, 5, 6);
vec1.add(vec2);
case1.add (case2);

angleTo(other: Vector3f): number

let vec1 = new Vector3f(1, 0, 0);
let vec2 = new Vector3f(0, 1, 0);
let angle = vec1.angleTo(vec2);

clampLength(length: number): this

let vec = new Vector3f(3, 4, 0);
vec.clampLength(2);

clone(): Vector3f

let vec = new Vector3f(1, 2, 3);
let cloneVec = vec.clone();

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;

onStart() {
let vec1 = new APJS.Vector3f(1,1,1)
let vec2 = new APJS.Vector3f(3,4,0)
console.log(vec2.magnitude()); // 5
console.log(vec2.sqrMagnitude());
vec1.add(vec2);
console.log(vec1);
console.log(vec1.angleTo(vec2));
vec2.clampLength(2);
console.log(vec2);
const vec3 = vec2.clone();
console.log(vec3);
}
onUpdate(deltaTime: number) {
}
}

DemoVector3fAPI1.zip

TypeNameInterface Description
Functionscross(other: Vector3f): this

Function: Calculate the cross product of the current vector and another vector.

FunctionsdistanceTo(other: Vector3f): number

Function: Calculate the distance between the current vector and another vector.

Functionsdivide(vec: Vector3f): this

Function: Divide the current vector by a scalar or another vector.

Functionsdot(other: Vector3f): number

Function: Calculate the dot product of the current vector and another vector.

Functionsequals(other: Vector3f): boolean

Function: Checks whether the current vector is equal to another vector.

Functionsmultiply(vec: Vector3f): this

Function: Multiply the current vector by a scalar or another vector.

FunctionsmultiplyScalar(scale: number): this

Function: Multiply the current vector by a scalar.

Functionsnormalize(): this

Function: Normalize the current vector so that its length is 1.

Examples

cross(other: Vector3f): this

let vec1 = new Vector3f(1, 0, 0);
let vec2 = new Vector3f(0, 1, 0);
let crossVec = vec1.cross(vec2);

distance(other: Vector3f): number

let vec1 = new Vector3f(1, 2, 3);
let vec2 = new Vector3f(4, 5, 6);
let distance = vec1.distance(vec2);

divide(vec: Vector3f): this

let vec = new Vector3f(10, 20, 30);
vec.divide(new Vector3f(10, 2, 15));

dot(other: Vector3f): number

let vec1 = new Vector3f(1, 2, 3);
let vec2 = new Vector3f(4, 5, 6);
let dotProduct = vec1.dot(vec2);

equals(other: Vector3f): boolean

let vec1 = new Vector3f(1, 2, 3);
let vec2 = new Vector3f(1, 2, 3);
console.log(vec1.equals(vec2)); // true

multiply(vec: Vector3f): this

let vec = new Vector3f(1, 2, 3);
vec.multiply(new Vector3f(2, 3, 4 ))

multiplyScalar(scale: number): this

let vec = new Vector3f(1, 2, 3);
vec.multiplyScalar(3);

normalize(): this

let vec = new Vector3f(3, 4, 0);
vec.normalize();

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;

onStart() {
let vec1 = new APJS.Vector3f(1,1,1)
let vec2 = new APJS.Vector3f(3,4,0)
vec1.cross(vec2);
console.log(vec1);
console.log(vec1.distance(vec2));
vec2.divide(vec1);
console.log(vec2);
const dotResult = vec1.dot(vec2);
console.log(dotResult);
const equalResult = vec1.equals(vec2);
console.log(equalResult);
vec1.multiply(vec2);
console.log(vec1);
vec1.multiplyScalar(2);
console.log(vec1);
vec1.normalize();
console.log(vec1);

}
onUpdate(deltaTime: number) {
}
}

DemoVector3fAPI2.zip

TypeNameInterface Description
Functionsproject(normal: Vector3f): this

Function: Project the current vector onto another vector.

Functionsreflect(other: Vector3f): this

Function: Calculate the reflection vector of the current vector relative to another vector.

Functionssubtract(other: Vector3f): this

Function: Subtracts another vector from the current vector.

Functionsinverse(): Vector3f

Function: Returns the inverse vector of the current vector.

FunctionstoString(): string

Function: Returns the string representation of the current vector.

Static Functionslerp(vecA: Vector3f, vecB: Vector3f, t: number): Vector3f

Function: Calculate the linear interpolation between two vectors.

Static FunctionscompareApproximate(vec1: Vector3f, vec2: Vector3f, distance: number)

Function: Check if two vectors are approximately equal within a specified distance.

Static Functionsmax(vecA: Vector3f, vecB: Vector3f): Vector3f

Function: Returns the vector with the largest components among two vectors.

Static Functionsmin(vecA: Vector3f, vecB: Vector3f): Vector3f

Function: Returns the vector with the smallest components among two vectors.

Examples

project(normal: Vector3f): this

let vec1 = new Vector3f(3, 4, 0);
let normal = new Vector3f(1, 0, 0);
vec1.project(normal);

reflect(other: Vector3f): this

let vec1 = new Vector3f(1, -1, 0);
let normal = new Vector3f(0, 1, 0);
vec1.reflect(normal);

subtract(other: Vector3f): this

let vec1 = new Vector3f(5, 6, 7);
let vec2 = new Vector3f(1, 2, 3);
vec1.subtract(vec2);

inverse(): Vector3f

let vec = new Vector3f(1, 2, 3);
let inverseVec = vec.inverse();

toString(): string

let vec = new Vector3f(1, 2, 3);
console.log(vec.toString()); // "(1, 2, 3)"

lerp(vecA: Vector3f, vecB: Vector3f, t: number): Vector3f

let vecA = new Vector3f(1, 1, 1);
let vecB = new Vector3f(3, 3, 3);
let lerpVec = Vector3f.lerp(vecA, vecB, 0.5);

compareApproximately(vec1: Vector3f, vec2:Vector3f, dist:number)

let vec1 = new Vector3f(1, 2, 3);
let vec2 = new Vector3f(1.1, 2.1, 3.1);
console.log(Vector3f.compareApproximately(vec1, vec2, 0.2)); // true

max(vecA: Vector3f, vecB: Vector3f): Vector3f

let vecA = new Vector3f(1, 4, 3);
let vecB = new Vector3f(3, 2, 5);
let maxVec = Vector3f.max(vecA, vecB);

min(vecA: Vector3f, vecB: Vector3f): Vector3f

let vecA = new Vector3f(1, 4, 3);
let vecB = new Vector3f(3, 2, 5);
let minVec = Vector3f.min(vecA, vecB);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;

onStart() {
let vec1 = new APJS.Vector3f(1,1,1)
let vec2 = new APJS.Vector3f(3,4,0)
console.log(vec1.clone().project(vec2));
console.log(vec1.clone().reflect(vec2));
console.log(vec1.clone().subtract(vec2));
console.log(vec1.clone().inverse());
console.log(vec1.toString());
console.log( APJS.Vector3f.lerp(vec1,vec2,0.5));
console.log( APJS.Vector3f.compareApproximately(vec1,vec2,0.001));
console.log( APJS.Vector3f.max(vec1,vec2));
console.log( APJS.Vector3f.min(vec1,vec2));

}
onUpdate(deltaTime: number) {
}
}

DemoVector3fAPI3.zip

Copyright © 2025 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalCookies