Skip to content

jsfi/nearest-point-inside-triangle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nearest-point-inside-triangle

Returns the point if it is inside a triangle or the nearest point if it is outside the triangle

Install

This module requires node >=4.0.0

npm install --save nearest-point-inside-triangle

Usage

let nearestInside = require('nearest-point-inside-triangle')(triangle, point);

Example

let nearestInside = require('nearest-point-inside-triangle')(
    [
        [0, 0],// A
        [1, 0],// B
        [0, 1] // C
    ],
    [0.75, 0.75] //point
);

// nearestInside = [0.5, 0.5]
//partial application
let nearestInside = require('nearest-point-inside-triangle')(
    [
        [0, 0],// A
        [1, 0],// B
        [0, 1] // C
    ]
);

let insideA = nearestInside([0.25, 0.25]);
// insideA = [0.25, 0.25]

let insideB = nearestInside([0.75, 0.75]);
// insideB = [0.5, 0.5]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published