Skip to main content

Vector4f

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.

Variablesw: number

Function: The W coordinate component of the vector.

Functionsconstructor()

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

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

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

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

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

Examples

x: number

let x = vec.x;

y: number

let y = vec.y;

z: number

let z = vec.z;
flight z = thing.z;

w:number

let w = vec.w;

constructor()

let vec = new Vector4f(1, 2, 3, 4);

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

let vec = new Vector4f();

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

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

Use Case

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

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

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

}
onUpdate(deltaTime: number) {
}
}

DemoVector4fContruction.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: Vector4f): this

Function: Add another vector to the current vector.

FunctionsclampLength(length: number): this

Function: Limit the length of the current vector.

Functionsclone(): Vector4f

Function: Clone the current vector.

Examples

magnitude(): number

let vec = new Vector4f(1, 2, 3, 4);
console.log(vec.magnitude()); // 5.477225575051661

sqrMagnitude(): number

let vec = new Vector4f(1, 2, 3, 4);
console.log(vec.sqrMagnitude()); // 30

add(other: Vector4f): this

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

clampLength(length: number): this

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

clone(): Vector4f

let vec = new Vector4f(1, 2, 3, 4);
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.Vector4f(1,1,1,1)
let vec2 = new APJS.Vector4f(3,4,5,0)
console.log(vec2.magnitude());
console.log(vec2.sqrMagnitude());
vec1.add(vec2);
console.log(vec1);
vec2.clampLength(2);
console.log(vec2);
const vec3 = vec2.clone();
console.log(vec3);
}
onUpdate(deltaTime: number) {
}
}

DemoVector4fAPI1.zip

TypeNameInterface Description
FunctionsdistanceTo(other: Vector4f): number

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

Functionsdivide(other: Vector4f): this

Function: Divide the current vector by another vector.

Functionsdot(other: Vector4f): number

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

Functionsequals(other: Vector4f): boolean

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

Functionsmultiply(other: Vector4f): this

Function: Multiply the current vector with 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

distance(other: Vector4f): number

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

divide(other: Vector4f): this

let vec1 = new Vector4f(10, 20, 30, 40);
let vec2 = new Vector4f(2, 4, 6, 8);
vec1.divide(vec2);
case1.divide (case2);

dot(other: Vector4f): number

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

equals(other: Vector4f): boolean

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

multiply(other: Vector4f): this

let vec1 = new Vector4f(1, 2, 3, 4);
let vec2 = new Vector4f(2, 3, 4, 5);
vec1.multiply(vec2);

multiplyScalar(scale: number): this

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

normalize(): this

let vec = new Vector4f(1, 2, 3, 4);
vec.normalize();

Use Case

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

onStart() {
let vec1 = new APJS.Vector4f(1,1,1,1)
let vec2 = new APJS.Vector4f(3,4,5,0)
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) {
}
}

DemoVector4fAPI2.zip

TypeNameInterface Description
Functionssubtract(other: Vector4f): this

Function: Subtracts another vector from the current vector.

Functionsinverse(): Vector4f

Function: Returns the inverse vector of the current vector.

FunctionstoString(): string

Function: Returns the string representation of the current vector.

Static FunctionscompareApproximate(vec1: Vector4f, vec2: Vector4f, dist: number): boolean

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

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

Function: Calculate the linear interpolation between two vectors.

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

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

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

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

Examples

subtract(other: Vector4f): this

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

inverse(): Vector4f

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

toString(): string

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

compareApproximately(vec1: Vector4f, vec2:Vector4f, dist:number):boolean

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

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

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

max(vecA: Vector4f, vecB: Vector4f): Vector4f

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

min(vecA: Vector4f, vecB: Vector4f): Vector4f

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

Use Case

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

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

}
onUpdate(deltaTime: number) {
}
}

DemoVector4fAPI3.zip

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