package collide
import "git.sr.ht/~adnano/go-collide"
Package collide implements 2D collision detection.
Index ¶
- func Cross(p, q Point) float64
- func Distance(a Shape, xfa Transform, b Shape, xfb Transform) float64
- func Dot(p, q Point) float64
- func TimeOfImpact(simplex *Simplex, a Shape, sweepA Sweep, b Shape, sweepB Sweep) float64
- type Circle
- type Collision
- func Collide(a Shape, xfa Transform, b Shape, xfb Transform) *Collision
- func CollideCircleAndPolygon(a *Circle, xfa Transform, b *Polygon, xfb Transform) *Collision
- func CollideCircles(a *Circle, xfa Transform, b *Circle, xfb Transform) *Collision
- func CollidePolygonAndCircle(a *Polygon, xfa Transform, b *Circle, xfb Transform) *Collision
- func CollidePolygons(a *Polygon, xfa Transform, b *Polygon, xfb Transform) *Collision
- type Point
- func CrossPS(p Point, s float64) Point
- func CrossSP(s float64, p Point) Point
- func Pt(X, Y float64) Point
- func (p Point) Add(q Point) Point
- func (p Point) Div(k float64) Point
- func (p Point) IsZero() bool
- func (p Point) Length() float64
- func (p Point) LengthSquared() float64
- func (p Point) Mul(k float64) Point
- func (p Point) Neg() Point
- func (p Point) Normalize() Point
- func (p Point) Sub(q Point) Point
- type Polygon
- func NewPolygon(points ...Point) *Polygon
- func Rect(x, y, w, h float64) *Polygon
- func Rectangle(center, extents Point) *Polygon
- type Rotation
- func NewRotation(theta float64) Rotation
- func (r Rotation) Mul(p Point) Point
- func (r Rotation) MulT(p Point) Point
- type Shape
- type Simplex
- func (s *Simplex) ClosestPoint() Point
- func (s *Simplex) GJK(a Shape, xfa Transform, b Shape, xfb Transform)
- func (s *Simplex) Metric() float64
- func (s *Simplex) ReadCache(cache *SimplexCache, a Shape, xfa Transform, b Shape, xfb Transform)
- func (s *Simplex) WitnessPoints() (Point, Point)
- func (s *Simplex) WriteCache(cache *SimplexCache)
- type SimplexCache
- type Sweep
- type Transform
Functions ¶
func Cross ¶
Cross returns the cross product of p and q.
func Distance ¶
Distance returns the distance between a and b.
func Dot ¶
Dot returns the dot product of p and q.
func TimeOfImpact ¶
CCD via the local separating axis method. This seeks progression by computing the largest time at which separation is maintained.
Types ¶
type Circle ¶
Circle represents a circle shape.
type Collision ¶
Collision represents a collision.
func Collide ¶
Collide calculates a collision for two shapes.
func CollideCircleAndPolygon ¶
func CollideCircles ¶
func CollidePolygonAndCircle ¶
func CollidePolygons ¶
type Point ¶
type Point struct { X, Y float64 }
A Point is an X, Y coordinate pair.
func CrossPS ¶
func CrossSP ¶
func Pt ¶
Pt is shorthand for Point{X, Y}.
func (Point) Add ¶
Add returns the vector p+q.
func (Point) Div ¶
Div returns the vector p/k.
func (Point) IsZero ¶
IsZero reports whether the point has zero length.
func (Point) Length ¶
Length returns the length of the vector p.
func (Point) LengthSquared ¶
LengthSquared returns the squared length of the vector p.
func (Point) Mul ¶
Mul returns the vector p*k.
func (Point) Neg ¶
Neg returns the vector -p.
func (Point) Normalize ¶
Normalize returns the unit vector in the direction of p.
func (Point) Sub ¶
Sub returns the vector p-q.
type Polygon ¶
Polygon represents a collection of points.
func NewPolygon ¶
NewPolygon returns a polygon with the given points specified in clockwise order.
func Rect ¶
Rect is shorthand for Rectangle(Point{x, y}, Point{w/2, h/2}).
func Rectangle ¶
Rectangle returns a rectangular polygon shape with the given center and half extents.
type Rotation ¶
type Rotation struct { Sin, Cos float64 }
Rotation represents a rotation.
func NewRotation ¶
NewRotation returns a new rotation of theta radians.
func (Rotation) Mul ¶
Mul returns the vector p rotated.
func (Rotation) MulT ¶
MulT returns the vector p inverse rotated.
type Shape ¶
type Shape interface {
// contains filtered or unexported methods
}
Shape represents a shape.
type Simplex ¶
type Simplex struct {
// contains filtered or unexported fields
}
Simplex represents a simplex.
func (*Simplex) ClosestPoint ¶
ClosestPoint returns the closest point on the simplex to the origin.
func (*Simplex) GJK ¶
GJK implements the Gilbert-Johnson-Keerthi distance algorithm.
func (*Simplex) Metric ¶
Metric returns a metric that identifies this simplex.
func (*Simplex) ReadCache ¶
ReadCache populates the simplex from the cache.
func (*Simplex) WitnessPoints ¶
WitnessPoints returns the witness points on the original shapes.
func (*Simplex) WriteCache ¶
func (s *Simplex) WriteCache(cache *SimplexCache)
WriteCache populates the cache.
type SimplexCache ¶
type SimplexCache struct {
// contains filtered or unexported fields
}
SimplexCache is used to speed up repeated calls to distance functions.
type Sweep ¶
A Sweep interpolates between two positions and orientations.
func (Sweep) Advance ¶
Advance advances the position and rotation to time t.
func (Sweep) GetTransform ¶
GetTransform returns the transform at time t.
type Transform ¶
A Transform represents translation and rotation.
func NewTransform ¶
NewTransform returns a Transform with the given position and rotation.
func (Transform) Mul ¶
Mul returns the transformation of the vector p.
func (Transform) MulT ¶
MulT returns the inverse transformation of the vector p.
Source Files ¶
collide.go distance.go doc.go math.go shape.go toi.go
- Version
- v0.0.0-20220221183648-c04b3ee7ccb2 (latest)
- Published
- Feb 21, 2022
- Platform
- linux/amd64
- Imports
- 1 packages
- Last checked
- 1 month ago –
Tools for package owners.