geom

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 8 Imported by: 11

Documentation

Overview

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Package geom has geometry related structs and funcs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AngleFromTriangleSideLengths added in v0.4.9

func AngleFromTriangleSideLengths(a, b, c float64) float64

AngleFromTriangleSideLengths returns one angle of a triangle where the lengths of each side are known. It returns the angle between a and b.

func BezLength added in v0.5.9

func BezLength(p0, p1, p2, p3 *Point, count float64) float64

BezLength returns the length of a bezier curve. count is how many segments the curve will be sliced into. The higher the count, the more accurate. 1000 is a decent start.

func CircleOnCircle

func CircleOnCircle(x0, y0, r0, x1, y1, r1 float64) bool

CircleOnCircle returns whether or not two circles intersect. TODO: return the points of intersection.

func CircleToLine

func CircleToLine(x0, y0, x1, y1, cx, cy, r float64) (*Point, *Point, bool)

CircleToLine reports the points of intersection between a line and a circle.

func Clockwise

func Clockwise(p1, p2, p3 *Point) bool

Clockwise returns whether or not the three points listed are in clockwise order

func LineOnLine

func LineOnLine(x0, y0, x1, y1, x2, y2, x3, y3 float64) (float64, float64, bool)

LineOnLine returns whether or not two infinite length lines intersect and the point they intersect if they do.

func PointDistanceToLine

func PointDistanceToLine(px, py, x0, y0, x1, y1 float64) float64

PointDistanceToLine reports the distance from a point to a line.

func PointDistanceToSegment

func PointDistanceToSegment(px, py, x0, y0, x1, y1 float64) float64

PointDistanceToSegment reports the distance from a point to a line segment

func PointInCircle

func PointInCircle(x, y, cx, cy, cr float64) bool

PointInCircle returns whether or not a point is within a circle.

func PointInPolygon

func PointInPolygon(x, y float64, points []float64) bool

PointInPolygon returns whether or not a point is within a polygon.

func PointInRect

func PointInRect(x, y, rx, ry, rw, rh float64) bool

PointInRect returns whether or not a point is within a rectangle.

func PolyInnerRadius added in v0.4.12

func PolyInnerRadius(radius float64, sides int) float64

PolyInnerRadius returns the radius of the largest circle that can fit inside the given regular polygon.

func RectOnRect

func RectOnRect(x0, y0, w0, h0, x1, y1, w1, h1 float64) bool

RectOnRect returns whether or not two rectangles intersect. TODO: return the rect of intersection.

func SegmentOnLine

func SegmentOnLine(x0, y0, x1, y1, x2, y2, x3, y3 float64) (float64, float64, bool)

SegmentOnLine returns whether or not a segment intersects an infinite length line and returns the point it intersects if it does. x0, y0 -> x1, y1 = segment. x2, y2 -> x3, y3 = line

func SegmentOnRect

func SegmentOnRect(x0, y0, x1, y1, rx, ry, rw, rh float64) bool

SegmentOnRect returns whether or not a segment intersects a rectangle. TODO: return the points of intersection.

func SegmentOnSegment

func SegmentOnSegment(x0, y0, x1, y1, x2, y2, x3, y3 float64) (float64, float64, bool)

SegmentOnSegment returns whether or not two line segments intersect and the point they intersect if they do.

Types

type BezierCurve added in v0.6.0

type BezierCurve struct {
	P0, P1, P2, P3 *Point
	// contains filtered or unexported fields
}

BezierCurve represents a Bezier curve.

func NewBezierCurve added in v0.6.0

func NewBezierCurve(p0, p1, p2, p3 *Point) *BezierCurve

NewBezierCurve creates a new BezierCurve object.

func (*BezierCurve) GetPath added in v0.6.0

func (b *BezierCurve) GetPath() PointList

GetPath returns the point list representing this path.

func (*BezierCurve) GetSegmentCount added in v0.6.0

func (b *BezierCurve) GetSegmentCount() int

GetSegmentCount returns the current segment count.

func (*BezierCurve) LerpPoint added in v0.6.0

func (b *BezierCurve) LerpPoint(t float64) *Point

LerpPoint returns a linearly interpolated point along the BezierCurve.

func (*BezierCurve) LinearPoints added in v0.6.0

func (b *BezierCurve) LinearPoints(count int) PointList

LinearPoints creates a list of points roughly evenly distributed along the curve.

func (*BezierCurve) Point added in v0.6.0

func (b *BezierCurve) Point(t float64) *Point

Point returns a point on the curve interpolated from t = 0.0 to 1.0.

func (*BezierCurve) SetSegmentCount added in v0.6.0

func (b *BezierCurve) SetSegmentCount(count int)

SetSegmentCount sets the count of segments to use in a path of this curve, recreates path.

func (*BezierCurve) SlopeAtBezierT added in v0.6.0

func (b *BezierCurve) SlopeAtBezierT(t float64) float64

SlopeAtBezierT returns the slope at a given t value of the Bezier curve.

func (*BezierCurve) SlopeAtLinearT added in v0.6.0

func (b *BezierCurve) SlopeAtLinearT(t float64) float64

SlopeAtLinearT returns the slope at a given linearly interpolated point.

type Circle

type Circle struct {
	X, Y, Radius float64
}

Circle is the struct representing a circle.

func CircleThroughPointsWithArcHeight

func CircleThroughPointsWithArcHeight(x0, y0, x1, y1, height float64) (*Circle, error)

CircleThroughPointsWithArcHeight returns the circle that passes through the two points and creates an arc of the given height through those points.

func CircleTouchingCircle added in v0.4.9

func CircleTouchingCircle(c0 *Circle, angle, radius float64) *Circle

CircleTouchingCircle returns a new circle that exactly touches another circle at a given angle.

func CircleTouchingTwoCircles added in v0.4.9

func CircleTouchingTwoCircles(c0, c1 *Circle, radius float64, clockwise bool) *Circle

CircleTouchingTwoCircles returns a new circle that exactly touches the other two circles.

func NewCircle

func NewCircle(x, y, r float64) *Circle

NewCircle creates a new circle struct.

func NewCircleFromPoint

