Skip to main content

Vector2f

TypeNameInterface Description
Variablesx: number

Function: The X coordinate component of the vector.

Variablesy: number

Function: The Y coordinate component of the vector.

Functionsconstructor()

Function: Creates a default two-dimensional vector with both x and y initialized to 0.

Functionsconstructor(x: number, y: number)

Function: Create a two-dimensional vector with specified x and y values.

Functionsequals(other: Vector2f): boolean

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

Examples

x: number

let x = vec.x;

y: number

let y = vec.y;

constructor()

let vec = new Vector2f();

constructor(x: number, y: number)

let vec = new Vector2f(1, 2);

equals(other: Vector2f): boolean

let vec1 = new Vector2f(1, 2);
let vec2 = new Vector2f(1, 2);
console.log(vec1.equals(vec2));

Use Case

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

onStart() {
let value = new APJS.Vector2f();
value.x = 2;
value.y = 2;
let value2 = new APJS.Vector2f(2,2);
let isEqual = value.equals(value2);


}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Functionsset(x: number, y: number): this

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

Functionsmagnitude(): number

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

FunctionssqrMagnitude(): number

Function: Returns the square of the vector length.

Functionsclone(): Vector2f

Function: Clone the current vector.

Functionsadd(other: Vector2f): this

Function: Add another vector to the current vector.

Functionssubtract(other: Vector2f): this

Function: Subtract another vector from the current vector.

Functionsdivide(vec: Vector2f): this

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

Functionsdot(other: Vector2f): number

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

Functionsmultiply(other: Vector2f): this

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

FunctionsmultiplyScalar(scale: number): this

Scales the numerical properties of an object by the specified scalar scale and returns the modified object itself, supporting chaining calls.

FunctionsangleTo(other: Vector2f): number

Parameters

vec: Vector2f

The target vector to calculate the angle against.

Returns number

The angle in radians between the two vectors.

Description

Returns the angle in radians between the current vector and the specified vector vec.

FunctionsdistanceTo(other: Vector2f): number

Parameters

vec: Vector2f

The target vector to which the distance is calculated.

Returns number

The distance as a number.

Description

Calculates and returns the Euclidean distance between the current vector and another vector vec.

FunctionsclampLength(length: number): this

Parameters

length: number

The maximum length to clamp the vector to.

Returns this

This vector with its length clamped to the specified value.

Description

Clamps the length of this vector to the specified length and returns this vector.

Functionsnormalize(): this

Returns this

The normalized vector.

Description

Scales the vector to have a length of 1 and returns the normalized vector.

Functionsproject(other: Vector2f): this

Parameters

vec: Vector2f

The vector to project onto.

Returns this

The current vector after being projected onto vec.

Description

Projects the current vector onto the given vector vec and returns the result.

Functionsreflect(other: Vector2f): this

Parameters

vec: Vector2f

The normal vector defining the reflection plane.

Returns this

This vector after being reflected.

Description

Reflects the vector across the plane defined by the normal vector vec and returns this.

Functionsinverse(): Vector2f

Returns this

The current instance of Vector2f with inverted x and y values.

Description

Inverts the components of the vector.

FunctionstoString(): string

Returns string

A string in the format "Vector2f(x, y)" where x and y are fixed to 6 decimal places.

Description

Returns a string representation of the vector.

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

Parameters

vec1: Vector2f

The first vector to compare.

vec2: Vector2f

The second vector to compare.

dist: number

The maximum allowed difference between the two dimensions for the vectors to be considered approximately equal.

Returns boolean

A boolean indicating whether the two vectors are approximately equal within the given distance threshold.

Description

Approximate comparison of the two vectors by the value of each dimension with a specified distance threshold.

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

Parameters

vecA: Vector2f

The starting vector.

vecB: Vector2f

The ending vector.

t: number

The interpolation factor, typically ranging from 0 to 1.

Returns Vector2f

A new Vector2f representing the interpolated position between vecA and vecB.

Description

Linearly interpolates between the two vectors vecA and vecB by the factor t.

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

Parameters

vecA: Vector2f

The first vector to compare.

vecB: Vector2f

The second vector to compare.

Returns Vector2f

A new Vector2f instance with components set to the maximum values from vecA and vecB.

Description

Returns a new vector containing the largest value of each component from the two input vectors.

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

Parameters

vecA: Vector2f

The first vector to compare.

vecB: Vector2f

The second vector to compare.

Returns Vector2f

A new Vector2f instance with components set to the minimum values from vecA and vecB.

Description

Returns a new vector containing the smallest value of each component from the two input vectors.

Examples

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

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

magnitude(): number

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

sqrMagnitude(): number

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

clone(): Vector2f

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

add(other: Vector2f): this

let vec1 = new Vector2f(1, 2);
let vec2 = new Vector2f(3, 4);
vec1.add(vec2);

subtract(other: Vector2f): this

let vec1 = new Vector2f(5, 6);
let vec2 = new Vector2f(3, 4);
vec1.subtract(vec2);

divide(vec: Vector2f): this

let vec = new Vector2f(10, 20);
vec.divide(new Vector2f(5, 5));

dot(other: Vector2f): number

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

multiply(other: Vector2f): this

let vec = new Vector2f(1, 2);
Vec.multiply(new Vector2f(2, 3));

multiplyScalar(scale: number): this

let vec = new Vector2f(1, 2);
Vec.multiplyScale(3));

angleTo(other: Vector2): number;

const result = v1.angleTo(v2);

distance(other: Vector2f): number;

const result = v1.distance(v2);

clampLength(length: number): this

const result = v1.clampLength(3);

normalize(): this

let result = v1.normalize();

project(other: Vector2f): this

 v2.project(v1)

reflect(other: Vector2f): this

 v2.reflect(v1)

inverse(): Vector2f

v1.inverse();

toString(): string

v1.toString();

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

const result = Vector2f.compareApproximately(vec1,vec2);

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

    const result = APJS.Vector2f.lerp(value2,value3,0.5);

max(vecA: Vector2f, vecB: Vector2f): Vector2f

    const max = APJS.Vector2f.max(value2, value3);

min(vecA: Vector2f, vecB: Vector2f): Vector2f

    const min = APJS.Vector2f.min(value2,value3);

Use Case

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

onStart() {
let value = new APJS.Vector2f();
value.x = 2;
value.y = 2;
let value2 = new APJS.Vector2f(2,2);
let isEqual = value.equals(value2);

let value3 = new APJS.Vector2f();
value3.set(3,3);
const mag = value3.magnitude();
const sqrt = value3.sqrMagnitude();
const value4 = value3.clone();
value3.add(value4);
value3.subtract(value4);

value.divide(value4);
value.multiply(value2);
value.multiplyScalar(2);

value3.angleTo(value4);
value3.distance(value4);
value3.clampLength(3);
value3.normalize();
value3.project(value4);
value3.reflect(value4);

value4.inverse();
value4.toString();

APJS.Vector2f.compareApproximately(value,value2,0.0001);
const result = APJS.Vector2f.lerp(value2,value3,0.5);
const max = APJS.Vector2f.max(value2, value3);
const min = APJS.Vector2f.min(value2,value3);
}
onUpdate(deltaTime: number) {
}
}

DemoVector2fAPI.zip

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