new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

D3 · all subjects

d3-polygon

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

d3-polygon module overview

d3-polygon provides geometric operations for two-dimensional polygons, including functions to compute area, centroid, convex hull, perimeter length, and test point containment.

d3-polygon operations

Polygon operations: d3.polygonArea (compute area), d3.polygonCentroid (compute centroid), d3.polygonHull (compute convex hull), d3.polygonContains (test point inside polygon), d3.polygonLength (compute perimeter length).

polygonArea signature and behavior

polygonArea(polygon) returns the signed area of a polygon represented as an array of [x, y] coordinate pairs. If vertices are in counterclockwise order (assuming origin at top-left), the returned area is positive; otherwise negative or zero. Example: d3.polygonArea([[1, 1], [1.5, 0], [2, 1]]) returns -0.5.

polygonCentroid signature and behavior

polygonCentroid(polygon) returns the centroid of a polygon represented as an array of [x, y] coordinate pairs. The centroid is returned as a [x, y] coordinate. Example: d3.polygonCentroid([[1, 1], [1.5, 0], [2, 1]]) returns [1.5, 0.6666666666666666].

polygonHull signature and algorithm

polygonHull(points) returns the convex hull of the specified points using Andrew's monotone chain algorithm. The returned hull is an array containing a subset of input points arranged in counterclockwise order. Returns null if points has fewer than three elements.

polygonContains signature and behavior

polygonContains(polygon, point) returns true if and only if the specified point (as [x, y] coordinates) is inside the specified polygon. Example: d3.polygonContains([[1, 1], [1.5, 0], [2, 1]], [1.5, 0.667]) returns true.

polygonLength signature and behavior

polygonLength(polygon) returns the length of the perimeter of the specified polygon represented as an array of [x, y] coordinate pairs. Example: d3.polygonLength([[1, 1], [1.5, 0], [2, 1]]) returns 3.23606797749979.

Polygon representation format

Polygons in d3-polygon are represented as arrays of two-element arrays [[x0, y0], [x1, y1], …]. Polygons may be closed (first and last points are the same) or open (they are different). Typically polygons are in counterclockwise order, assuming a coordinate system where the origin is in the top-left corner.

Give your agent this brain