func NewCircleFromPoint(center *Point, r float64) *Circle

NewCircleFromPoint creates a new circle struct using a Point object as center.

func NewCircleFromPoints added in v0.5.7

func NewCircleFromPoints(p0, p1, p2 *Point) *Circle

NewCircleFromPoints returns a new circle that intersects the three given points. If the points are collinear, it will return nil.

func (*Circle) Contains

func (c *Circle) Contains(p *Point) bool

Contains reports whether a point is within this circle.

func (*Circle) Hit

func (c *Circle) Hit(d *Circle) bool

Hit reports whether this circle intersects another circle.

func (*Circle) InnerCircles added in v0.5.2

func (c *Circle) InnerCircles(count int, rotation float64) CircleList

InnerCircles returns a slice of circles arrange around the inside of the given circle.

func (*Circle) Intersection

func (c *Circle) Intersection(c1 *Circle) (*Point, *Point, bool)

Intersection returns the points of intersection (if any) with another circles and a bool indicating whether or not they intersect at all.

func (*Circle) InvertPoint

func (c *Circle) InvertPoint(p *Point) *Point

InvertPoint inverts a point into our out of a circle.

func (*Circle) InvertXY

func (c *Circle) InvertXY(x, y float64) (float64, float64)

InvertXY inverts a point into our out of a circle.

func (*Circle) OuterCircles added in v0.5.2

func (c *Circle) OuterCircles(count int, rotation float64) CircleList

OuterCircles returns a slice of circles arrange around the outside of the given circle.

func (*Circle) RandomizePosition added in v0.5.2

func (c *Circle) RandomizePosition(amount float64)

RandomizePosition randomizes the position of this triangle

func (*Circle) RandomizeRadius added in v0.5.2

func (c *Circle) RandomizeRadius(amount float64)

RandomizeRadius randomizes the radius of this triangle

func (*Circle) RandomizedPosition added in v0.5.2

func (c *Circle) RandomizedPosition(amount float64) *Circle

RandomizedPosition returns a new circle with a randomized position.

func (*Circle) RandomizedRadius added in v0.5.2

func (c *Circle) RandomizedRadius(amount float64) *Circle

RandomizedRadius returns a new circle with a randomized radius.

func (*Circle) Rotate added in v0.4.13

func (c *Circle) Rotate(angle float64)

Rotate rotates a circle around the origin.

func (*Circle) RotateFrom added in v0.4.13

func (c *Circle) RotateFrom(x, y float64, angle float64)

RotateFrom rotates a circle around the given x, y location.

func (*Circle) Rotated added in v0.5.2

func (c *Circle) Rotated(angle float64) *Circle

Rotated returns a new circle rotated.

func (*Circle) RotatedFrom added in v0.5.2

func (c *Circle) RotatedFrom(x, y, angle float64) *Circle

RotatedFrom returns a new circle rotated.

func (*Circle) Scale added in v0.4.13

func (c *Circle) Scale(scale float64)

Scale scales this circle on the x and y axes, as well as its size.

func (*Circle) ScaleFrom added in v0.4.13

func (c *Circle) ScaleFrom(x, y, scale float64)

ScaleFrom scales this circle on the x and y axes, with the given x, y location as a center.

func (*Circle) ScaleLocal added in v0.5.2

func (c *Circle) ScaleLocal(scale float64)

ScaleLocal scales this circle's radius only.

func (*Circle) Scaled added in v0.5.2

func (c *Circle) Scaled(scale float64) *Circle

Scaled returns a new circle scaled.

func (*Circle) ScaledFrom added in v0.5.2

func (c *Circle) ScaledFrom(x, y, scale float64) *Circle

ScaledFrom returns a new circle scaled.

func (*Circle) ScaledLocal added in v0.5.2

func (c *Circle) ScaledLocal(scale float64) *Circle

ScaledLocal returns a new circle scaled.

func (*Circle) Translate added in v0.4.13

func (c *Circle) Translate(x float64, y float64)

Translate moves this circle on the x and y axes.

func (*Circle) Translated added in v0.5.2

func (c *Circle) Translated(tx, ty float64) *Circle

Translated returns a new circle translated.

type CircleList added in v0.4.13

type CircleList []*Circle

CircleList is a slice of circles

func NewCircleList added in v0.4.13

func NewCircleList() CircleList

NewCircleList creates a new circle list

func (*CircleList) Add added in v0.4.13

func (c *CircleList) Add(circle *Circle)

Add adds a circle to the list

func (*CircleList) AddXY added in v0.4.13

func (c *CircleList) AddXY(x, y, r float64)

AddXY adds a circle to the list

func (*CircleList) RandomizePosition added in v0.5.2

func (c *CircleList) RandomizePosition(amount float64)

RandomizePosition randomizes the position of all the circles in a list.

func (*CircleList) RandomizeRadius added in v0.5.2

func (c *CircleList) RandomizeRadius(amount float64)

RandomizeRadius randomizes the position of all the circles in a list.

func (*CircleList) Rotate added in v0.4.13

func (c *CircleList) Rotate(angle float64)

Rotate rotates all the circles in a list.

func (*CircleList) RotateFrom added in v0.4.13

func (c *CircleList) RotateFrom(x, y float64, angle float64)

RotateFrom rotates all the circles in a list using the x, y location as a center.

func (*CircleList) Scale added in v0.4.13

func (c *CircleList) Scale(scale float64)

Scale scales all the circles in a list.

func (*CircleList) ScaleFrom added in v0.4.13

func (c *CircleList) ScaleFrom(x, y, scale float64)

ScaleFrom scales all the circles in a list using the x, y location as a center.

func (*CircleList) ScaleLocal added in v0.5.2

func (c *CircleList) ScaleLocal(scale float64)

ScaleLocal scales all the circles in a list.

func (*CircleList) Translate added in v0.4.13

func (c *CircleList) Translate(x, y float64)

Translate translates all the circles in a list.

type Line

type Line Segment

Line is the same as a segment, but we'll keep them separate for collision purposes

func NewLine

func NewLine(x0, y0, x1, y1 float64) *Line

NewLine creates a new line.

func NewLineFromPoints

func NewLineFromPoints(p0, p1 *Point) *Line

