npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

triangle-vector-geometry

v1.0.1

Published

Determine triangle geometry centers and some vectorial operations.

Downloads

1

Readme

Triangle Geometry is an all in one package to calculate triangle centers and some vectorial operations. The package works on 2D orthonormal coordinate system.

Install

npm install triangle-vector-geometry

API

var geometry = require('triangle-vector-geometry');

geometry.isTriangle(point_A,point_B,point_C)

Points should be a 2-scalar array of coordinates where pi=[xi,yi]. The method returns boolean whether the three points form a trangle or not.

geometry.orthocenter(point_A,point_B,point_C)

Points should be a 2-scalar array of coordinates where pi=[xi,yi]. If the points (point_A,point_B,point_C) form a triangle the method returns the orthocenter coordinates (pi=[xi,yi]) of this triangle. else it returns NULL.

geometry.circumcenter(point_A,point_B,point_C)

Points should be a 2-scalar array of coordinates where pi=[xi,yi]. If the points (point_A,point_B,point_C) form a triangle the method returns Obj {center, radius} the circumcenter coordinate (pi=[xi,yi]) and the circle radius of this triangle. else it returns NULL.

geometry.incenter(point_A,point_B,point_C)

Points should be a 2-scalar array of coordinates where pi=[xi,yi]. If the points (point_A,point_B,point_C) form a triangle the method returns Obj {center, radius} the incenter coordinate (pi=[xi,yi]) and the circle radius of this triangle. else it returns NULL.

geometry.centroid(point_A,point_B,point_C)

Points should be a 2-scalar array of coordinates where pi=[xi,yi]. The method returns the centroid coordinates (pi=[xi,yi]) of the triangle formed by (point_A,point_B,point_C).

geometry.weightedPoint(point_A,weight_A,point_B,weight_B,point_C,weight_C)

Points should be a 2-scalar array of coordinates where pi=[xi,yi]. Weights should be scalar. The method returns the sum of weighted point coordinates (point_A,weight_A); (point_B,weight_B);(point_C,weight_C).

geometry.intersect(orientation_vector_AB,point_A,orientation_vector_CD,point_C)

Orientation_vector_AB is the orientation vector of the line (AB). Points should be a 2-scalar array of coordinates where pi=[xi,yi]. Orientation_vector_CD is the orientation vector of the line (CD). If the two lines (AB) and (CD) are not // the method returns the point of intersection else it returns NULL

geometry.det(vector_i,vector_j)

Vector should be a 2-scalar array where vi=[a,b]. The method returns the determinant value of 2D vectors.

geometry.scalar(vector_i,vector_j)

Vector should be a 2-scalar array where vi=[a,b]. The method returns the scalar product value of 2D vectors.

geometry.sum(vector_i,vector_j)

Vector should be a 2-scalar array where vi=[a,b]. The method returns a vector which is the sum of 2D vectors.

geometry.dilation(vector,k)

Vector should be a 2-scalar array where vi=[a,b]. The dilation factor k should be a scalar. The method returns k*vector.

geometry.unit(vector)

Vector should be a 2-scalar array where vi=[a,b]. The method returns vector/||vector|| (unitary vector).

geometry.vector(point_A,point_B)

Points should be a 2-scalar array of coordinates where pi=[xi,yi]. The method returns the vector A->B.

Example: geometry.isTriangle(point_A,point_B,point_C)

var A=[ 2, 2 ];
var B=[ 5, 2 ];
var C=[ 2, 6 ];
console.log(geometry.isTriangle(A,C,B));
//true
console.log(geometry.isTriangle(A,A,A));
//false

Example: triangle centers

var A=[ 2, 2 ];
var B=[ 5, 2 ];
var C=[ 2, 6 ];
console.log(geometry.orthocenter(A,C,B));//orthocenter of ABC
//[ 2, 2 ]
console.log([geometry.centroid(A,C,B)]);// centroid G
//[ 3, 3.3333333333333335 ]
console.log(geometry.sum(geometry.sum(geometry.vector(geometry.centroid(A,C,B),A),geometry.vector(geometry.centroid(A,C,B),B)),geometry.vector(geometry.centroid(A,C,B),C))); //GA +GB +GC=0_
//[ 0, -4.440892098500626e-16 ]
console.log(geometry.circumcenter(A,C,B));//circumcenter
//{ center: [ 3.5, 4 ], radius: 2.5 }
console.log(geometry.circumcenter(A,C,B).center);
//[ 3.5, 4 ]
console.log(geometry.circumcenter(A,C,B).radius);
//2.5
console.log(geometry.incenter(A,C,B));
//{ center: [ 3, 3 ], radius: 1 }

Example: weightedPoint

var A=[ 2, 2 ];
var B=[ 5, 2 ];
var C=[ 2, 6 ];
console.log(geometry.weightedPoint(A,1/3,C,1/3,B,1/3));
//[ 3, 3.333333333333333 ]
console.log(geometry.centroid(A,C,B));
//[ 3, 3.333333333333333 ]
console.log(geometry.weightedPoint(A,2,C,-1,B,-1));
//[ -3, -4 ]

Example: intersect, vector

var A=[ 2, 2 ];
var B=[ 5, 2 ];
var C=[ 2, 6 ];
var AB=geometry.vector(A,B); // Orientation vector of (AB)
var AC=geometry.vector(A,C); // Orientation vector of (AC)
console.log(AB);
//[3,0]
console.log(AC);
//[0,4]
console.log(geometry.intersect(AB,A,AC,C));
//[2,2] A

Example: vector operations

var A=[ 2, 2 ];
var B=[ 5, 2 ];
var C=[ 2, 6 ];
var AB=geometry.vector(A,B); // Orientation vector of (AB)
var AC=geometry.vector(A,C); // Orientation vector of (AC)
console.log([geometry.scalar(AC,AB),geometry.scalar([1,5],[0,-1]),geometry.scalar([2,2],[2,2])]); /// geometry.scalar
//[ 0, -5, 8 ]  
console.log([geometry.det(AC,AB),geometry.det(AB,AC),geometry.det(AB,AB)]); /// geometry.det
//[ -12, 12, 0 ]
console.log(geometry.sum(AB,AC)); /// geometry.sum
//[ 3, 4 ]
console.log([geometry.dilation(AB,2), geometry.dilation(AB,-1)]); /// geometry.dilation
//[ [ 6, 0 ], [ -3, -0 ] ]
console.log([geometry.unit(AB,2), Math.sqrt(geometry.unit(AB,2)[0]*geometry.unit(AB,2)[0]+geometry.unit(AB,2)[1]*geometry.unit(AB,2)[1])]); /// geometry.unit
//[ [ 1, 0 ], 1 ]

License

MIT