Documentation ¶
Index ¶
- func Barycentric(a, b, c, p *glm.Vec3) (u, v, w float32)
- func BarycentricWithCache(b *BarycentricCache, p *glm.Vec3) (u, v, w float32)
- func ClosestPointAABBPoint(a *AABB, p *glm.Vec3) glm.Vec3
- func ClosestPointLineTriangle(p, q, a, b, c *glm.Vec3) (u, v glm.Vec3)
- func ClosestPointOBBPoint(o *OBB, p *glm.Vec3) glm.Vec3
- func ClosestPointRect(p, a, b, c *glm.Vec3) glm.Vec3
- func ClosestPointRectPoint(r *Rect, p *glm.Vec3) glm.Vec3
- func ClosestPointSegmentPoint(a, b, c *glm.Vec3) (t float32, point glm.Vec3)
- func ClosestPointSegmentSegment(p1, q1, p2, q2 *glm.Vec3) (s, t, u float32, c1, c2 glm.Vec3)
- func ClosestPointTetrahedronPoint(p, a, b, c, d *glm.Vec3) glm.Vec3
- func ClosestPointTrianglePoint(p, a, b, c *glm.Vec3) glm.Vec3
- func ClosestPointTriangleTriangle(a, b, c, d, e, f *glm.Vec3) (u, v glm.Vec3)
- func CovarianceMatrix(cov *glm.Mat3, points []glm.Vec3)
- func DOP8FromPoints(d *DOP8, points []glm.Vec3)
- func DistToTriangle(p, a, b, c *glm.Vec3) float32
- func DistanceToPlane(p *Plane, v *glm.Vec3) float32
- func ExtremePointsAlongDirection(direction *glm.Vec3, points []glm.Vec3) (imin int, imax int)
- func InsideSpherePlane(s *Sphere, p *Plane) bool
- func IntersectRayAABB(p, d *glm.Vec3, a *AABB) (t float32, q glm.Vec3, overlap bool)
- func IntersectRaySphere(p, d *glm.Vec3, s *Sphere) (t float32, q glm.Vec3, overlap bool)
- func IntersectSegmentCylinder(sa, sb, p, q *glm.Vec3, r float32) (float32, bool)
- func IntersectSegmentPlane(a, b *glm.Vec3, p *Plane) (t float32, q glm.Vec3, overlap bool)
- func IntersectSegmentQuad(p, q, a, b, c, d *glm.Vec3) (glm.Vec3, bool)
- func IntersectSegmentTriangle(p, q, a, b, c *glm.Vec3) (u, v, w float32, overlap bool)
- func IntersectSegmentTriangle2(p, q, a, b, c *glm.Vec3) (u, v, w, t float32, overlap bool)
- func IsConvexQuad(a, b, c, d *glm.Vec3) bool
- func IsPointInTriangle(p, a, b, c *glm.Vec3) bool
- func Jacobi(a, v *glm.Mat3)
- func MinimumAreaRectangle(points []glm.Vec2) (minArea float32, center glm.Vec2, orientation [2]glm.Vec2)
- func PointOutsidePlane(p, a, b, c *glm.Vec3) bool
- func PointsOnOppositeSideOfPlane(p1, a, b, c, p2 *glm.Vec3) bool
- func Quickhull(points []glm.Vec3)
- func SqDistAABBPoint(a *AABB, p *glm.Vec3) float32
- func SqDistOBBPoint(o *OBB, p *glm.Vec3) float32
- func SqDistPointSegment(a, b, c *glm.Vec3) float32
- func SqDistRectPoint(r *Rect, p *glm.Vec3) float32
- func SymSchur2(a *glm.Mat3, p, q int) (c, s float32)
- func TestAABBAABB(a, b *AABB) bool
- func TestAABBPlane(b *AABB, p *Plane) bool
- func TestCapsuleCapsule(a, b *Capsule) bool
- func TestCapsuleSphere(c *Capsule, s *Sphere) bool
- func TestDOP8DOP8(a, b *DOP8) bool
- func TestOBBOBB(a, b *OBB) bool
- func TestOBBPlane(b *OBB, p *Plane) bool
- func TestRaySphere(p, d *glm.Vec3, s *Sphere) bool
- func TestSegmentAABB(p0, p1 *glm.Vec3, b *AABB) bool
- func TestSphereAABB(s *Sphere, b *AABB) bool
- func TestSphereHalfspace(s *Sphere, p *Plane) bool
- func TestSphereOBB(s *Sphere, b *OBB) bool
- func TestSpherePlane(s *Sphere, p *Plane) bool
- func TestSphereSphere(a, b *Sphere) bool
- func TestSphereTriangle(s *Sphere, a, b, c *glm.Vec3) bool
- func TestTriangleAABB(v0, v1, v2 *glm.Vec3, b *AABB) bool
- func TriangleAreaFromLengths(a, b, c float32) float32
- func UpdateAABB(base, fill *AABB, t *glm.Mat3x4)
- func Variance(s []float32) float32
- type AABB
- type BarycentricCache
- type Capsule
- type DOP8
- type OBB
- type Plane
- type Rect
- type Simplex
- type Slab
- type Sphere
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Barycentric ¶
Barycentric returns the barycentric coordinates for a point in a triangle. The barycentric coordinates cna be used for interpolation of {a, b, c} to point p (such as normals, texture coordinates, colors, etc)
func BarycentricWithCache ¶
func BarycentricWithCache(b *BarycentricCache, p *glm.Vec3) (u, v, w float32)
BarycentricWithCache returns the barycentric coordinates for a point in a triangle.
func ClosestPointAABBPoint ¶
ClosestPointAABBPoint returns the point in or on the AABB closest to p.
func ClosestPointLineTriangle ¶
ClosestPointLineTriangle returns the pair of points that are the closest from the line and the triangle.
func ClosestPointOBBPoint ¶
ClosestPointOBBPoint returns the point in or on the OBB closest to p
func ClosestPointRect ¶
ClosestPointRect is a shortcut for Rect3.ClosestPoint where the rectangle is defined by the span of [ab, ac].
func ClosestPointRectPoint ¶
ClosestPointRectPoint returns the point on the rectangle closest to p
func ClosestPointSegmentPoint ¶
ClosestPointSegmentPoint returns the point on ab closest to c. Also returns t for the position of d, d(t) = a + t*(b - a)
func ClosestPointSegmentSegment ¶
ClosestPointSegmentSegment computes points C₁ and C₂ of S₁(s) = p₁ + s * (q₁-p₁) and S₂(t) = p₂ + t * (q₂-p₂), returning s, t, and the squared distance u between S₁(s) and S₂(t).
func ClosestPointTetrahedronPoint ¶
ClosestPointTetrahedronPoint returns the closes point in or on tetrahedron abcd.
func ClosestPointTrianglePoint ¶
ClosestPointTrianglePoint returns the point on the triangle abc that is closest to p
func ClosestPointTriangleTriangle ¶
ClosestPointTriangleTriangle returns the pair of points that are the closest from the triangle pair.
func CovarianceMatrix ¶
CovarianceMatrix computes the covariance matrix of the given set of points.
func DOP8FromPoints ¶
DOP8FromPoints recomputes the 8-DOP from the given points in world space.
func DistToTriangle ¶
DistToTriangle returns the distance of p to triangle {a b c}, CCW order
func DistanceToPlane ¶
DistanceToPlane returns the distance of v to plane p.
func ExtremePointsAlongDirection ¶
ExtremePointsAlongDirection returns indices imin and imax into points of the least and most, respectively, distant points along the direction dir.
func InsideSpherePlane ¶
InsideSpherePlane returns true if s is completely inside plane p.
func IntersectRayAABB ¶
IntersectRayAABB intersect ray R(t) = p + t*d against AABB a. When intersecting, return intersection distance t and point q of intersection.
func IntersectRaySphere ¶
IntersectRaySphere intersects ray r = p + td, |d| = 1, with sphere s and, if intersecting, // returns t value of intersection and intersection point q
func IntersectSegmentCylinder ¶
IntersectSegmentCylinder intersects segment S(t)=sa+t(sb-sa), 0<=t<=1 against cylinder specified by p, q and r
func IntersectSegmentPlane ¶
IntersectSegmentPlane returns how far in the segment, the point in world coordinates and true if the segment and the plane intersect
func IntersectSegmentQuad ¶
IntersectSegmentQuad is given line pq and ccw quadrilateral abcd, return whether the line pierces the triangle. If so, also return the point r of intersection.
func IntersectSegmentTriangle ¶
IntersectSegmentTriangle is given line pq and ccw triangle abc and return whether line pierces triangle. If so, also return the barycentric coordinates (u,v,w) of the intersection point.
func IntersectSegmentTriangle2 ¶
IntersectSegmentTriangle2 is given segment pq and triangle abc and returns whether segment intersects triangle and if so, also returns the barycentric coordinates (u,v,w) of the intersection point.
func IsConvexQuad ¶
IsConvexQuad returns true if the qualidrateral is convex.
func IsPointInTriangle ¶
IsPointInTriangle returns true if the point p projected on triangle {a,b,c} is inside triangle {a,b,c}
func Jacobi ¶
Jacobi computes the eigenvectors and eigenvalues of the symmetric matrix A using the classic Jacobi method of iteratively updating A as A = J∧T * A * J, where J = J(p, q, theta) is the Jacobi rotation matrix.
On exit, v will contain the eigenvectors, and the diagonal elements of a are the corresponding eigenvalues.
See Golub, Van Loan, Matrix Computations, 3rd ed, p428
func MinimumAreaRectangle ¶
func MinimumAreaRectangle(points []glm.Vec2) (minArea float32, center glm.Vec2, orientation [2]glm.Vec2)
MinimumAreaRectangle returns the center point and axis orientation of the minimum area rectangle in the xy plane.
func PointOutsidePlane ¶
PointOutsidePlane returns true if p is outside or on triangle abc CCW.
func PointsOnOppositeSideOfPlane ¶
PointsOnOppositeSideOfPlane returns true if point p is opposite of d, such that it doesn't matter if abc is CW or CCW
func SqDistAABBPoint ¶
SqDistAABBPoint returns the square distance of p to the AABB.
func SqDistOBBPoint ¶
SqDistOBBPoint returns the square distance of p to the OBB.
func SqDistPointSegment ¶
SqDistPointSegment returns the squared distance between point c and segment ab
func SqDistRectPoint ¶
SqDistRectPoint returns the square distance of p to the rectangle.
func SymSchur2 ¶
SymSchur2 aka: 2-by-2 Symmetric Schur decomposition. Given an n-by-n symmetric matrix and indices p, q such that 1 <= p < q <= n, computes a sine-cosine pair (s, c) that will serve to form a Jacobi rotation matrix.
See Golub, Van Loan, Matrix Computations, 3rd ed, p428
func TestAABBAABB ¶
TestAABBAABB returns true if these AABB overlap.
func TestAABBPlane ¶
TestAABBPlane tests if AABB b intersects plane p.
func TestCapsuleCapsule ¶
TestCapsuleCapsule returns true if these Capsules overlap.
func TestCapsuleSphere ¶
TestCapsuleSphere returns true if the capsule and the sphere overlap.
func TestDOP8DOP8 ¶
TestDOP8DOP8 returns true if the 8-DOP intersect.
func TestOBBPlane ¶
TestOBBPlane returns true if b and p intersect.
func TestRaySphere ¶
TestRaySphere tests if ray r = p + td intersects sphere s
func TestSegmentAABB ¶
TestSegmentAABB tests if segment specified by points p0 and p1 intersects AABB b.
func TestSphereAABB ¶
TestSphereAABB returns true if sphere s intersects AABB b
func TestSphereHalfspace ¶
TestSphereHalfspace returns true if s is touching or inside halfspace p.
func TestSphereOBB ¶
TestSphereOBB returns true if sphere s intersects OBB b, false otherwise. The point p on the OBB closest to the sphere center is also returned
func TestSpherePlane ¶
TestSpherePlane returns true if s and p intersect. The plane normal must be normalized.
func TestSphereSphere ¶
TestSphereSphere return true if the spheres overlap.
func TestSphereTriangle ¶
TestSphereTriangle returns true if sphere s intersects triangle ABC, false otherwise. The point p on abc closest to the sphere center is also returned.
func TestTriangleAABB ¶
TestTriangleAABB returns true if [v0 v1 v2] intersects b
func TriangleAreaFromLengths ¶
TriangleAreaFromLengths returns the area of a triangle defined by the given lengths. Returns NaN if the triangle does not exist.
func UpdateAABB ¶
UpdateAABB computes an enclosing AABB base transformed by t and puts the result in fill. base and fill must not be the same.
Types ¶
type AABB ¶
type AABB struct { // Center represents the center of the bounding box. Center glm.Vec3 // HalfExtend represents the 3 half extends of the bounding box. HalfExtend glm.Vec3 }
AABB is an axis-aligned bounding box
func AABBFromSphere ¶
AABBFromSphere returns the AABB bounding this sphere.
NOTE: If you need to use this function you better start questioning the algorithm you're implementing as the sphere is both faster and bounds the underlying object better.
type BarycentricCache ¶
type BarycentricCache struct {
// contains filtered or unexported fields
}
BarycentricCache is a cache of data for quick Barycentric calls. Use it if you need to call Barycentric on the same triangle over and over.
func BarycentricCacheFromTriangle ¶
func BarycentricCacheFromTriangle(a, b, c *glm.Vec3) BarycentricCache
BarycentricCacheFromTriangle takes a triangle and returns a barycentric cache for queries.
type OBB ¶
type OBB struct { // The center of the OBB Center glm.Vec3 // The orientation of the OBB, these need to be orthonormal. Orientation [3]glm.Vec3 // The half extends of the OBB. HalfExtend glm.Vec3 }
OBB is a Oriented Bounding Box.
type Plane ¶
type Plane struct { // the normal to the plane N glm.Vec3 // The arbitrary point that the plane starts on. P glm.Vec3 }
Plane is a hyperplane in 3D.
func PlaneFromPoints ¶
PlaneFromPoints computes the plane given by (a,b,c), ordered ccw.
type Rect ¶
type Rect struct { // the center of the rectangle Center glm.Vec3 // the orientation of the rectangle in space. Orientation [2]glm.Vec3 // the half extends of the rectangle. HalfExtend glm.Vec2 }
Rect is a rectangle in 3D space, they are a simpler version of OBBs.
type Simplex ¶
type Simplex struct { // the Points contained in the simplex. Data past Points[Size] is assumed to // be garbage. Points [4]glm.Vec3 // use an array to keep the memory all in 1 spot // the current extend of the simplex. Size int }
Simplex represents a simplex in 3D. Either a point, a line, a triangle, or a tetrahedron.
func (*Simplex) Merge ¶
Merge merges the given vector to the simplex. This will panic if you add a 5th vertex.
func (*Simplex) NearestToOrigin ¶
NearestToOrigin modifies the simplex to contain only the minimum amount of points required to describe the direction to origin, it also returns the next direction to search in GJK and true if the origin is contained in the simplex
type Slab ¶
type Slab struct { // The direction of the slab. Normal glm.Vec3 // The distance from origin along the Normal that the slab starts and end. Near, Far float32 }
Slab represent a region R = (x, y, z) | Near <= a*x + b*y + c*z <= Far
type Sphere ¶
Sphere is a bounding volume for spheres.
func EigenSphere ¶
EigenSphere sets this sphere to the bounding sphere of the given points using eigen values algorithm, this doesn't necessarily wrap all the points so use RitterEigenSphere.
func RitterEigenSphere ¶
RitterEigenSphere sets this sphere to wrap all the given points using eigen values as base.
func (*Sphere) MergePoint ¶
MergePoint updates the bounding sphere to encompass v if needed.