NewLineFromPoints creates a new line from two Points.

func NewLineFromSegment added in v0.5.7

func NewLineFromSegment(seg *Segment) *Line

NewLineFromSegment creates a new line from an existing Segment.

func (*Line) Angle added in v0.4.11

func (l *Line) Angle() float64

Angle returns the angle of rthis line (from the first point to the second)

func (*Line) ClosestPoint

func (l *Line) ClosestPoint(p *Point) *Point

ClosestPoint reports the point on a line closest to another given point.

func (*Line) DistanceTo

func (l *Line) DistanceTo(p *Point) float64

DistanceTo reports the distance from a given point to this line.

func (*Line) HitLine

func (l *Line) HitLine(m *Line) (float64, float64, bool)

HitLine reports the point of intersection of two lines.

func (*Line) HitSegment

func (l *Line) HitSegment(s *Segment) (float64, float64, bool)

HitSegment reports the point of intersection of a line and a line segment.

func (*Line) Parallel added in v0.4.11

func (l *Line) Parallel(dist float64) *Line

Parallel returns a line parallel to this line, at a certain distance.

func (*Line) Perpendicular

func (l *Line) Perpendicular(p *Point) *Line

Perpendicular returns a line that is perpendicular to the line and crosses through the given point.

type Point

type Point struct {
	X, Y float64
}

Point is the structure representing a 2D point.

func BezierPoint

func BezierPoint(t float64, p0 *Point, p1 *Point, p2 *Point, p3 *Point) *Point

BezierPoint calculates a point along a Bezier curve.

func Bisect added in v0.5.7

func Bisect(pA, pB, pC *Point, length float64) *Point

Bisect returns a point that will bisect the angle formed by the three points passed in.

func LerpPoint

func LerpPoint(t float64, p0, p1 *Point) *Point

LerpPoint linearly interpolates between two points.

func MidPoint

func MidPoint(p0, p1 *Point) *Point

MidPoint returns a point exactly midway between two points.

func NewPoint

func NewPoint(x, y float64) *Point

NewPoint creates a new point.

func QuadraticPoint

func QuadraticPoint(t float64, p0 *Point, p1 *Point, p2 *Point) *Point

QuadraticPoint calculated a point along a quadratic Bezier curve.

func RandomPointInCircle

func RandomPointInCircle(x, y, r float64, dist bool) *Point

RandomPointInCircle creates a random point within the defined circle. if dist is true, it will evenly distribute them in the circle.

func RandomPointInRect

func RandomPointInRect(x, y, w, h float64) *Point

RandomPointInRect creates a random point within the defined rectangle.

func RandomPointInTriangle

func RandomPointInTriangle(A, B, C *Point) *Point

RandomPointInTriangle returns a randomly generated point within the triangle described by the given points.

func (*Point) Angle

func (p *Point) Angle() float64

Angle returns the angle from the origin to this point.

func (*Point) AngleBetween added in v0.5.7

func (p *Point) AngleBetween(p0, p1 *Point) float64

AngleBetween returns the angle formed from p0 to this point to p1.

func (*Point) AngleTo

func (p *Point) AngleTo(o *Point) float64

AngleTo returns the angle from this point to another point.

func (*Point) Clone added in v0.5.4

func (p *Point) Clone() *Point

Clone returns a copy of this point.

func (*Point) Coords

func (p *Point) Coords() (float64, float64)

Coords returns the x, y coords of this point.

func (*Point) Distance

func (p *Point) Distance(p1 *Point) float64

Distance between this point and another point

func (*Point) Equals added in v0.5.0

func (p *Point) Equals(other *Point) bool

Equals returns whether this point is equal to another point.

func (*Point) Magnitude

func (p *Point) Magnitude() float64

Magnitude is distance from origin to this point

func (*Point) Normalize added in v0.5.5

func (p *Point) Normalize()

Normalize normalizes each component of this point, in place.

func (*Point) Normalized added in v0.5.5

func (p *Point) Normalized() *Point

Normalized returns a copy of this point, normalized.

func (*Point) Randomize added in v0.4.10

func (p *Point) Randomize(rx, ry float64)

Randomize randomizes this point.

func (*Point) Randomized added in v0.5.2

func (p *Point) Randomized(rx, ry float64) *Point

Randomized returns a new point, randomized from this.

func (*Point) Rotate

func (p *Point) Rotate(angle float64)

Rotate rotates this point around the origin.

func (*Point) RotateFrom added in v0.4.12

func (p *Point) RotateFrom(x, y float64, angle float64)

RotateFrom rotates this point around the the given x, y origin point.

func (*Point) Rotated added in v0.5.2

func (p *Point) Rotated(angle float64) *Point

Rotated creates a new point, a rotated version of this point.

func (*Point) RotatedFrom added in v0.5.2

func (p *Point) RotatedFrom(x, y, angle float64) *Point

RotatedFrom creates a new point, rotated from the given x, y location.

func (*Point) Scale

func (p *Point) Scale(scaleX float64, scaleY float64)

Scale scales this point on the x and y axes.

func (*Point) ScaleFrom added in v0.4.12

func (p *Point) ScaleFrom(x, y, scaleX float64, scaleY float64)

ScaleFrom scales this point on the x and y axes, with the given x, y location as a center.

func (*Point) Scaled

func (p *Point) Scaled(scaleX float64, scaleY float64) *Point

Scaled creates a new point, a scaled version of this point.

func (*Point) ScaledFrom added in v0.5.2

func (p *Point) ScaledFrom(x, y, scaleX, scaleY float64) *Point

ScaledFrom creates a new point, scaled from a given x, y location.

func (*Point) Translate

func (p *Point) Translate(x float64, y float64)

Translate moves this point on the x and y axes.

func (*Point) Translated added in v0.5.2

func (p *Point) Translated(tx, ty float64) *Point

Translated creates a new point, a translated version of this point.

func (*Point) UniScale

func (p *Point) UniScale(scale float64)

UniScale scales this point by the same amount on the x and y axes.

func (*Point) UniScaleFrom added in v0.4.13

func (p *Point) UniScaleFrom(x, y, scale float64)

