point-calculation
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.1 • Public • Published

    Point Calculation

    Node.js CI

    Node.js Package

    A simple library that provides functions for cartesian point calculations.

    Install

    Install the package

    npm i point-calculation
    

    Import the module

    var pc = require('point-calculation');
    

    Supported Calculations

    Many calculation use a simple class of Point. The structure of this class is as follows:

    {
        x: number,
        y: number
    }
    

    Distance

    Finds the distance between two points

    distance(point1, point2);

    Params

    • point1: required Point
    • point2: required Point
    var pc = require('point-calculation');
    var dist = pc.distance({x: 2, y: 2}, {x: 2, y: 4});
    console.log(dist); // 2
    

    Angle

    Finds the angle of the line that passes through both of the points. Angle is returned in Radians.

    angle(point1, point2);

    Params

    • point1: required Point
    • point2: required Point
    var pc = require('point-calculation');
    var angle = pc.angle({x: 30, y: 37}, {x: 79, y: -51});
    console.log(angle); // ~2.08
    

    Rotate Point

    Rotates a point around another point by a given angle.

    rotatePoint(rotatingPoint, centerPoint, angle);

    Params

    • rotatingPoint: required Point This is where the point is before it is rotated.
    • centerPoint: required Point The rotatingPoint is rotated around this point
    • angle required angle in radians
    var pc = require('point-calculation');
    var point = pc.rotatePoint({x: 5, y: 0}, {x: 0, y: 0}, Math.PI / 6);
    console.log(point); // {x: 4, y: -2}
    

    Translate Point

    Moves point a given distance and angle;

    translatePoint(point, distance, angle);

    Params

    • point: required Point
    • distance: required number
    • angle: optional angle in radians (defaults to 0)
    var pc = require('point-calculation');
    var point = pc.translatePoint({x: 0, y: 0}, 5, Math.PI / 4);
    console.log(point); // ~{x: 3.535, y: 3.535}
    

    Find Point on Line

    Returns a point between to points as a given distance

    findPointOnLine(startPoint, endPoint, distanceFromStart)

    Params

    • startPoint: required Point
    • endPoint: required Point
    • distanceFromStart: required number
    var pc = require('point-calculation');
    var point = pc.findPointOnLine({x: 0, y: 0}, {x: 3, y: 4}, 3);
    console.log(point); // ~{x: 1.8, y: 2.4}
    

    Keywords

    none

    Install

    npm i point-calculation

    DownloadsWeekly Downloads

    9

    Version

    1.1.1

    License

    ISC

    Unpacked Size

    13.5 kB

    Total Files

    12

    Last publish

    Collaborators

    • nilestanner