A downloadable project

Download NowName your own price

The vector3d class is a JavaScript class designed to represent and manipulate 3D vectors in space. It provides a range of methods for performing common vector operations. Below is an overview of its methods and how to use them.

Vector Operations

multiply(other)

Multiplies the vector with another vector element-wise.

  • other (vector3d): The vector to multiply with.

divide(other)

Divides the vector by another vector element-wise.

  • other (vector3d): The vector to divide by.

substractNum(num)

Subtracts a number from each component of the vector.

  • num (number): The number to subtract.

addNum(num)

Adds a number to each component of the vector.

  • num (number): The number to add.

multiplyNum(num)

Multiplies each component of the vector by a number.

  • num (number): The number to multiply by.

divideNum(num)

Divides each component of the vector by a number.

  • num (number): The number to divide by.

round()

Rounds each component of the vector to the nearest integer.

floor()

Rounds down each component of the vector to the nearest integer.

dot(other)

Calculates the dot product of the vector with another vector.

  • other (vector3d): The vector to calculate the dot product with.

cross(other)

Calculates the cross product of the vector with another vector, returning a new vector.

  • other (vector3d): The vector to calculate the cross product with.

distanceTo(other)

Calculates the Euclidean distance between this vector and another vector.

  • other (vector3d): The vector to calculate the distance to.

equals(other)

Checks if the vector is equal to another vector.

  • other (vector3d): The vector to compare with.

negate()

Returns a new vector that is the negation of the current vector.

lerp(other, t)

Linearly interpolates between the current vector and another vector based on a parameter t (a value between 0 and 1).


  • other (vector3d): The target vector to interpolate towards.
  • t (number): The interpolation parameter.

Note: The lerp method modifies the current vector in place.

EXAMPLE:

// Create vector instances
const vectorA = new vector3d(1, 2, 3);
const vectorB = new vector3d(3, 4, 5);
// Example usage of methods
vectorA.multiply(vectorB);
vectorA.divideNum(2);
vectorA.round();
// Calculate the dot product
const dotProduct = vectorA.dot(vectorB);
// Calculate the cross product
const crossProduct = vectorA.cross(vectorB);
// Calculate the distance between vectors
const distance = vectorA.distanceTo(vectorB);
// Check vector equality
const areEqual = vectorA.equals(vectorB);

Download

Download NowName your own price

Click download now to get access to the following files:

behavior_vector3d.js 1 kB

Leave a comment

Log in with itch.io to leave a comment.