UniScaleFrom scales this point by the same amount on the x and y axes, given the x, y location as a center

func (*Point) UniScaled

func (p *Point) UniScaled(scale float64) *Point

UniScaled creates a new point, a scaled version of this point.

func (*Point) UniScaledFrom added in v0.5.2

func (p *Point) UniScaledFrom(x, y, scale float64) *Point

UniScaledFrom creates a new point, scaled from a given x, y location.

type PointList

type PointList []*Point

PointList is a slice of Points

func ConvexHull

func ConvexHull(points PointList) PointList

ConvexHull returns a list of points that form a convex hull around the given set of points.

func LineOnRect

func LineOnRect(lineX1, lineY1, lineX2, lineY2, rectX, rectY, rectW, rectH float64) PointList

LineOnRect returns the points of intersection from a line to a rect (if any).

func LinearBezierPoints added in v0.5.9

func LinearBezierPoints(count int, p0, p1, p2, p3 *Point) PointList

LinearBezierPoints creates a list of points roughly evenly distributed along the curve.

func NewPointList

func NewPointList() PointList

NewPointList creates a new point list

func PointGrid added in v0.5.2

func PointGrid(x, y, w, h, xres, yres float64) PointList

PointGrid creats a list of points arranged in a grid.

func PoissonDiskSampling added in v0.4.11

func PoissonDiskSampling(x, y, width, height, radius float64, tries int) PointList

PoissonDiskSampling returns a poisson disk sampling of points

func RandomPointList added in v0.4.12

func RandomPointList(count int, x, y, w, h float64) PointList

RandomPointList returns a list of random points in a given rect.

func (*PointList) Add

func (p *PointList) Add(point *Point)

Add adds a point to the list

func (*PointList) AddXY

func (p *PointList) AddXY(x, y float64)

AddXY adds a point to the list

func (PointList) BoundingBox added in v0.5.8

func (p PointList) BoundingBox() *Rect

BoundingBox returns a rectangle enclosing all the points in the list.

func (PointList) Center added in v0.5.8

func (p PointList) Center() *Point

Center returns the local center of the points in the list.

func (PointList) Clone added in v0.5.2

func (p PointList) Clone() PointList

Clone returns a deep copy of this PointList.

func (*PointList) Cull added in v0.4.11

func (p *PointList) Cull(test func(*Point) bool)

Cull removes any points from the list that don't match the test.

func (PointList) Culled added in v0.5.5

func (p PointList) Culled(test func(*Point) bool) PointList

Culled returns a new point list of points from this list that match a test

func (PointList) First added in v0.5.0

func (p PointList) First() *Point

First gets the first point in this list

func (*PointList) Fisheye added in v0.5.8

func (p *PointList) Fisheye(radius float64)

Fisheye applies a fisheye transform from the center of the list.

func (*PointList) FisheyeFromPoint added in v0.5.8

func (p *PointList) FisheyeFromPoint(center *Point, radius float64)

FisheyeFromPoint applies a fisheye transform from the given point.

func (*PointList) FisheyeFromXY added in v0.5.8

func (p *PointList) FisheyeFromXY(x, y, radius float64)

FisheyeFromXY applies a fisheye transform from the given x, y location.

func (PointList) Get added in v0.5.3

func (p PointList) Get(index int) *Point

Get returns the point at the given index. If the index is negative, it counts from the end of the list.

func (*PointList) Insert added in v0.5.0

func (p *PointList) Insert(index int, point *Point) error

Insert inserts a point at the given index.

func (PointList) Interpolate added in v0.5.9

func (p PointList) Interpolate(t float64) *Point

Interpolate returns a point interpolated along the length of this path.

func (PointList) Last added in v0.5.0

func (p PointList) Last() *Point

Last gets the last point in this list

func (PointList) Length added in v0.5.8

func (p PointList) Length() float64

Length returns the measured length along the path created by the points.

func (*PointList) Noisified added in v0.5.5

func (p *PointList) Noisified(sx, sy, z, offset float64) PointList

Noisified warps the point locations with simplex noise

func (*PointList) Noisify added in v0.4.12

func (p *PointList) Noisify(sx, sy, z, offset float64)

Noisify warps the point locations with simplex noise

func (*PointList) Normalize added in v0.5.5

func (p *PointList) Normalize()

Normalize normalizes all the points in this list.

func (*PointList) Normalized added in v0.5.5

func (p *PointList) Normalized() PointList

Normalized normalizes all the points in this list.

func (*PointList) Randomize added in v0.4.9

func (p *PointList) Randomize(rx, ry float64)

Randomize randomizes all the points in a list.

func (*PointList) Randomized added in v0.5.5

func (p *PointList) Randomized(rx, ry float64) PointList

Randomized randomizes all the points in a list.

func (*PointList) Rotate added in v0.4.9

func (p *PointList) Rotate(angle float64)

Rotate rotates all the points in a list.

func (*PointList) RotateFrom added in v0.4.12

func (p *PointList) RotateFrom(x, y float64, angle float64)

RotateFrom rotates all the points in a list using the x, y location as a center.

func (*PointList) RotateLocal added in v0.5.8

func (p *PointList) RotateLocal(angle float64)

RotateLocal rotates all the points in a list from their local center.

func (*PointList) Rotated added in v0.5.5

func (p *PointList) Rotated(angle float64) PointList

Rotated rotates all the points in a list.

func (*PointList) RotatedFrom added in v0.5.5

func (p *PointList) RotatedFrom(x, y float64, angle float64) PointList

RotatedFrom rotates all the points in a list using the x, y location as a center.

func (*PointList) Scale added in v0.4.9

func (p *PointList) Scale(sx, sy float64)

Scale scales all the points in a list.

func (*PointList) ScaleFrom added in v0.4.12

func (p *PointList) ScaleFrom(x, y, sx, sy float64)

ScaleFrom scales all the points in a list using the x, y location as a center.

func (*PointList) ScaleLocal added in v0.5.8

func (p *PointList) ScaleLocal(sx, sy float64)

ScaleLocal scales all the points in a list using their local center.

func (*PointList) Scaled added in v0.5.5

func (p *PointList) Scaled(sx, sy float64) PointList

Scaled scales all the points in a list.

func (*PointList) ScaledFrom added in v0.5.5

func (p *PointList) ScaledFrom(x, y, sx, sy float64) PointList

ScaledFrom scales all the points in a list using the x, y location as a center.

func (PointList) SortDistFrom added in v0.5.2

func (p PointList) SortDistFrom(x, y float64) PointList

SortDistFrom sorts the list by the distance to a given x, y location

func (PointList) SortXY added in v0.5.2

func (p PointList) SortXY() PointList

SortXY sorts the list by x position, deciding matches with y

func (PointList) SortYX added in v0.5.2

func (p PointList) SortYX() PointList

SortYX sorts the list by y position, deciding matches with x

func (*PointList) Split added in v0.5.5

func (p *PointList) Split(test func(*Point) bool) PointList

Split removes any points from the list that do not match the test, and then returns those removed points as a new list.

func (*PointList) Translate added in v0.4.9

func (p *PointList) Translate(x, y float64)

Translate translates all the points in a list.

func (*PointList) Translated added in v0.5.5

func (p *PointList) Translated(x, y float64) PointList

Translated translates all the points in a list.

func (*PointList) UniScale added in v0.5.2

func (p *PointList) UniScale(scale float64)

UniScale scales all the points in a list.

func (*PointList) UniScaleFrom added in v0.5.2

func (p *PointList) UniScaleFrom(x, y, scale float64)

UniScaleFrom scales all the points in a list using the x, y location as a center.

func (*PointList) UniScaleLocal added in v0.5.8

func (p *PointList) UniScaleLocal(scale float64)

UniScaleLocal scales all the points in a list using their local center.

func (*PointList) UniScaled added in v0.5.5

func (p *PointList) UniScaled(scale float64) PointList

UniScaled scales all the points in a list.

func (*PointList) UniScaledFrom added in v0.5.5

func (p *PointList) UniScaledFrom(x, y, scale float64) PointList

UniScaledFrom scales all the points in a list using the x, y location as a center.

func (PointList) Unique added in v0.5.2

func (p PointList) Unique() PointList

Unique returns a new PointList with any duplicate points removed.

func (PointList) Uniqued added in v0.5.5

func (p PointList) Uniqued() PointList

Uniqued returns a new PointList with any duplicate points removed.

func (*PointList) Vortex added in v0.5.8

func (p *PointList) Vortex(radius float64)

Vortex applies a vortex transform from the given x, y location.

func (*PointList) VortexFromPoint added in v0.5.8

func (p *PointList) VortexFromPoint(center *Point, radius float64)

VortexFromPoint applies a vortex transform from the given point.

func (*PointList) VortexFromXY added in v0.5.8

func (p *PointList) VortexFromXY(x, y, radius float64)

VortexFromXY applies a vortex transform from the given x, y location.

type Rect

type Rect struct {
	X, Y, W, H float64
}

Rect represents a rectangle

func NewRect

func NewRect(x, y, w, h float64) *Rect

NewRect creates a new rectangle.

func NewRectFromPoints

func NewRectFromPoints(p0, p1 *Point) *Rect

NewRectFromPoints creates a new rectangle.

func (*Rect) Contains

func (r *Rect) Contains(p *Point) bool

Contains reports whether a point is in this rectangle.

func (*Rect) HitRect

func (r *Rect) HitRect(s *Rect) bool

HitRect reports whether or not another rectangle is intersecting this one.

func (*Rect) HitSegment

func (r *Rect) HitSegment(s *Segment) bool

HitSegment reports whether a line segment is interesecting this rectangle.

func (*Rect) Scaled

func (r *Rect) Scaled(factor float64) *Rect

Scaled returns a new rectangle, a scaled version of this rectangle.

type Segment

type Segment struct {
	PointA, PointB *Point
}

Segment represents a line segment.

func NewSegment

func NewSegment(x0, y0, x1, y1 float64) *Segment

NewSegment creates a new line segment.

func NewSegmentFromPoints

func NewSegmentFromPoints(p0, p1 *Point) *Segment

NewSegmentFromPoints creates a new line segment.

func TangentSegmentToCircles added in v0.4.10

func TangentSegmentToCircles(c0, c1 *Circle, sign float64) *Segment

TangentSegmentToCircles returns a line segment that forms a tangent to the two given circles. There can be two such segments. The sign parameter (positive or negative) allows you to choose which one.

func (*Segment) ClosestPoint

func (s *Segment) ClosestPoint(p *Point) *Point

ClosestPoint returns the point on this segment closest to another point.

func (*Segment) DistanceTo

func (s *Segment) DistanceTo(p *Point) float64

DistanceTo returns the distance from this segment to another point.

func (*Segment) Equals added in v0.5.0

func (s *Segment) Equals(other *Segment) bool

Equals returns whether or not this segment is roughly equal to another segment.

func (*Segment) HitLine

func (s *Segment) HitLine(l *Line) (float64, float64, bool)

HitLine returns the point of intersection between this and another line.

func (*Segment) HitRect

func (s *Segment) HitRect(r *Rect) bool

HitRect returns whether this segment intersects a rectangle.

func (*Segment) HitSegment

func (s *Segment) HitSegment(z *Segment) (float64, float64, bool)

HitSegment returns the point of intersection between this and another segment.

func (*Segment) Length

func (s *Segment) Length() float64

Length is the length of this segment.

func (*Segment) Parallel added in v0.5.7

func (s *Segment) Parallel(dist float64) *Line

Parallel returns a Line that is parallel to this line, a certain distance away.

func (*Segment) Points added in v0.5.7

func (s *Segment) Points() (*Point, *Point)

Points returns the two endpoints of this segment as Points.

func (*Segment) Randomize added in v0.5.2

func (s *Segment) Randomize(amount float64)

Randomize randomizes the endpoints of the segment by the given amount.

func (*Segment) Randomized added in v0.5.2

func (s *Segment) Randomized(amount float64) *Segment

Randomized returns a randomized segment from this segment.

func (*Segment) Rotate added in v0.5.2

func (s *Segment) Rotate(angle float64)

Rotate rotates a segment around the origin.

func (*Segment) RotateFrom added in v0.5.2

