Documentation ¶
Index ¶
- Constants
- Variables
- func ConvexHull(pts ...d2.Pt) []d2.Pt
- func GetTriangles(triangles [][3]uint32, p Polygon) []*triangle.Triangle
- func GrahamScan(pts ...d2.Pt) []d2.Pt
- type AssertConvexHull
- type AssertConvexHuller
- type Collision
- type Collisions
- type ConcavePolygon
- func (c ConcavePolygon) Area() float64
- func (c ConcavePolygon) Centroid() d2.Pt
- func (c ConcavePolygon) Contains(f d2.Pt) bool
- func (c ConcavePolygon) Perimeter() float64
- func (c ConcavePolygon) Pt1(t0 float64) d2.Pt
- func (c ConcavePolygon) Pt2(t0, t1 float64) d2.Pt
- func (c ConcavePolygon) SignedArea() float64
- type ConvexHuller
- type ErrNotConvex
- type LLNode
- type LLPolygon
- type PolarPolygon
- type Polygon
- func New(pts []d2.Pt) Polygon
- func RectanglePointWidthLength(pt d2.Pt, v d2.V) Polygon
- func RectangleTwoPoints(p1, p2 d2.Pt) Polygon
- func RegularPolygonRadius(center d2.Pt, radius float64, a angle.Rad, sides int) Polygon
- func RegularPolygonSideLength(center d2.Pt, sideLength float64, a angle.Rad, sides int) Polygon
- func (p Polygon) Area() float64
- func (p Polygon) BoundingBox() (min, max d2.Pt)
- func (p Polygon) Centroid() d2.Pt
- func (p Polygon) Collision(lineSegment line.Line) (lineT float64, idx int, sideT float64)
- func (p Polygon) Contains(pt d2.Pt) bool
- func (p Polygon) Convex() bool
- func (p Polygon) ConvexHull() []d2.Pt
- func (p Polygon) CountAngles(out []int) (ccw int, cw int)
- func (p Polygon) FindTriangles() [][3]uint32
- func (p Polygon) LineIntersections(ln line.Line, buf []float64) []float64
- func (p Polygon) NonIntersecting() bool
- func (p Polygon) Perimeter() float64
- func (p Polygon) PolygonCollisions(p2 Polygon) Collisions
- func (p Polygon) Pt1(t0 float64) d2.Pt
- func (p Polygon) Pt2(t0, t1 float64) d2.Pt
- func (p Polygon) Pt2c1(t0 float64) d2.Pt1
- func (p Polygon) Reverse() Polygon
- func (p Polygon) Side(n int) line.Line
- func (p Polygon) Sides() []line.Line
- func (p Polygon) SignedArea() float64
- func (p Polygon) String() string
Constants ¶
const ( // Tau constant Tau = math.Pi * 2 // Pi constant Pi = math.Pi )
Variables ¶
var GrahamTolerance = cmpr.Tolerance(1e-7)
GrahamTolerance is the deviation from 0 of a cross product that will still be treated as 0.
Functions ¶
func ConvexHull ¶
ConvexHull is currently a wrapper around GrahamScan. A more efficient algorithm may be added later.
func GetTriangles ¶
GetTriangles takes triangle indexes from FindTriangles and returns a slice of triangles. This can be used to map one polygon to another with the same number of sides.
func GrahamScan ¶
GrahamScan: https://en.wikipedia.org/wiki/Graham_scan Finds the convex hull of a set of points in O(n log n).
Types ¶
type AssertConvexHull ¶
AssertConvexHull fulfills geomtest.AssertEqualizer. It is a list of points. Given a convex hull, it checks that the hull is convex and contains all the points in it's list.
func (AssertConvexHull) AssertEqual ¶
func (a AssertConvexHull) AssertEqual(actual interface{}, t cmpr.Tolerance) error
AssertEqual fulfills geomtest.AssertEqualizer. It checks that actual is a slice of points that form a convex hull containing all the points in AssertConvexHull.
type AssertConvexHuller ¶
AssertConvexHuller fulfills geomtest.AssertEqualizer. It is a list of points. Given an interface that fulfills ConvexHuller, it checks that the hull is convex and contains all the points in it's list.
func (AssertConvexHuller) AssertEqual ¶
func (a AssertConvexHuller) AssertEqual(actual interface{}, t cmpr.Tolerance) error
AssertEqual fulfills geomtest.AssertEqualizer. It check that actual is an an instance of ConvexHuller and the ConvexHull returned is convex and contains all the points in AssertConvexHuller.
type Collision ¶
Collision between two polygons
type Collisions ¶
type Collisions []Collision
Collisions represent a set of collisions between two polygons.
type ConcavePolygon ¶
type ConcavePolygon struct {
// contains filtered or unexported fields
}
ConcavePolygon represents a Polygon with at least one concave angle.
func NewConcavePolygon ¶
func NewConcavePolygon(concave Polygon) ConcavePolygon
NewConcavePolygon converts a Polygon to a ConcavePolygon
func (ConcavePolygon) Centroid ¶
func (c ConcavePolygon) Centroid() d2.Pt
Centroid returns the center of mass of the polygon
func (ConcavePolygon) Contains ¶
func (c ConcavePolygon) Contains(f d2.Pt) bool
Contains returns true of the point f is inside of the polygon
func (ConcavePolygon) Perimeter ¶
func (c ConcavePolygon) Perimeter() float64
Perimeter returns the total length of the perimeter
func (ConcavePolygon) Pt1 ¶
func (c ConcavePolygon) Pt1(t0 float64) d2.Pt
Pt1 returns a point on the perimeter
func (ConcavePolygon) Pt2 ¶
func (c ConcavePolygon) Pt2(t0, t1 float64) d2.Pt
Pt2 returns a point in the ConcavePolygon adhereing to the shape rules
func (ConcavePolygon) SignedArea ¶
func (c ConcavePolygon) SignedArea() float64
SignedArea returns the Area and may be negative depending on the polarity.
type ConvexHuller ¶
ConvexHuller is taken from shape.ConvexHuller to avoid cyclic imports.
type ErrNotConvex ¶
type ErrNotConvex struct{}
ErrNotConvex is return if a convex hull is not actually convex.
func (ErrNotConvex) Error ¶
func (ErrNotConvex) Error() string
Error fulfills error and returns the string "hull is not convex"
type LLPolygon ¶
LLPolygon represents a polygon as a linked list stored in a slice. Start can be any index that is in the list. The list should be circular. This is useful when adding and removing vertexes in an algorithm.
func (*LLPolygon) ConvexHull ¶
ConvexHull fulfills shape.ConvexHuller. Returns the convex hull of the polygon using the ConvexHull function.
type PolarPolygon ¶
PolarPolygon is useful in constructing a Polygon when the order of the vertexes is not known. It does not fulfill shape.
func NewPolar ¶
func NewPolar(pts []d2.Pt) (polarPolygon PolarPolygon, center d2.Pt)
Create a new PolarPolygon from a set of points. The result will be translated so the center is (0,0) and the previous center returned.
func (PolarPolygon) Len ¶
func (p PolarPolygon) Len() int
Len returns the number of points, fulfills sort.Interface
type Polygon ¶
Polygon represents a Convex Polygon
func RectanglePointWidthLength ¶
RectanglePointWidthLength takes a point and a vector and returns a rectangle
func RectangleTwoPoints ¶
RectangleTwoPoints takes two points and returns a Polygon representing a rectangle.
func RegularPolygonRadius ¶
RegularPolygonRadius constructs a regular polygon. The radius is measured from the center of each side.
func RegularPolygonSideLength ¶
RegularPolygonSideLength constructs a regular polygon defined by the length of the sides.
func (Polygon) BoundingBox ¶
BoundingBox fulfills BoundingBoxer returning a box that contains the polygon.
func (Polygon) Collision ¶
Collision returns the first side that is intersected by the given lineSegment, returning the parametic t for the lineSegment, the index of the side and the parametric t of the side
func (Polygon) Contains ¶
Contains returns true of the point f is inside of the polygon. This is done with the winding number algorithm and runs in O(n).
func (Polygon) ConvexHull ¶
ConvexHull fulfills shape.ConvexHuller. Returns the convex hull of the polygon using the ConvexHull function.
func (Polygon) CountAngles ¶
CountAngles returns the number of counter clockwise and clockwise angles. If ccwOut or cwOut is not nil, they will be populated with the indexes of the verticies
func (Polygon) FindTriangles ¶
FindTriangles returns the index sets of the polygon broken up into triangles. Given a unit square it would return [[0,1,2], [0,2,3]] which means that the square can be broken up in to 2 triangles formed by the points at those indexes.
func (Polygon) LineIntersections ¶
LineIntersections fulfills line.LineIntersector
func (Polygon) NonIntersecting ¶
NonIntersecting returns false if any two sides intersect. This requires O(N^2) time to check.
func (Polygon) PolygonCollisions ¶
func (p Polygon) PolygonCollisions(p2 Polygon) Collisions
PolygonIntersections finds the intersection points between two polygons.
func (Polygon) SignedArea ¶
SignedArea returns the Area and may be negative depending on the polarity.