What is @math.gl/core?
@math.gl/core is a JavaScript library that provides a suite of mathematical utilities for 3D graphics and geospatial applications. It includes functions for vector and matrix operations, quaternion calculations, and other mathematical computations commonly used in computer graphics and geospatial applications.
What are @math.gl/core's main functionalities?
Vector Operations
This feature allows you to perform vector operations such as addition, subtraction, and normalization. The code sample demonstrates how to create vectors and add them together.
const { Vector3 } = require('@math.gl/core');
const v1 = new Vector3(1, 2, 3);
const v2 = new Vector3(4, 5, 6);
const v3 = v1.add(v2);
console.log(v3); // Vector3 { x: 5, y: 7, z: 9 }
Matrix Operations
This feature provides functions for matrix operations such as multiplication, inversion, and transformation. The code sample shows how to create identity and translation matrices and multiply them.
const { Matrix4 } = require('@math.gl/core');
const m1 = new Matrix4().identity();
const m2 = new Matrix4().translate([1, 2, 3]);
const m3 = m1.multiplyRight(m2);
console.log(m3); // Matrix4 { elements: [1, 0, 0, 1, 0, 1, 0, 2, 0, 0, 1, 3, 0, 0, 0, 1] }
Quaternion Calculations
This feature allows you to perform quaternion calculations such as creating quaternions from axis rotations and multiplying quaternions. The code sample demonstrates how to create and multiply quaternions.
const { Quaternion } = require('@math.gl/core');
const q1 = new Quaternion().fromAxisRotation([0, 1, 0], Math.PI / 2);
const q2 = new Quaternion().fromAxisRotation([1, 0, 0], Math.PI / 2);
const q3 = q1.multiply(q2);
console.log(q3); // Quaternion { x: 0.5, y: 0.5, z: 0.5, w: 0.5 }
Other packages similar to @math.gl/core
gl-matrix
gl-matrix is a high-performance library for matrix and vector operations in WebGL. It provides similar functionalities to @math.gl/core, including vector, matrix, and quaternion operations. However, gl-matrix is more focused on performance and is widely used in WebGL applications.
three.js
three.js is a popular 3D library that includes a comprehensive set of mathematical utilities for 3D graphics, such as vectors, matrices, and quaternions. While three.js is primarily a 3D rendering library, its math utilities are comparable to those in @math.gl/core.
mathjs
mathjs is a versatile mathematics library for JavaScript that supports a wide range of mathematical operations, including matrix and vector calculations. While it is not specifically designed for 3D graphics, it provides a broad set of mathematical tools that can be used in various applications.
math.gl
math.gl is a suite of math modules for 3D applications.
This module contains classes for vectors and matrices etc.
For documentation please visit the website.