func (s *Segment) RotateFrom(x, y, angle float64)

RotateFrom rotates a segment around the given x, y location.

func (*Segment) RotateLocal added in v0.5.2

func (s *Segment) RotateLocal(angle float64)

RotateLocal rotates a segment around its own center.

func (*Segment) Rotated added in v0.5.2

func (s *Segment) Rotated(angle float64) *Segment

Rotated returns a new segment rotated from this.

func (*Segment) RotatedFrom added in v0.5.2

func (s *Segment) RotatedFrom(x, y, angle float64) *Segment

RotatedFrom returns a new segment rotated from this.

func (*Segment) RotatedLocal added in v0.5.2

func (s *Segment) RotatedLocal(angle float64) *Segment

RotatedLocal returns a new segment rotated from this.

func (*Segment) Scale added in v0.5.2

func (s *Segment) Scale(sx, sy float64)

Scale scales a segment the given amount on each axis.

func (*Segment) ScaleFrom added in v0.5.2

func (s *Segment) ScaleFrom(x, y, sx, sy float64)

ScaleFrom scales a segment the given amount on each axis, from the given x, y location.

func (*Segment) ScaleLocal added in v0.5.2

func (s *Segment) ScaleLocal(sx, sy float64)

ScaleLocal scales a segment the given amount on each axis from its own center

func (*Segment) Scaled added in v0.5.2

func (s *Segment) Scaled(sx, sy float64) *Segment

Scaled returns a new segment scaled by the given amount.

func (*Segment) ScaledFrom added in v0.5.2

func (s *Segment) ScaledFrom(x, y, sx, sy float64) *Segment

ScaledFrom returns a new segment scaled by the given amount.

func (*Segment) ScaledLocal added in v0.5.2

func (s *Segment) ScaledLocal(sx, sy float64) *Segment

ScaledLocal returns a new segment scaled by the given amount.

func (*Segment) Translate added in v0.5.2

func (s *Segment) Translate(x, y float64)

Translate translates a segment the given amount on each axis.

func (*Segment) Translated added in v0.5.2

func (s *Segment) Translated(x, y float64) *Segment

Translated returns a new segment translated from this.

func (*Segment) UniScale added in v0.5.2

func (s *Segment) UniScale(scale float64)

UniScale scales a segment the given amount on both axes equally.

func (*Segment) UniScaleFrom added in v0.5.2

func (s *Segment) UniScaleFrom(x, y, scale float64)

UniScaleFrom scales a segment using the x, y location as a center

func (*Segment) UniScaleLocal added in v0.5.2

func (s *Segment) UniScaleLocal(scale float64)

UniScaleLocal scales a segment the given amount on each axis.

func (*Segment) UniScaled added in v0.5.2

func (s *Segment) UniScaled(scale float64) *Segment

UniScaled returns a new segment scaled by the given amount - the same on both axes.

func (*Segment) UniScaledFrom added in v0.5.2

func (s *Segment) UniScaledFrom(x, y, scale float64) *Segment

UniScaledFrom returns a new segment scaled from the given point.

func (*Segment) UniScaledLocal added in v0.5.2

func (s *Segment) UniScaledLocal(scale float64) *Segment

UniScaledLocal returns a new segment scaled by the given amount - the same on both axes.

type SegmentList added in v0.5.2

type SegmentList []*Segment

SegmentList is a slice of segments

func NewSegmentList added in v0.5.2

func NewSegmentList() SegmentList

NewSegmentList creates a new segment list

func (*SegmentList) Add added in v0.5.2

func (s *SegmentList) Add(segment *Segment)

Add adds a segment to the list

func (*SegmentList) AddXY added in v0.5.2

func (s *SegmentList) AddXY(x0, y0, x1, y1 float64)

AddXY adds a segment to the list

func (*SegmentList) Noisify added in v0.5.9

func (s *SegmentList) Noisify(sx, sy, z, offset float64)

func (*SegmentList) Randomize added in v0.5.2

func (s *SegmentList) Randomize(amount float64)

Randomize randomizes the position of both ends of the segment by up to a given amount on each axis.

func (*SegmentList) Rotate added in v0.5.2

func (s *SegmentList) Rotate(angle float64)

Rotate rotates all the segments in a list.

func (*SegmentList) RotateFrom added in v0.5.2

func (s *SegmentList) RotateFrom(x, y float64, angle float64)

RotateFrom rotates all the segments in a list using the x, y location as a center.

func (*SegmentList) RotateLocal added in v0.5.2

func (s *SegmentList) RotateLocal(angle float64)

RotateLocal rotates each segment from its own center.

func (*SegmentList) Scale added in v0.5.2

func (s *SegmentList) Scale(sx, sy float64)

Scale scales all the segments in a list.

func (*SegmentList) ScaleFrom added in v0.5.2

func (s *SegmentList) ScaleFrom(x, y, sx, sy float64)

ScaleFrom scales all the segments in a list using the x, y location as a center.

func (*SegmentList) ScaleLocal added in v0.5.2

func (s *SegmentList) ScaleLocal(sx, sy float64)

ScaleLocal scales each segment from its own center.

func (*SegmentList) Translate added in v0.5.2

func (s *SegmentList) Translate(x, y float64)

Translate translates all the segments in a list.

func (*SegmentList) UniScale added in v0.5.2

func (s *SegmentList) UniScale(scale float64)

UniScale scales each segment

func (*SegmentList) UniScaleFrom added in v0.5.2

func (s *SegmentList) UniScaleFrom(x, y, scale float64)

UniScaleFrom scales each segment

func (*SegmentList) UniScaleLocal added in v0.5.2

func (s *SegmentList) UniScaleLocal(scale float64)

UniScaleLocal scales each segment

type Triangle

type Triangle struct {
	PointA, PointB, PointC *Point
}

Triangle represents a triangle.

func EquilateralTriangleFromCenterAndPoint

func EquilateralTriangleFromCenterAndPoint(c, p0 *Point) *Triangle

EquilateralTriangleFromCenterAndPoint creates a new equilateral triangle from a centroid point and another point.

func EquilateralTriangleFromTwoPoints

