New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

polygon-generator

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polygon-generator

A utility to generate coordinates of an equilateral polygon.

  • 1.2.15
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
47
decreased by-16.07%
Maintainers
1
Weekly downloads
 
Created
Source

npm version Run Status Coverage Badge Codacy Badge

polygon-generator

API

polygon = require('polygon-generator');

coordinates method

Calculate coordinates of an equilateral polygon. The returned object is an array of the following structure:

[{x: 0, y: 0}, {x: 1, y: 0}, {x: 0.5, y: 0.866}]

The vectors form an anti-clockwise path with the last vector connecting back to the first one. All coordinates will be in the first quadrant of a cartesian coordinate system meaning there will be no negative numbers. This method takes three parameters:

  • sides: the number of sides of the polygon (minimum is 3)
  • sideLength: the length of each side (default is 1)
  • startingAngle: determines the angle of the first edge, rotates anti-clockwise (default is 0, horizontal line)
sides = 3;
sideLength = 1;
startingAngle = 10;
vertices = polygon.coordinates(sides, sideLength, startingAngle);

polygon wrapper

The polygon object provides translation, rotation and scaling methods for polygons. To create one simply pass in an array of vectors representing the vertices.

poly = polygon.polygon([{x: 0, y: 0}, {x: 1, y: 0}, {x: 0.5, y: 0.866}]);

You can also directly pass in the results of the coordinates method.

poly = polygon.polygon(polygon.coordinates(5,2,20));
translate
poly.translate(vector);

Translate shifts a polygon along a vector. The vector needs to be an object with a field x and y, which should both be numbers.

rotate
poly.rotate(angle, point);

Rotate a polygon anti-clockwise around a given point {x: ?, y: ?} by the specified angle. If no point is specified then the centroid of the polygon will be used.

scale
poly.rotate(factor, point);

Scale a polygon by a certain factor with regard to a given point. If no point is specified then the centroid of the polygon will be used.

area
poly.area();

Returns the area of the polygon.

centroid
poly.centroid();

Returns the coordinates of the centroid {x: Cx, y: Cy}.

Contributing

License

Keywords

FAQs

Package last updated on 10 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc