{"id":13547596,"url":"https://github.com/HarryStevens/geometric","last_synced_at":"2025-04-02T20:30:27.191Z","repository":{"id":43331470,"uuid":"159524217","full_name":"HarryStevens/geometric","owner":"HarryStevens","description":"A JavaScript library for doing geometry.","archived":false,"fork":false,"pushed_at":"2023-10-19T16:44:15.000Z","size":1486,"stargazers_count":945,"open_issues_count":6,"forks_count":49,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-04-14T07:30:24.255Z","etag":null,"topics":["geometry"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/geometric","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HarryStevens.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-11-28T15:33:50.000Z","updated_at":"2024-04-12T21:16:44.000Z","dependencies_parsed_at":"2024-01-18T04:07:13.306Z","dependency_job_id":"4bcc8ebb-1651-42d5-be16-5294032ee4f5","html_url":"https://github.com/HarryStevens/geometric","commit_stats":{"total_commits":310,"total_committers":5,"mean_commits":62.0,"dds":0.04516129032258065,"last_synced_commit":"6ab640a450568d3c64a53e5c0cb391ab865b2d42"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarryStevens%2Fgeometric","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarryStevens%2Fgeometric/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarryStevens%2Fgeometric/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarryStevens%2Fgeometric/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HarryStevens","download_url":"https://codeload.github.com/HarryStevens/geometric/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246887744,"owners_count":20850136,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geometry"],"created_at":"2024-08-01T12:00:58.555Z","updated_at":"2025-04-02T20:30:26.621Z","avatar_url":"https://github.com/HarryStevens.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","👨‍💻 JavaScript Libraries","应用相关"],"sub_categories":["Data Processing"],"readme":"# Geometric.js\nA JavaScript library for doing geometry.\n\n[\u003cimg src=\"https://raw.githubusercontent.com/HarryStevens/geometric/master/img/angle-thumb.png\" /\u003e](https://blocks.roadtolarissa.com/HarryStevens/5fe49df19892c04dfb9883c217571409)\n[\u003cimg src=\"https://raw.githubusercontent.com/HarryStevens/geometric/master/img/length-thumb.png\" /\u003e](https://blocks.roadtolarissa.com/HarryStevens/c4eddfb97535e8e01643325cb43175ff)\n[\u003cimg src=\"https://raw.githubusercontent.com/HarryStevens/geometric/master/img/centroid-thumb.png\" /\u003e](https://blocks.roadtolarissa.com/HarryStevens/37287b23b345f394f8276dc87a9c2bc6)\n\n## Installation\n\n### Web browser\nIn vanilla, a `geometric` global is exported. You can use the latest version from unpkg.\n```html\n\u003cscript src=\"https://unpkg.com/geometric@2.5.5/build/geometric.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/geometric@2.5.5/build/geometric.min.js\"\u003e\u003c/script\u003e\n```\nIf you'd rather host it yourself, download the latest release from the [`build` directory](https://github.com/HarryStevens/geometric/tree/master/build).\n\n### npm\n\n```bash\nnpm i geometric -S\n```\n```js\nconst geometric = require(\"geometric\");\n```\n\n## API\n\nGeometric.js uses the geometric primitives \u003cb\u003epoints\u003c/b\u003e, \u003cb\u003elines\u003c/b\u003e, and \u003cb\u003epolygons\u003c/b\u003e.\n* [\u003cb\u003ePoints\u003c/b\u003e](#points) are represented as arrays of two numbers, such as [0, 0].\n* [\u003cb\u003eLines\u003c/b\u003e](#lines) are represented as arrays of two points, such as [[0, 0], [1, 0]]. Because they have endpoints, these are technically [line \u003ci\u003esegments\u003c/i\u003e](https://web.archive.org/web/20170829200252/https://www.mhschool.com/math/mathconnects/wa/assets/docs/394_397_wa_gr3_adllsn_onln.pdf), but Geometric.js refers to them as lines for simplicity's sake.\n* [\u003cb\u003ePolygons\u003c/b\u003e](#polygons) are represented as arrays of vertices, each of which is a point, such as [[0, 0], [1, 0], [1, 1], [0, 1]]. Polygons can be closed – the first and last vertex are the same – or open.\n* There are also functions to [calculate relationships](#relationships) between these primitives.\n\nYou will also encounter \u003cb\u003eangles\u003c/b\u003e, \u003cb\u003eareas\u003c/b\u003e, \u003cb\u003edistances\u003c/b\u003e, and \u003cb\u003elengths\u003c/b\u003e.\n* [\u003cb\u003eAngles\u003c/b\u003e](#angles) are represented as numbers, measured in degrees. Geometric.js also provides functions to convert angles from [degrees to radians](#angleToRadians) or [vice versa](#angleToDegrees).\n* \u003cb\u003eAreas\u003c/b\u003e, \u003cb\u003edistances\u003c/b\u003e, and \u003cb\u003elengths\u003c/b\u003e are represented as numbers, measured in pixels.\n\n\u003chr /\u003e\n\n### \u003ca name=\"points\"\u003e\u003c/a\u003ePoints\n\n\u003ca name=\"pointRotate\" href=\"#pointRotate\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epointRotate\u003c/b\u003e(\u003ci\u003epoint\u003c/i\u003e, \u003ci\u003eangle\u003c/i\u003e[, \u003ci\u003eorigin\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/points/pointRotate.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-pointrotate \"Example\")\n\nReturns the coordinates resulting from rotating a \u003ci\u003epoint\u003c/i\u003e about an origin by an \u003ci\u003eangle\u003c/i\u003e in degrees. If \u003ci\u003eorigin\u003c/i\u003e is not specified, the origin defaults to [0, 0].\n\n\u003ca name=\"pointTranslate\" href=\"#pointTranslate\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epointTranslate\u003c/b\u003e(\u003ci\u003epoint\u003c/i\u003e, \u003ci\u003eangle\u003c/i\u003e, \u003ci\u003edistance\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/points/pointTranslate.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-pointtranslate \"Example\")\n\nReturns the coordinates resulting from translating a \u003ci\u003epoint\u003c/i\u003e by an \u003ci\u003eangle\u003c/i\u003e in degrees and a \u003ci\u003edistance\u003c/i\u003e.\n\n\u003chr /\u003e\n\n### \u003ca name=\"lines\"\u003e\u003c/a\u003eLines\n\n\u003ca name=\"lineAngle\" href=\"#lineAngle\"\u003e#\u003c/a\u003e geometric.\u003cb\u003elineAngle\u003c/b\u003e(\u003ci\u003eline\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/lines/lineAngle.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-lineangle \"Example\")\n\nReturns the angle of a \u003ci\u003eline\u003c/i\u003e, in degrees, with respect to the horizontal axis.\n\n\u003ca name=\"lineInterpolate\" href=\"#lineInterpolate\"\u003e#\u003c/a\u003e geometric.\u003cb\u003elineInterpolate\u003c/b\u003e(\u003ci\u003eline\u003c/i\u003e[, \u003ci\u003eclamp\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/lines/lineInterpolate.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-lineinterpolate \"Example\")\n\nReturns an interpolator function given a \u003ci\u003eline\u003c/i\u003e [a, b]. The returned interpolator function takes a single argument \u003ci\u003et\u003c/i\u003e, where t is a number in [0, 1]; a value of 0 returns a, while a value of 1 returns b. Intermediate values interpolate from a to b along the line segment.\n\nBy default, the interpolator will return points outside of the line segment if t is less than 0 or greater than 1. You can pass an optional boolean indicating whether to \u003ci\u003eclamp\u003c/i\u003e the returned point to inside of the line segment, even if t is greater than 1 or less than 0.\n\n\u003ca name=\"lineLength\" href=\"#lineLength\"\u003e#\u003c/a\u003e geometric.\u003cb\u003elineLength\u003c/b\u003e(\u003ci\u003eline\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/lines/lineLength.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-linelength \"Example\")\n\nReturns the length of a \u003ci\u003eline\u003c/i\u003e.\n\n\u003ca name=\"lineMidpoint\" href=\"#lineMidpoint\"\u003e#\u003c/a\u003e geometric.\u003cb\u003elineMidpoint\u003c/b\u003e(\u003ci\u003eline\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/lines/lineMidpoint.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-linemidpoint \"Example\")\n\nReturns the midpoint of a \u003ci\u003eline\u003c/i\u003e.\n\n\u003ca name=\"lineRotate\" href=\"#lineRotate\"\u003e#\u003c/a\u003e geometric.\u003cb\u003elineRotate\u003c/b\u003e(\u003ci\u003eline\u003c/i\u003e, \u003ci\u003eangle\u003c/i\u003e[, \u003ci\u003eorigin\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/lines/lineRotate.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-linerotate \"Example\")\n\nReturns the coordinates resulting from rotating a \u003ci\u003eline\u003c/i\u003e about an origin by an \u003ci\u003eangle\u003c/i\u003e in degrees. If \u003ci\u003eorigin\u003c/i\u003e is not specified, the origin defaults to the \u003ca href=\"#lineMidpoint\"\u003emidpoint\u003c/a\u003e of the line.\n\n\u003ca name=\"lineTranslate\" href=\"#lineTranslate\"\u003e#\u003c/a\u003e geometric.\u003cb\u003elineTranslate\u003c/b\u003e(\u003ci\u003eline\u003c/i\u003e, \u003ci\u003eangle\u003c/i\u003e, \u003ci\u003edistance\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/lines/lineTranslate.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-linetranslate \"Example\")\n\nReturns the coordinates resulting from translating a \u003ci\u003eline\u003c/i\u003e by an \u003ci\u003eangle\u003c/i\u003e in degrees and a \u003ci\u003edistance\u003c/i\u003e.\n\n\u003chr /\u003e\n\n### \u003ca name=\"polygons\"\u003e\u003c/a\u003ePolygons\n\n\u003ca name=\"polygonArea\" href=\"#polygonArea\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonArea\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e[, \u003ci\u003esigned\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonArea.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonarea \"Example\")\n\nReturns the area of a \u003ci\u003epolygon\u003c/i\u003e. You can pass a boolean indicating whether the returned area is \u003ci\u003esigned\u003c/i\u003e, which defaults to false.\n\n\u003ca name=\"polygonBounds\" href=\"#polygonBounds\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonBounds\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonBounds.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonbounds \"Example\")\n\nReturns the bounds of a \u003ci\u003epolygon\u003c/i\u003e, ignoring points with invalid values (null, undefined, NaN, Infinity). The returned bounds are represented as an array of two points, where the first point is the top-left corner and the second point is the bottom-right corner. For example:\n\n```js\nconst rectangle = [[0, 0], [0, 1], [1, 1], [1, 0]];\nconst bounds = geometric.polygonBounds(rectangle); // [[0, 0], [1, 1]]\n```\n\nReturns null if the \u003ci\u003epolygon\u003c/i\u003e has fewer than three points.\n\n\u003ca name=\"polygonCentroid\" href=\"#polygonCentroid\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonCentroid\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonCentroid.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygoncentroid-geometric-polygonmean \"Example\")\n\nReturns the weighted centroid of a \u003ci\u003epolygon\u003c/i\u003e. Not to be [confused](https://github.com/Turfjs/turf/issues/334) with a [mean center](#polygonMean).\n\n\u003ca name=\"polygonHull\" href=\"#polygonHull\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonHull\u003c/b\u003e(\u003ci\u003epoints\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonHull.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonhull \"Example\")\n\nReturns the [convex hull](https://en.wikipedia.org/wiki/Convex_hull), represented as a polygon, for an array of \u003ci\u003epoints\u003c/i\u003e. Returns null if the input array has fewer than three points. Uses [Andrew’s monotone chain algorithm](https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain#JavaScript).\n\n\u003ca name=\"polygonInterpolate\" href=\"#polygonInterpolate\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonInterpolate\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonInterpolate.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygoninterpolate \"Example\")\n\nReturns an interpolator function given a \u003ci\u003epolygon\u003c/i\u003e of vertices [a, ..., n]. The returned interpolator function takes a single argument \u003ci\u003et\u003c/i\u003e, where t is a number in [0, 1]; a value of 0 returns a, while a value of 1 returns n. Intermediate values interpolate from a to n along the polygon's perimeter.\n\n\u003ca name=\"polygonLength\" href=\"#polygonLength\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonLength\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonLength.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonlength \"Example\")\n\nReturns the length of a \u003ci\u003epolygon\u003c/i\u003e's perimeter.\n\n\u003ca name=\"polygonMean\" href=\"#polygonMean\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonMean\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonMean.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygoncentroid-geometric-polygonmean \"Example\")\n\nReturns the arithmetic mean of the vertices of a polygon. Keeps duplicate vertices, resulting in different values for open and closed polygons. Not to be [confused](https://github.com/Turfjs/turf/issues/334) with a [centroid](#polygonCentroid).\n\n\u003ca name=\"polygonRandom\" href=\"#polygonRandom\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonRandom\u003c/b\u003e([\u003ci\u003esides\u003c/i\u003e[, \u003ci\u003earea\u003c/i\u003e[, \u003ci\u003ecentroid\u003c/i\u003e]]]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonRandom.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonrandom \"Example\")\n\nReturns the vertices of a random convex polygon of the specified number of \u003ci\u003esides\u003c/i\u003e, \u003ci\u003earea\u003c/i\u003e, and \u003ci\u003ecentroid\u003c/i\u003e coordinates. If \u003ci\u003esides\u003c/i\u003e is not specified, defaults to 3. If \u003ci\u003earea\u003c/i\u003e is not specified, defaults to 100. If \u003ci\u003ecentroid\u003c/i\u003e is not specified, defaults to [0, 0]. The returned polygon's winding order will be counter-clockwise. Based on an algorithm by Pavel Valtr and an [implementation by Maneesh Agrawala](https://observablehq.com/@magrawala/random-convex-polygon).\n\n\u003ca name=\"polygonReflectX\" href=\"#polygonReflectX\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonReflectX\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e[, \u003ci\u003ereflectFactor\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonReflectX.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonreflectx \"Example\")\n\nReflects a \u003cem\u003epolygon\u003c/em\u003e over its vertical midline. Pass an optional \u003cem\u003ereflectFactor\u003c/em\u003e between 0 and 1, where 1 indicates a full reflection, 0 leaves the polygon unchanged, and 0.5 collapses the polygon on its vertical midline.\n\n\u003ca name=\"polygonReflectX\" href=\"#polygonReflectY\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonReflectY\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e[, \u003ci\u003ereflectFactor\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonReflectY.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonreflecty \"Example\")\n\nReflects a \u003cem\u003epolygon\u003c/em\u003e over its horizontal midline. Pass an optional \u003cem\u003ereflectFactor\u003c/em\u003e between 0 and 1, where 1 indicates a full reflection, 0 leaves the polygon unchanged, and 0.5 collapses the polygon on its horizontal midline.\n\n\u003ca name=\"polygonRegular\" href=\"#polygonRegular\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonRegular\u003c/b\u003e([\u003ci\u003esides\u003c/i\u003e[, \u003ci\u003earea\u003c/i\u003e[, \u003ci\u003ecenter\u003c/i\u003e]]]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonRegular.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonregular \"Example\")\n\nReturns the vertices of a regular polygon of the specified number of \u003ci\u003esides\u003c/i\u003e, \u003ci\u003earea\u003c/i\u003e, and \u003ci\u003ecenter\u003c/i\u003e coordinates. If \u003ci\u003esides\u003c/i\u003e is not specified, defaults to 3. If \u003ci\u003earea\u003c/i\u003e is not specified, defaults to 100. If \u003ci\u003ecenter\u003c/i\u003e is not specified, defaults to [0, 0]. The returned polygon's winding order will be counter-clockwise.\n\n\u003ca name=\"polygonRotate\" href=\"#polygonRotate\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonRotate\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e, \u003ci\u003eangle\u003c/i\u003e[, \u003ci\u003eorigin\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonRotate.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonrotate \"Example\")\n\nReturns the vertices resulting from rotating a \u003ci\u003epolygon\u003c/i\u003e about an origin by an \u003ci\u003eangle\u003c/i\u003e in degrees. If \u003ci\u003eorigin\u003c/i\u003e is not specified, the origin defaults to [0, 0].\n\n\u003ca name=\"polygonScale\" href=\"#polygonScale\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonScale\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e, \u003ci\u003escaleFactor\u003c/i\u003e[, \u003ci\u003eorigin\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonScale.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonscale \"Example\")\n\nReturns the vertices resulting from scaling a \u003ci\u003epolygon\u003c/i\u003e by a \u003ci\u003escaleFactor\u003c/i\u003e (where 1 is the polygon's current size) from an origin point. If \u003ci\u003eorigin\u003c/i\u003e is not specified, the origin defaults to the polygon's centroid.\n\nThe returned polygon's area is equal to the input polygon's area multiplied by the square of the \u003ci\u003escaleFactor\u003c/i\u003e. To scale the polygon's area by the \u003ci\u003escaleFactor\u003c/i\u003e itself, see \u003ca href=\"#polygonScaleArea\"\u003egeometric.polygonScaleArea\u003c/a\u003e.\n\n\u003ca name=\"polygonScaleArea\" href=\"#polygonScaleArea\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonScaleArea\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e, \u003ci\u003escaleFactor\u003c/i\u003e[, \u003ci\u003eorigin\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonScaleArea.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonscalearea \"Example\")\n\nReturns the vertices resulting from scaling a \u003ci\u003epolygon\u003c/i\u003e by a \u003ci\u003escaleFactor\u003c/i\u003e (where 1 is the polygon's current size) from an origin point. If \u003ci\u003eorigin\u003c/i\u003e is not specified, the origin defaults to the polygon's centroid.\n\nThe returned polygon's area is equal to the input polygon's area multiplied by the \u003ci\u003escaleFactor\u003c/i\u003e. To scale the polygon's area by the square of the \u003ci\u003escaleFactor\u003c/i\u003e, see \u003ca href=\"#polygonScale\"\u003egeometric.polygonScale\u003c/a\u003e.\n\n\u003ca name=\"polygonScaleX\" href=\"#polygonScaleX\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonScaleX\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e, \u003ci\u003escaleFactor\u003c/i\u003e[, \u003ci\u003eorigin\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonScaleX.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonscalex \"Example\")\n\nReturns the vertices resulting from scaling the horizontal coordinates of a \u003ci\u003epolygon\u003c/i\u003e by a \u003ci\u003escaleFactor\u003c/i\u003e (where 1 is the polygon's current size) from an origin point. The vertical coordinates remain unchanged. If \u003ci\u003eorigin\u003c/i\u003e is not specified, the origin defaults to the polygon's centroid.\n\nThe returned polygon's area is equal to the input polygon's area multiplied by the \u003ci\u003escaleFactor\u003c/i\u003e.\n\n\u003ca name=\"polygonScaleY\" href=\"#polygonScaleY\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonScaleY\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e, \u003ci\u003escaleFactor\u003c/i\u003e[, \u003ci\u003eorigin\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonScaleY.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonscaley \"Example\")\n\nReturns the vertices resulting from scaling the vertical coordinates of a \u003ci\u003epolygon\u003c/i\u003e by a \u003ci\u003escaleFactor\u003c/i\u003e (where 1 is the polygon's current size) from an origin point. The horizontal coordinates remain unchanged. If \u003ci\u003eorigin\u003c/i\u003e is not specified, the origin defaults to the polygon's centroid.\n\nThe returned polygon's area is equal to the input polygon's area multiplied by the \u003ci\u003escaleFactor\u003c/i\u003e.\n\n\u003ca name=\"polygonTranslate\" href=\"#polygonTranslate\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonTranslate\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e, \u003ci\u003eangle\u003c/i\u003e, \u003ci\u003edistance\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonTranslate.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygontranslate \"Example\")\n\nReturns the vertices resulting from translating a \u003ci\u003epolygon\u003c/i\u003e by an \u003ci\u003eangle\u003c/i\u003e in degrees and a \u003ci\u003edistance\u003c/i\u003e.\n\n\u003ca name=\"polygonWind\" href=\"#polygonWind\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonWind\u003c/b\u003e(\u003ci\u003epolygon\u003c/i\u003e[, \u003ci\u003eorder\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/polygons/polygonWind.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonwind \"Example\")\n\nReturns a \u003ci\u003epolygon\u003c/i\u003e in the specified winding order. If an \u003ci\u003eorder\u003c/i\u003e string is passed as either \"cw\" or \"clockwise\", returns a polygon with a clockwise winding order. Otherwise, returns a polygon with a counter-clockwise winding order. Returns null if the \u003ci\u003epolygon\u003c/i\u003e has fewer than three points.\n\nOn computer screens where the top-left corner is at [0, 0], a polygon with a negative signed area has a counter-clockwise winding order.\n\n\u003chr /\u003e\n\n### \u003ca name=\"relationships\"\u003e\u003c/a\u003eRelationships\n\n\u003ca name=\"lineIntersectsLine\" href=\"#lineIntersectsLine\"\u003e#\u003c/a\u003e geometric.\u003cb\u003elineIntersectsLine\u003c/b\u003e(\u003ci\u003elineA\u003c/i\u003e, \u003ci\u003elineB\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/relationships/lineIntersectsLine.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-lineintersectsline \"Example\")\n\nReturns a boolean representing whether \u003ci\u003elineA\u003c/i\u003e intersects \u003ci\u003elineB\u003c/i\u003e.\n\n\u003ca name=\"lineIntersectsPolygon\" href=\"#lineIntersectsPolygon\"\u003e#\u003c/a\u003e geometric.\u003cb\u003elineIntersectsPolygon\u003c/b\u003e(\u003ci\u003eline\u003c/i\u003e, \u003ci\u003epolygon\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/relationships/lineIntersectsPolygon.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-lineintersectspolygon \"Example\")\n\nReturns a boolean representing whether a \u003ci\u003eline\u003c/i\u003e intersects a \u003ci\u003epolygon\u003c/i\u003e.\n\n\u003ca name=\"pointInPolygon\" href=\"#pointInPolygon\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epointInPolygon\u003c/b\u003e(\u003ci\u003epoint\u003c/i\u003e, \u003ci\u003epolygon\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/relationships/pointInPolygon.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-pointinpolygon \"Example\")\n\nReturns a boolean representing whether a \u003ci\u003epoint\u003c/i\u003e is inside of a \u003ci\u003epolygon\u003c/i\u003e. Uses [ray casting](https://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm).\n\n\u003ca name=\"pointOnPolygon\" href=\"#pointOnPolygon\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epointOnPolygon\u003c/b\u003e(\u003ci\u003epoint\u003c/i\u003e, \u003ci\u003epolygon\u003c/i\u003e[, \u003ci\u003eepsilon\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/relationships/pointOnPolygon.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-pointonpolygon \"Example\")\n\nReturns a boolean representing whether a \u003ci\u003epoint\u003c/i\u003e is located on one of the edges of a \u003ci\u003epolygon\u003c/i\u003e. An optional \u003ci\u003eepsilon\u003c/i\u003e number, such as 1e-6, can be passed to reduce the precision with which the relationship is measured.\n\n\u003ca name=\"pointOnLine\" href=\"#pointOnLine\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epointOnLine\u003c/b\u003e(\u003ci\u003epoint\u003c/i\u003e, \u003ci\u003eline\u003c/i\u003e[, \u003ci\u003eepsilon\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/relationships/pointOnLine.js#L17 \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-pointonline-geometric-pointwithline \"Example\")\n\nReturns a boolean representing whether a \u003ci\u003epoint\u003c/i\u003e is collinear with a \u003ci\u003eline\u003c/i\u003e and is also located on the line segment. An optional \u003ci\u003eepsilon\u003c/i\u003e number, such as 1e-6, can be passed to reduce the precision with which the relationship is measured. See also [pointWithLine](#pointWithLine).\n\n[\u003cimg width=\"150\" src=\"https://raw.githubusercontent.com/HarryStevens/geometric/master/img/point-on-with-line.png\" /\u003e](https://observablehq.com/d/c463ce4b7cbcd048)\n\n\u003ca name=\"pointWithLine\" href=\"#pointWithLine\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epointWithLine\u003c/b\u003e(\u003ci\u003epoint\u003c/i\u003e, \u003ci\u003eline\u003c/i\u003e[, \u003ci\u003eepsilon\u003c/i\u003e]) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/relationships/pointOnLine.js#L21 \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-pointonline-geometric-pointwithline \"Example\")\n\nReturns a boolean representing whether a \u003ci\u003epoint\u003c/i\u003e is collinear with a \u003ci\u003eline\u003c/i\u003e. An optional \u003ci\u003eepsilon\u003c/i\u003e number, such as 1e-6, can be passed to reduce the precision with which the relationship is measured. See also [pointOnLine](#pointOnLine).\n\n\u003ca name=\"pointLeftofLine\" href=\"#pointLeftofLine\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epointLeftofLine\u003c/b\u003e(\u003ci\u003epoint\u003c/i\u003e, \u003ci\u003eline\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/relationships/pointOnLine.js#L9 \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-pointleftofline-geometric-pointrightofline-g \"Example\")\n\nReturns a boolean representing whether a \u003ci\u003epoint\u003c/i\u003e is to the left of a \u003ci\u003eline\u003c/i\u003e.\n\n\u003ca name=\"pointRightofLine\" href=\"#pointRightofLine\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epointRightofLine\u003c/b\u003e(\u003ci\u003epoint\u003c/i\u003e, \u003ci\u003eline\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/relationships/pointOnLine.js#L13 \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-pointleftofline-geometric-pointrightofline-g \"Example\")\n\nReturns a boolean representing whether a \u003ci\u003epoint\u003c/i\u003e is to the right of a \u003ci\u003eline\u003c/i\u003e.\n\n\u003ca name=\"polygonInPolygon\" href=\"#polygonInPolygon\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonInPolygon\u003c/b\u003e(\u003ci\u003epolygonA\u003c/i\u003e, \u003ci\u003epolygonB\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/relationships/polygonInPolygon.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygoninpolygon \"Example\")\n\nReturns a boolean representing whether \u003ci\u003epolygonA\u003c/i\u003e is contained by \u003ci\u003epolygonB\u003c/i\u003e.\n\n\u003ca name=\"polygonIntersectsPolygon\" href=\"#polygonIntersectsPolygon\"\u003e#\u003c/a\u003e geometric.\u003cb\u003epolygonIntersectsPolygon\u003c/b\u003e(\u003ci\u003epolygonA\u003c/i\u003e, \u003ci\u003epolygonB\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/relationships/polygonIntersectsPolygon.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-polygonintersectspolygon \"Example\")\n\nReturns a boolean representing whether \u003ci\u003epolygonA\u003c/i\u003e intersects but is not contained by \u003ci\u003epolygonB\u003c/i\u003e.\n\n\u003chr /\u003e\n\n### Angles\n\n\u003ca name=\"angleReflect\" href=\"#angleReflect\"\u003e#\u003c/a\u003e geometric.\u003cb\u003eangleReflect\u003c/b\u003e(\u003ci\u003eincidence\u003c/i\u003e, \u003ci\u003esurface\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/angles/angleReflect.js \"Source\"), [Example](https://observablehq.com/@harrystevens/geometric-anglereflect \"Example\")\n\nReturns the angle of reflection given a starting angle, also known as the angle of \u003ci\u003eincidence\u003c/i\u003e, and the angle of the \u003ci\u003esurface\u003c/i\u003e off of which it is reflected.\n\n\u003ca name=\"angleToDegrees\" href=\"#angleToDegrees\"\u003e#\u003c/a\u003e geometric.\u003cb\u003eangleToDegrees\u003c/b\u003e(\u003ci\u003eangle\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/angles/angleToDegrees.js \"Source\")\n\nReturns the result of converting an \u003ci\u003eangle\u003c/i\u003e in radians to the same angle in degrees.\n\n\u003ca name=\"angleToRadians\" href=\"#angleToRadians\"\u003e#\u003c/a\u003e geometric.\u003cb\u003eangleToRadians\u003c/b\u003e(\u003ci\u003eangle\u003c/i\u003e) · [Source](https://github.com/HarryStevens/geometric/blob/master/src/angles/angleToRadians.js \"Source\")\n\nReturns the result of converting an \u003ci\u003eangle\u003c/i\u003e in degrees to the same angle in radians.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHarryStevens%2Fgeometric","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHarryStevens%2Fgeometric","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHarryStevens%2Fgeometric/lists"}