func EquilateralTriangleFromTwoPoints(p0, p1 *Point, clockwise bool) *Triangle

EquilateralTriangleFromTwoPoints creates a new equilateral triangle from a two points.

func IsoscoleseTriangle added in v0.5.7

func IsoscoleseTriangle(point *Point, sideLength, angle float64) *Triangle

IsoscoleseTriangle creates a new trangle with the given point and two sides of the given length with the given angle.

func NewTriangle

func NewTriangle(x0, y0, x1, y1, x2, y2 float64) *Triangle

NewTriangle creates a new triangle from three x, y pairs

func NewTriangleFromPoints

func NewTriangleFromPoints(pA, pB, pC *Point) *Triangle

NewTriangleFromPoints creates a new triangle from three points.

func (*Triangle) Altitude added in v0.5.7

func (t *Triangle) Altitude(index int) float64

Altitude returns the altitude of the given point to its opposite side.

func (*Triangle) AltitudeLine added in v0.5.7

func (t *Triangle) AltitudeLine(index int) *Segment

AltitudeLine returns a line that represents the altitude from a given point to its opposite side.

func (*Triangle) Angles added in v0.5.7

func (t *Triangle) Angles() []float64

Angles returns the three angles of the triangle.

func (*Triangle) Area

func (t *Triangle) Area() float64

Area returns the area of the triangle

func (*Triangle) BisectorLine added in v0.5.7

func (t *Triangle) BisectorLine(index int) *Segment

BisectorLine returns a line segment representing the bisector from a given point to its opposite side.

func (*Triangle) Centroid

func (t *Triangle) Centroid() *Point

Centroid returns the centroid of a triangle.

func (*Triangle) CircumCenter

func (t *Triangle) CircumCenter() *Point

CircumCenter returns a point representing the circumcenter of the triangle

func (*Triangle) CircumCircle

func (t *Triangle) CircumCircle() *Circle

CircumCircle returns a circle object representing the center and radius of the circumcircle.

func (*Triangle) Contains

func (t *Triangle) Contains(p *Point) bool

Contains returns whether or not the given point is contained by the triangle.

func (*Triangle) Edges added in v0.5.0

func (t *Triangle) Edges() SegmentList

Edges returns the three segments that make up the triangle.

func (*Triangle) Equals added in v0.5.0

func (t *Triangle) Equals(other *Triangle) bool

Equals returns whether or not this triangle is equal to another triangle

func (*Triangle) Foot added in v0.5.7

func (t *Triangle) Foot(index int) *Point

Foot returns the altitude foot of a triangle (intersection of base and altitude).

func (*Triangle) InCenter

func (t *Triangle) InCenter() *Point

InCenter returns the point representing the incenter of the triangle.

func (*Triangle) InCircle

func (t *Triangle) InCircle() *Circle

InCircle returns a circle containing the center and radius of the incircle.

func (*Triangle) Lengths added in v0.5.7

func (t *Triangle) Lengths() []float64

Lengths returns the lenghts of the three sides of this triangle.

func (*Triangle) MedianLine added in v0.5.7

func (t *Triangle) MedianLine(index int) *Segment

MedianLine returns a line segment representing the median from a given point to its opposite side.

func (*Triangle) OrthicTriangle added in v0.5.7

func (t *Triangle) OrthicTriangle() *Triangle

OrthicTriangle returns the triangle created by the foot of each corner of the triangle.

func (*Triangle) OrthoCenter

func (t *Triangle) OrthoCenter() *Point

OrthoCenter returns a point representing the orthocenter of the triangle.

func (*Triangle) Points

func (t *Triangle) Points() PointList

Points returns a list of points that make up this triangle

func (*Triangle) Randomize added in v0.5.2

func (t *Triangle) Randomize(amount float64)

Randomize randomizes the position of the three points of the triangle.

func (*Triangle) Randomized added in v0.5.2

func (t *Triangle) Randomized(amount float64) *Triangle

Randomized returns another triangle that is randomized from this one.

func (*Triangle) Rotate added in v0.5.2

func (t *Triangle) Rotate(angle float64)

Rotate rotates a triangle around the origin.

func (*Triangle) RotateFrom added in v0.5.2

func (t *Triangle) RotateFrom(x, y, angle float64)

RotateFrom rotates a triangle around the given x, y location.

func (*Triangle) RotateLocal added in v0.5.2

func (t *Triangle) RotateLocal(angle float64)

RotateLocal rotates a triangle around its own center (centroid)

func (*Triangle) Rotated added in v0.5.2

func (t *Triangle) Rotated(angle float64) *Triangle

Rotated returns a new triangle rotated by the given amount.

func (*Triangle) RotatedFrom added in v0.5.2

func (t *Triangle) RotatedFrom(x, y, angle float64) *Triangle

RotatedFrom returns a new triangle rotated by the given amount.

func (*Triangle) RotatedLocal added in v0.5.2

func (t *Triangle) RotatedLocal(angle float64) *Triangle

RotatedLocal returns a new triangle rotated by the given amount.

func (*Triangle) Scale added in v0.5.2

func (t *Triangle) Scale(sx, sy float64)

Scale scales a triangle the given amount on each axis.

func (*Triangle) ScaleFrom added in v0.5.2

func (t *Triangle) ScaleFrom(x, y, sx, sy float64)

ScaleFrom scales a triangle the given amount on each axis, from the given x, y location.

func (*Triangle) ScaleLocal added in v0.5.2

func (t *Triangle) ScaleLocal(sx, sy float64)

ScaleLocal scales a triangle the given amount on each axis.

func (*Triangle) Scaled

func (t *Triangle) Scaled(sx, sy float64) *Triangle

Scaled returns another triangle that is scaled from this one.

func (*Triangle) ScaledFrom added in v0.5.2

func (t *Triangle) ScaledFrom(x, y, sx, sy float64) *Triangle

ScaledFrom returns a new triangle scaled by the given amount.

func (*Triangle) ScaledLocal added in v0.5.2

func (t *Triangle) ScaledLocal(sx, sy float64) *Triangle

ScaledLocal returns a new triangle scaled by the given amount.

func (*Triangle) String added in v0.5.0

func (t *Triangle) String() string

