Class Polygon2
Defined in: lina.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Polygon2(xyList)
Create a new 2d polygon.
|
Method Attributes | Method Name and Description |
---|---|
append(ptOrPg)
Append a point or polygon.
|
|
appendUnique(ptOrPg, eps)
Append a point or polygon, discarding duplicate points.
|
|
area()
Return polygons area.
|
|
contains(pt)
Check, if pt is inside this polygon.
|
|
copy()
Create and return a copy of this polygon.
|
|
count()
Return number of points.
|
|
getBoundingBox(forceRecalc)
Return the bounding box as {min: {x:_,y:_}, max: {x:_,y:_}}.
|
|
Return the smallest bounding circle.
|
|
Return a new polygon that connects the extreme points of this polygon.
|
|
getPoint(idx)
Return polygon point by index.
|
|
getSegment(idx)
Return polygon edge by index.
|
|
Return a new polygon that draws along the outer lines of this polygon.
|
|
getUniquePoints(eps)
Return a copy with duplicate points removed.
|
|
getXY(idx)
Return polygon point by index.
|
|
Find index of point with minimmum y coord (and minimum x, if multiple
matches found).
|
|
intersects(pg2, velocity, time)
Check, if this polygon intersects with another polygon.
|
|
intersectsCircle(circle, velocity, time)
Check, if this polygon intersects with a (moving) circle.
|
|
isCCW()
Check, if this polygon has a counterclocwise vertex order.
|
|
makeCCW()
Make sure this polygon has a counterclocwise vertex order.
|
|
makeCW()
Make sure this polygon has a clocwise vertex order.
|
|
makeFirst(idx)
Reorder polygon to start with given index.
|
|
nearestPt(pt, cullingVector)
Return polygon point nearest to pt.
|
|
perimeter(closed)
Return the total length of all line segments.
|
|
remove(idx)
Remove point at index.
|
|
revert()
Revert vertex list (in-place) and return this instance.
|
|
<static> |
Polygon2.revert(pg)
Return a reverse copy of a polygon.
|
segmentIntersects(pt1, pt2)
Check, if line segment pt1, pt2 is inside this polygon.
|
|
set(xyList)
|
|
setCount(n)
Set maximum number of points (truncating trailing points).
|
|
swap(idx, idx2)
Exchange points.
|
|
toString(prec)
Return string representation '[(x1,y1), (x2,y2), .
|
|
<static> |
Polygon2.transform(pg, m)
Return a transformed copy of a polygon.
|
transform(m)
Apply transformation matrix (in-place) and return this instance.
|
Method Detail
append(ptOrPg)
Append a point or polygon.
- Returns:
- this
appendUnique(ptOrPg, eps)
Append a point or polygon, discarding duplicate points.
- Returns:
- this
area()
Return polygons area.
This assumes an implicitly closed, non self-intersecting polygon.
contains(pt)
Check, if pt is inside this polygon.
- Parameters:
- pt
copy()
Create and return a copy of this polygon.
count()
Return number of points.
getBoundingBox(forceRecalc)
Return the bounding box as {min: {x:_,y:_}, max: {x:_,y:_}}.
- Parameters:
- forceRecalc
getBoundingCircle()
Return the smallest bounding circle.
getConvexHull()
Return a new polygon that connects the extreme points of this polygon.
The result will be convex, non-intersecting.
This bounding polygon has typically less points, and my be used for faster
collision testing.
This polygon is treated as unconnected point cloud, so it is possible to
get a bounding polygon of multiple objects like this:
var pgHull = pg1.copy().append(pg2).append(pg3).getConvexHull();
getPoint(idx)
Return polygon point by index.
- Parameters:
- {int} idx
- Returns:
- Point2
{x0:_|y0:_|x1:_|y1:_}
getSegment(idx)
Return polygon edge by index.
If idx == last then the closing edge is returned.
- Parameters:
- {int} idx
- Index of first point
- Returns:
- {x0:_|y0:_|x1:_|y1:_}
getShapePolygon()
Return a new polygon that draws along the outer lines of this polygon.
getUniquePoints(eps)
Return a copy with duplicate points removed.
- Parameters:
- {float} eps
- (optional) defaults to LinaJS.EPS
- Returns:
- new Polygon2
{x:_|y:_}
getXY(idx)
Return polygon point by index.
- Parameters:
- {int} idx
- Returns:
- {x:_|y:_}
indexOfLowestPoint()
Find index of point with minimmum y coord (and minimum x, if multiple
matches found).
intersects(pg2, velocity, time)
Check, if this polygon intersects with another polygon.
- Parameters:
- pg2
- velocity
- time
intersectsCircle(circle, velocity, time)
Check, if this polygon intersects with a (moving) circle.
In case of a collision some additional information is calculated.
- Parameters:
- {Circle2} circle
- {Vec2} velocity
- Relative speed in units per second (assuming this polygon is static)
- {float} time
- seconds to look ahead (e.g. 1/30s for one frame step). Default: 1
- Returns:
- false, if no intersection, otherwise {...}
isCCW()
Check, if this polygon has a counterclocwise vertex order.
makeCCW()
Make sure this polygon has a counterclocwise vertex order.
makeCW()
Make sure this polygon has a clocwise vertex order.
makeFirst(idx)
Reorder polygon to start with given index.
- Parameters:
- {int} idx
- Returns:
- this
nearestPt(pt, cullingVector)
Return polygon point nearest to pt.
- Parameters:
- {Point2} pt
- {Vec2} cullingVector
- (optional) If we pass a velocity vector here, CCW oriented polygons will only consider objects aproaching from the outside.
perimeter(closed)
Return the total length of all line segments.
- Parameters:
- {boolean} closed
- Include implicit closing segment (default: true).
remove(idx)
Remove point at index.
- Parameters:
- {int} idx
- Returns:
- this
revert()
Revert vertex list (in-place) and return this instance.
<static>
Polygon2.revert(pg)
Return a reverse copy of a polygon.
- Parameters:
- pg
segmentIntersects(pt1, pt2)
Check, if line segment pt1, pt2 is inside this polygon.
- Parameters:
- pt1
- pt2
set(xyList)
- Parameters:
- xyList
setCount(n)
Set maximum number of points (truncating trailing points).
- Parameters:
- n
swap(idx, idx2)
Exchange points.
- Parameters:
- {int} idx
- idx2
- Returns:
- this
toString(prec)
Return string representation '[(x1,y1), (x2,y2), ...]'.
- Parameters:
- prec
<static>
Polygon2.transform(pg, m)
Return a transformed copy of a polygon.
- Parameters:
- pg
- m
transform(m)
Apply transformation matrix (in-place) and return this instance.
- Parameters:
- m