Your "friendly" helper for performing mathematical operations on vectors.
- Features
- Installation
- Vex2 — Utilities for two-dimensional vectors.
- Vex3 — Utilities for three-dimensional vectors.
- Methods for both mutating and creating new vectors.
Set up a new creation with the Minepicker Creator CLI and then run the following command to install the latest version of Vex:
minepicker use vex
Utilities for two-dimensional vectors.
Creates a new Vector2 by adding two vectors together.
Vex2.add({ x: 1, y: 1 }, { x: 0, y: 1 });
Creates a new Vector2 by assigning components to a vector.
Vex2.assign({ x: 0, y: 0 }, { y: 1 });
Creates a new Vector2 by performing a ceiling function on each component of a vector.
Vex2.ceil({ x: 0.2, y: 0.6 });
Creates a new Vector2 by clamping each component of a vector between those of a minimum and maximum vector.
Vex2.clamp(
{ x: 18, y: 4 },
{ x: 0 }, // Minimum
{ x: 10, y: 10 } // Maximum
);
Calculates the distance between two vectors.
Vex2.distance({ x: 5, y: 0 }, { x: -2, y: 4 });
Creates a new Vector2 by dividing a vector by a scalar value or another vector.
Vex2.divide({ x: 4, y: 8 }, 4);
Vex2.divide({ x: 4, y: 8 }, { x: 4, y: 2 });
Calculates the dot product of two vectors.
Vex2.dot({ x: 5, y: 0 }, { x: -2, y: 4 });
Checks whether two vectors are equal.
Vex2.equals({ x: 5, y: 0 }, { x: -2, y: 4 });
Creates a new Vector2 by performing a floor function on each component of a vector.
Vex2.floor({ x: 0.2, y: 0.6 });
Creates a new Vector2 from different data types.
Vex2.from(1, 2);
Vex2.from({ x: 0, y: 1 });
Vex2.from(0);
Vex2.from(Direction.North);
Vex2.from(Direction.North, 5);
Creates a new Vector2 by using linear interpolation on each component of two vectors.
Vex2.lerp(
{ x: 5, y: 0 }, // Start
{ x: -2, y: 4 }, // End
0.5 // Interpolant
);
Calculates the magnitude of a vector.
Vex2.magnitude({ x: 2, y: 5 });
Creates a new Vector2 from the largest values of each component in the provided vectors.
Vex2.max({ x: 5, y: 0 }, { x: -2, y: 4 });
Creates a new Vector2 from the smallest values of each component in the provided vectors.
Vex2.min({ x: 5, y: 0 }, { x: -2, y: 4 });
Creates a new Vector2 by multiplying a vector by a scalar value or another vector.
Vex2.multiply({ x: 4, y: 8 }, 4);
Vex2.multiply({ x: 4, y: 8 }, { x: 4, y: 2 });
Creates a new Vector2 by normalizing a vector.
Vex2.normalize({ x: 2, y: 5 });
Creates a new Vector2 by rounding each component of a vector.
Vex2.round({ x: 0.2, y: 0.6 });
Creates a new Vector2 by using spherical linear interpolation on each component of two vectors.
Vex2.slerp(
{ x: 5, y: 0 }, // Start
{ x: -2, y: 4 }, // End
0.5 // Interpolant
);
Creates a new Vector2 by subtracting the second vector from the first vector.
Vex2.subtract({ x: 1, y: 1 }, { x: 0, y: 1 });
Creates a string representation of a Vector2.
Vex2.toString(
{ x: 0.2, y: 0.6 },
{ fractionDigits: 1 }
);
Creates a new Vex2 instance from different data types.
const vector = new Vex2(1, 2);
const vector = new Vex2({ x: 0, y: 1 });
const vector = new Vex2(0);
const vector = new Vex2(Direction.Up);
const vector = new Vex2(Direction.Up, 5);
Adds another vector to this vector.
vector.add({ x: 0, y: 1 });
Assigns components to this vector.
vector.assign({ y: 1 });
Performs a ceiling function on each component of this vector.
vector.ceil();
Clamps all components of this vector between those of a minimum and maximum vector.
vector.clamp(
{ x: 0 }, // Minimum
{ x: 10, y: 10 } // Maximum
);
Calculates the distance between this vector and another vector
vector.distance({ x: -2, y: 4 });
Divides this vector by a scalar value or another vector.
vector.divide(4);
vector.divide({ x: 4, y: 2 });
Calculates the dot product of this vector and another vector.
vector.dot({ x: -2, y: 4 });
Checks whether this vector is equal to another vector.
vector.equals({ x: -2, y: 4 });
Performs a floor function on each component of this vector.
vector.floor();
Multiplies this vector by a scalar value or another vector.
vector.multiply(4);
vector.multiply({ x: 4, y: 2 });
Normalizes this vector.
vector.normalize();
Rounds each component of this vector.
vector.round();
Subtracts another vector from this vector
vector.subtract({ x: 0, y: 1 });
Creates a string representation of this vector.
vector.toString({ fractionDigits: 1 });
Calculates the magnitude of this vector.
vector.magnitude;
The X component of this vector.
vector.x;
The Y component of this vector.
vector.y;
Utilities for three-dimensional vectors.
Creates a new Vector3 by adding two vectors together.
Vex3.add(
{ x: 1, y: 1, z: 2 },
{ x: 0, y: 1, z: 5 }
);
Creates a new Vector3 by assigning components to a vector.
Vex3.assign({ x: 0, y: 0, z: 2 }, { y: 1, x: 0 });
Creates a new Vector3 by performing a ceiling function on each component of a vector.
Vex3.ceil({ x: 0.2, y: 0.6, z: 0.5 });
Creates a new Vector3 by clamping each component of a vector between those of a minimum and maximum vector.
Vex3.clamp(
{ x: 18, y: 4, z: 0 },
{ x: 0, z: 5 }, // Minimum
{ x: 10, y: 10 } // Maximum
);
Calculates the distance between two vectors.
Vex3.distance(
{ x: 5, y: 0, z: 8 },
{ x: -2, y: 4, z: -12 }
);
Creates a new Vector3 by dividing a vector by a scalar value or another vector.
Vex3.divide({ x: 4, y: 8, z: 18 }, 4);
Vex3.divide(
{ x: 4, y: 8, z: 18 },
{ x: 4, y: 2, z: 3 }
);
Calculates the dot product of two vectors.
Vex3.dot(
{ x: 5, y: 0, z: 8 },
{ x: -2, y: 4, z: -12 }
);
Checks whether two vectors are equal.
Vex3.equals(
{ x: 5, y: 0, z: 8 },
{ x: -2, y: 4, z: -12 }
);
Creates a new Vector3 by performing a floor function on each component of a vector.
Vex3.floor({ x: 0.2, y: 0.6, z: 0.5 });
Creates a new Vector3 from different data types.
Vex3.from(1, 2, 3);
Vex3.from({ x: 0, y: 1, z: 5 });
Vex3.from(0);
Vex3.from(Direction.North);
Vex3.from(Direction.North, 5);
Creates a new Vector3 by using linear interpolation on each component of two vectors.
Vex3.lerp(
{ x: 5, y: 0 }, // Start
{ x: -2, y: 4 }, // End
0.5 // Interpolant
);
Calculates the magnitude of a vector.
Vex3.magnitude({ x: 2, y: 5, z: -3 });
Creates a new Vector3 from the largest values of each component in the provided vectors.
Vex3.max(
{ x: 5, y: 0, z: 8 },
{ x: -2, y: 4, z: -12 }
);
Creates a new Vector3 from the smallest values of each component in the provided vectors.
Vex3.min(
{ x: 5, y: 0, z: 8 },
{ x: -2, y: 4, z: -12 }
);
Creates a new Vector3 by multiplying a vector by a scalar value or another vector.
Vex3.multiply({ x: 4, y: 8, z: 18 }, 4);
Vex3.multiply(
{ x: 4, y: 8, z: 18 },
{ x: 4, y: 2, z: 3 }
);
Creates a new Vector3 by normalizing a vector.
Vex3.normalize({ x: 2, y: 5, z: -3 });
Creates a new Vector3 by rounding each component of a vector.
Vex3.round({ x: 0.2, y: 0.6, z: 0.5 });
Creates a new Vector3 by using spherical linear interpolation on each component of two vectors.
Vex3.slerp(
{ x: 5, y: 0 }, // Start
{ x: -2, y: 4 }, // End
0.5 // Interpolant
);
Creates a new Vector3 by subtracting the second vector from the first vector.
Vex3.subtract(
{ x: 1, y: 1, z: 2 },
{ x: 0, y: 1, z: 5 }
);
Creates a string representation of a Vector3.
Vex3.toString(
{ x: 0.2, y: 0.6, z: 0.5 },
{ fractionDigits: 1 }
);
Creates a new Vex3 instance from different data types.
const vector = new Vex3(1, 2, 3);
const vector = new Vex3({ x: 0, y: 1, z: 5 });
const vector = new Vex3(0);
const vector = new Vex3(Direction.North);
const vector = new Vex3(Direction.North, 5);
Adds another vector to this vector.
vector.add({ x: 0, y: 1, z: 5 });
Assigns components to this vector.
vector.assign({ y: 1, z: 0 });
Performs a ceiling function on each component of this vector.
vector.ceil();
Clamps all components of this vector between those of a minimum and maximum vector.
vector.clamp(
{ x: 0, z: 5 }, // Minimum
{ x: 10, y: 10 } // Maximum
);
Calculates the distance between this vector and another vector
vector.distance({ x: -2, y: 4, z: 18 });
Divides this vector by a scalar value or another vector.
vector.divide(4);
vector.divide({ x: 4, y: 2, z: 3 });
Calculates the dot product of this vector and another vector.
vector.dot({ x: -2, y: 4, z: 18 });
Checks whether this vector is equal to another vector.
vector.equals({ x: -2, y: 4, z: 18 });
Performs a floor function on each component of this vector.
vector.floor();
Multiplies this vector by a scalar value or another vector.
vector.multiply(4);
vector.multiply({ x: 4, y: 2, z: 3 });
Normalizes this vector.
vector.normalize();
Rounds each component of this vector.
vector.round();
Subtracts another vector from this vector
vector.subtract({ x: 0, y: 1, z: 5 });
Creates a string representation of this vector.
const command = `setblock ${vector} air destroy`;
vector.toString({ fractionDigits: 1 });
Calculates the magnitude of this vector.
vector.magnitude;
The X component of this vector.
vector.x;
The Y component of this vector.
vector.y;
The Z component of this vector.
vector.z;