func (*Triangle) Translate added in v0.5.2

func (t *Triangle) Translate(x, y float64)

Translate translates a triangle the given amount on each axis.

func (*Triangle) Translated added in v0.5.2

func (t *Triangle) Translated(tx, ty float64) *Triangle

Translated returns a new triangle translated by the given amount.

func (*Triangle) UniScale added in v0.5.2

func (t *Triangle) UniScale(scale float64)

UniScale scales a triangle the given amount on each axis.

func (*Triangle) UniScaleFrom added in v0.5.2

func (t *Triangle) UniScaleFrom(x, y, scale float64)

UniScaleFrom scales a triangle the given amount on each axis, from the given x, y location.

func (*Triangle) UniScaleLocal added in v0.5.2

func (t *Triangle) UniScaleLocal(scale float64)

UniScaleLocal scales a triangle the given amount on each axis

func (*Triangle) UniScaled added in v0.5.2

func (t *Triangle) UniScaled(scale float64) *Triangle

UniScaled returns a new triangle scaled by the given amount - the same on both axes.

func (*Triangle) UniScaledFrom added in v0.5.2

func (t *Triangle) UniScaledFrom(x, y, scale float64) *Triangle

UniScaledFrom returns a new segment scaled from the given point.

func (*Triangle) UniScaledLocal added in v0.5.2

func (t *Triangle) UniScaledLocal(scale float64) *Triangle

UniScaledLocal returns a new segment scaled locally

type TriangleList added in v0.5.2

type TriangleList []*Triangle

TriangleList is a slice of triangles

func NewTriangleList added in v0.5.2

func NewTriangleList() TriangleList

NewTriangleList creates a new triangle list

func (*TriangleList) Add added in v0.5.2

func (t *TriangleList) Add(triangle *Triangle)

Add adds a Triangle to the list

func (*TriangleList) Edges added in v0.5.2

func (t *TriangleList) Edges() SegmentList

Edges returns a list of unique edges from the triangle list.

func (*TriangleList) Randomize added in v0.5.2

func (t *TriangleList) Randomize(amount float64)

Randomize randomizes the position of both ends of the segment by up to a given amount on each axis.

func (*TriangleList) Rotate added in v0.5.2

func (t *TriangleList) Rotate(angle float64)

Rotate rotates all the segments in a list.

func (*TriangleList) RotateFrom added in v0.5.2

func (t *TriangleList) RotateFrom(x, y float64, angle float64)

RotateFrom rotates all the segments in a list using the x, y location as a center.

func (*TriangleList) RotateLocal added in v0.5.2

func (t *TriangleList) RotateLocal(angle float64)

RotateLocal rotates each segment from its own center.

func (*TriangleList) Scale added in v0.5.2

func (t *TriangleList) Scale(sx, sy float64)

Scale scales all the segments in a list.

func (*TriangleList) ScaleFrom added in v0.5.2

func (t *TriangleList) ScaleFrom(x, y, sx, sy float64)

ScaleFrom scales all the segments in a list using the x, y location as a center.

func (*TriangleList) ScaleLocal added in v0.5.2

func (t *TriangleList) ScaleLocal(sx, sy float64)

ScaleLocal scales each segment from its own center.

func (*TriangleList) Translate added in v0.5.2

func (t *TriangleList) Translate(x, y float64)

Translate translates all the segments in a list.

func (*TriangleList) UniScale added in v0.5.2

func (t *TriangleList) UniScale(scale float64)

UniScale scales each segment

func (*TriangleList) UniScaleFrom added in v0.5.2

func (t *TriangleList) UniScaleFrom(x, y, scale float64)

UniScaleFrom scales each segment

func (*TriangleList) UniScaleLocal added in v0.5.2

func (t *TriangleList) UniScaleLocal(scale float64)

UniScaleLocal scales each segment

type Vector

type Vector struct {
	U, V float64
}

Vector is a struct representing a 2D vector.

func NewVector added in v0.4.13

func NewVector(u, v float64) *Vector

NewVector returns a new vector with the given components.

func VectorBetween

func VectorBetween(x0, y0, x1, y1 float64) *Vector

VectorBetween returns the vector between two points.

func VectorFromPoints

func VectorFromPoints(p0, p1 *Point) *Vector

VectorFromPoints returns the vector between two points.

func (*Vector) Abs added in v0.4.13

func (v *Vector) Abs() *Vector

Abs returns the absolute value (taken component-wise) of this vector.

func (*Vector) Add

func (v *Vector) Add(w *Vector) *Vector

Add adds another vector to this vector returning the result.

func (*Vector) Angle added in v0.4.10

func (v *Vector) Angle() float64

Angle returns the angle of this vector.

func (*Vector) AngleValueTo

func (v *Vector) AngleValueTo(w *Vector) float64

AngleValueTo returns the angle to another vector.

func (*Vector) CrossProduct

func (v *Vector) CrossProduct(w *Vector) float64

CrossProduct returns the cross product between this and another vector.

func (*Vector) DotProduct

func (v *Vector) DotProduct(w *Vector) float64

DotProduct returns the dot product between this and another vector.

func (*Vector) Magnitude added in v0.4.11

func (v *Vector) Magnitude() float64

Magnitude returns the magnitude (length) of this vector.

func (*Vector) Max added in v0.4.13

func (v *Vector) Max(other float64) *Vector

Max returns the maximum value (taken component-wise) of this vector and another value.

func (*Vector) Min added in v0.4.13

func (v *Vector) Min(other float64) *Vector

Min returns the minimum value (taken component-wise) of this vector and another value.

func (*Vector) Norm

func (v *Vector) Norm() float64

Norm returns a normalized vector.

func (*Vector) Normalized

func (v *Vector) Normalized() *Vector

Normalized returns this vector normalized.

func (*Vector) Project

func (v *Vector) Project(w *Vector) float64

Project returns the value by projecting this vector onto another vector.

func (*Vector) Scaled

func (v *Vector) Scaled(factor float64) *Vector

Scaled returns this vector scaled.

func (*Vector) Subtract

func (v *Vector) Subtract(w *Vector) *Vector

Subtract subtracts another vector from this vector returning the result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL