Catalog npm
Back to packageRELEASE DETAILS

1.0.1

npm

2d-math-utils

2D math utilities library

2dgeometrymath
Published18 Apr 2025
Direct dependencies6
Transitive dependenciesNot calculated

README

Current package documentation

2D Math Utils

Common math utilities meant for working with 2D games and simulations. This library provides a collection of functions and classes to simplify working with 2D geometry, physics, and vector math.

Live Demo

Installation

Install the library using npm:

npm install 2d-math-utils

Example Usage

Here's an example of how to use the library to calculate the angle between two points and create a vector:

import { angle, vector, point } from '2d-math-utils';

const pointA = { x: 0, y: 0 };
const pointB = { x: 3, y: 4 };

// Calculate the angle between two points
const angleBetween = angle.radiansBetweenPoints(pointA, pointB);
console.log(`Angle between points: ${angleBetween} radians`);

// Create a vector from the angle
const directionVector = vector.fromAngleRadians(angleBetween, 5);
console.log('Direction vector:', directionVector);

// Add the vector to pointA to get a new point
const newPoint = point.add(pointA, directionVector);
console.log('New point:', newPoint);

TypeScript

This library is written in TypeScript, providing type definitions out of the box.

import { Point, Vector2d, Line, Circle, Rect } from '2d-math-utils';

const pointA: Point = { x: 0, y: 0 };
const pointB: Point = { x: 3, y: 4 };

Alternative Import

You can also import specific modules directly if you prefer:

import * as vector from "math-utils-2d/vector";

Package Overview

angle

Utilities for working with angles, including conversions between degrees and radians, and calculating angles between points.

vector

Functions for creating and manipulating 2D vectors, such as addition, scaling, and rotation.

point

Utilities for working with 2D points, including distance calculations and point transformations.

physics 🧪

Experimental: Higher level physics-related utilities, including collision detection and basic physics simulations.

PhysicalBody

A class representing a physical body with properties like position, velocity, and mass, useful for simulations.

intersection

Functions for calculating intersections between geometric shapes, such as lines and circles.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 6

Native requirements
6 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
lit-html
Environment
{
  "local_name": "lit-html",
  "alias": false,
  "peer_metadata": null
}
^2.7.5runtime
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
^29.6.2development
parcel
Environment
{
  "local_name": "parcel",
  "alias": false,
  "peer_metadata": null
}
^2.9.3development
ts-jest
Environment
{
  "local_name": "ts-jest",
  "alias": false,
  "peer_metadata": null
}
^29.1.1development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^5.1.6development
@types/jest
Environment
{
  "local_name": "@types/jest",
  "alias": false,
  "peer_metadata": null
}
^29.5.3development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "37bf01da3fb87c1ea3496f68f136359264768a01",
  "tarball": "https://registry.npmjs.org/2d-math-utils/-/2d-math-utils-1.0.1.tgz",
  "fileCount": 18,
  "integrity": "sha512-2pmSecWCGB+44NfThQH3NjQWOs9xI/3f09By2Q5qbunYSAPyDepg4TnuwXSE8DAhaar5EDk+Ey5D+iFeh/KUzQ==",
  "signatures": [
    {
      "sig": "MEQCIFfPPKqw5JFl4Pi6lk8CD4M4xOV8ehkeTzIptD8UKZJjAiBCI6xn+Xp7DHaWYtH988X7HnMVNwrkD+1ifqKdQT3/1w==",
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
    }
  ],
  "unpackedSize": 68882
}

Repository

PENDING
aaronbeall/2d-math-utils

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:10 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:4dc0351937ed3dfef38dff6fd86fab4ac2b8bca179ce9fce8be8ca8df299600c

Other collected versions

1.0.218 Apr1.0.018 AprView all collected versions →