geom

package
v0.0.0-...-e3578a0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2016 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

package geom contains routines for computing geometric quantities.

Contains implementations of algorithms described in Platis & Theoharis, 2015 as well as Schneider & Eberly.

The calling signatures might be more convoluted than they have to be because I was too worried about memory consumption when I started it. I should include examples.

Index

Constants

This section is empty.

Variables

View Source
var LineEps float32 = 1e-5

LineEps represents the maximum distance between two two floating point numbers at which they are still considered as equal by this module when calulating properties of lines. Specifically, when detecting whether or not a line is vertical.

You can change it if you want, but since I use float32s, making it much smaller than this will probably be a mistake on your part.

Functions

func AngleBinRange

func AngleBinRange(low, width float32, bins int) (lowIdx, idxWidth int)

AngleBinRange returns the bin range of the given angle range.

func AngleInRange

func AngleInRange(phi, low, width float32) bool

AngleInRange takes two angles in the range [0, 2 pi) and an angular width in the range [0, 2 pi]. True is returned if phi is within the range inclusive range specified by low and width and false is returned otherwise.

func AngularDistance

func AngularDistance(phi1, phi2 float32) float32

AngularDistance computes the signed distance from phi1 to phi2 in the range [0, 2 pi).

func AreParallel

func AreParallel(l1, l2 *Line) bool

AreParallel returns true if both the given lines are parallel.

func EulerMatrix

func EulerMatrix(phi, theta, psi float32) *mat.Matrix32

EulerMatrix creates a 3D rotation matrix based off the Euler angles phi, theta, and psi. These represent three consecutive rotations around the z, x, and z axes, respectively.

This is really slow right now.

func EulerMatrixAt

func EulerMatrixAt(phi, theta, psi float32, out *mat.Matrix32)

EulerMatrixAt writes an Euler rotation matrix to the specified loaction. An Euler matrix is matrix based off the Euler angles phi, theta, and psi. These represent three consecutive rotations around the z, x, and z axes, respectively.

This is really slow right now.

func EulerMatrixBetween

func EulerMatrixBetween(v1, v2 *Vec) *mat.Matrix32

EulerMatrixBetween creates a 3D rotation matrix which such that M * v1 = v2.

func EulerMatrixBetweenAt

func EulerMatrixBetweenAt(v1, v2 *Vec, out *mat.Matrix32) *mat.Matrix32

func PolarAngle

func PolarAngle(x, y float32) float32

PolarAngle returns the polar angle of the point as x, y.

func Solve

func Solve(l1, l2 *Line) (x, y float32, ok bool)

Solve solves for the intersection point between l1 and l2 if it exists. If no intersection point exists, ok is returned as false. Otherwise it is returned as true.

func SphericalAngles

func SphericalAngles(x, y, z float32) (phi, theta float32)

SphericalAngles returns the azimuthal and polar angles (respectively) of the point specified by x, y, z.

func UnitSphericalAngles

func UnitSphericalAngles(x, y, z float32) (phi, theta float32)

UnitSphericalAngles returns the azimuthal and polar angles (respectively) of the point specified by x, y, z. It is assumed that Sqrt(x*x + y*y + z*z) = 1

Types

type AnchoredPluckerVec

type AnchoredPluckerVec struct {
	PluckerVec
	P Vec
}

AnchoredPluckerVec is a Plucker vector which also saves the position of the ray's origin.

func (*AnchoredPluckerVec) Init

func (ap *AnchoredPluckerVec) Init(P, L *Vec)

Init initializes an anchored Plucker vector given a ray origin, P, and a unit direction vector, L.

func (*AnchoredPluckerVec) InitFromSegment

func (ap *AnchoredPluckerVec) InitFromSegment(P1, P2 *Vec)

InitFromSegment initialized a Plucker vector which corresponds to a ray pointing from the position vector P1 to the position vector P2.

func (*AnchoredPluckerVec) Translate

func (ap *AnchoredPluckerVec) Translate(dx *Vec)

Translate translates a Plucker vector along the given vector.

type IntersectionWorkspace

type IntersectionWorkspace struct {
	// contains filtered or unexported fields
}

IntersectionWorkspace contains various fields useful for speeding up ray-tetrahedron intersection checks.

Workspaces should not be shared between threads.

func (*IntersectionWorkspace) IntersectionBary

func (w *IntersectionWorkspace) IntersectionBary(
	pt *PluckerTetra, p *PluckerVec,
) (bEnter, bLeave *TetraFaceBary, ok bool)

IntersectionBary tests for intersection between the ray represented by p and the tetrahedron represented by pt and returns the barycentric coordinates of the intersection points if they exist.

ok is returned as true if there is an intersection and as false if there is no intersection.

The ray represented by ap extends infinitely in both directions.

func (*IntersectionWorkspace) IntersectionDistance

func (w *IntersectionWorkspace) IntersectionDistance(
	pt *PluckerTetra, t *Tetra, ap *AnchoredPluckerVec,
) (lEnter, lLeave float32, ok bool)

IntersectionDistance tests for intersection between the ray represented b ap and the tetrahedron represented by t and pt and returns the distance to the intersection points from the origin of ap if they exist.

ok is returned as true if there is an intersection and as false if there is no intersection.

The ray represented by ap extends infinitely in both directions, so negative distances are valid return values.

type Line

type Line struct {
	Y0, M    float32
	Vertical bool
}

Line is a possibly vertical 2D line.

func (*Line) Init

func (l *Line) Init(x1, y1, x2, y2 float32) (ok bool)

Init initializes a line so that it passes though both the supplied points. Init returns false if a line cannot be unambiguously drawn between the given points, false is returned. Otherwise true is returned.

func (*Line) InitFromPlucker

func (l *Line) InitFromPlucker(ap *AnchoredPluckerVec)

InitFromPlucker initializes a line so that it is aligned with the given Plucker vector.

type LineSegment

type LineSegment struct {
	Origin, Dir  Vec
	StartR, EndR float32
}

LineSegment represents a line segment.

type PlatonicSolid

type PlatonicSolid int

PlatonicSolid is a polyhedron in which every face is identical.

const (
	PlatonicTetrahedron PlatonicSolid = iota
	PlatonicHexahedron
	PlatonicOctahedron
	PlatonicDodecahedron
	PlatonicIcosahedron
)

func NewPlatonicSolid

func NewPlatonicSolid(sides int) (solid PlatonicSolid, ok bool)

NewPlatonicSolid returns the flag corresponding to the Platonic solid with the specified number of sides. ok is returned as true if there exists a Platonic solid with that many sides and false otherwise.

In case you forgot, valid side numbers are: 4, 6, 8, 12, 20.

func NewUniquePlatonicSolid

func NewUniquePlatonicSolid(sides int) (solid PlatonicSolid, ok bool)

func (PlatonicSolid) FaceVertices

func (solid PlatonicSolid) FaceVertices(i int) []Vec

FaceVertices returns the coordinates of vertices of the specifed face.

These coordinates are not normalized in any particular way.

func (PlatonicSolid) Normals

func (solid PlatonicSolid) Normals() []Vec

Normals returns the normal vectors of all the faces of a Platonic solid.

Note: (since I know what you're going to use this for) if you want to generate origin-anchored planes from these vectors, make sure to remove vectors which would result in duplicate planes (i.e. filter one of each pair of vectors that point in opposite directions.)

func (PlatonicSolid) Sides

func (solid PlatonicSolid) Sides() int

Sides returns the number of sides contianed by a Platonic solide.

func (PlatonicSolid) UniqueNormals

func (solid PlatonicSolid) UniqueNormals() []Vec

UniqueNormals returns all the face-centered normal vectors which specify unique origin-centered planes.

type PluckerTetra

type PluckerTetra [6]PluckerVec

PluckerTetra is a tetrahedron represented by the Plucker vectors that make up its edges. It is used for Platis & Theoharis's interseciton detection algorithm.

The raw ordering of edges is F0(V3, V2, V1) F1(V2, V3, V0) F2(V1, V0, V3) F3(V0, V1, V2) {0-1, 0-2, 0-3, 1-2, 1-3, 2-3}

func (*PluckerTetra) EdgeIdx

func (_ *PluckerTetra) EdgeIdx(face, edge int) (idx int, flip bool)

EdgeIdx returns the index into pt which corresponds to the requested face and edge. A flag is also returned indicating whether the vector stored in pt needs to be flipped when doing operations on that face.

func (*PluckerTetra) Init

func (pt *PluckerTetra) Init(t *Tetra)

Init initializes a Plucker Tetrahedron from a normal Tetrahedron.

func (*PluckerTetra) TetraVertices

func (_ *PluckerTetra) TetraVertices(i int) (start, end int)

TetraVertexIdx returns the indices of the vertices in a Tetra object which correspond to end points of a given PluckerVector within a PluckerTetra.

func (*PluckerTetra) Translate

func (pt *PluckerTetra) Translate(dx *Vec)

Translate translates a Plucker tetrahedron along the given vector.

type PluckerVec

type PluckerVec struct {
	U, V Vec
}

PluckerVec represents a ray. If P and L are the position of the ray's origin and the unit vector representing its direction, respectively, then U = L and V = L cross P.

func (*PluckerVec) Dot

func (p1 *PluckerVec) Dot(p2 *PluckerVec, flip bool) float32

Dot computes the permuted inner product of p1 and p2, i.e. p1.U*p2.V + p1.V*p2.U.

func (*PluckerVec) Init

func (p *PluckerVec) Init(P, L *Vec)

Init initializes a Plucker vector given a ray origin, P, and a unit direction vector, L.

func (*PluckerVec) InitFromSegment

func (p *PluckerVec) InitFromSegment(P1, P2 *Vec)

InitFromSegment initialized a Plucker vector which corresponds to a ray pointing from the position vector P1 to the position vector P2.

func (*PluckerVec) SignDot

func (p1 *PluckerVec) SignDot(p2 *PluckerVec, flip bool) (float32, int)

Dot computes the permuted inner product of p1 and p2, i.e. p1.U*p2.V + p1.V*p2.U and also returns a sign flag of -1, 0, or +1 if that product is negative, zero, or positive, respectively.

func (*PluckerVec) Translate

func (p *PluckerVec) Translate(dx *Vec)

Translate translates a Plucker vector along the given vector.

type Sphere

type Sphere struct {
	C Vec
	R float32
}

Sphere is exactly what you think it is.

func (*Sphere) LineSegmentIntersect

func (s *Sphere) LineSegmentIntersect(
	ls *LineSegment,
) (enter, exit float32, enters, exits bool)

LineSegmentIntersect tests for intersection between a sphere and a line segment. The distances between the line segment's origin and the two intersect points are returned as the first two arguments and bools indicating whether those entrance points exist on the line segment are returned as the second two arguments.

func (*Sphere) SphereContain

func (s1 *Sphere) SphereContain(s2 *Sphere) bool

SphereContain returns true if s1 is completely contained in s2.

func (*Sphere) SphereIntersect

func (s1 *Sphere) SphereIntersect(s2 *Sphere) bool

Intersect returns true if the two spheres intersect and false otherwise.

func (*Sphere) TetraContain

func (s *Sphere) TetraContain(t *Tetra) bool

TetraContain returns true if a tetrahedron is completely contained in a sphere.

func (*Sphere) TetraIntersect

func (s *Sphere) TetraIntersect(t *Tetra) bool

TetraIntersect returns true if a tetrahedron and a sphere overlap.

func (*Sphere) VecIntersect

func (s *Sphere) VecIntersect(v *Vec) bool

VecIntersect returns true if a vector is contained inside a sphere.

type Tetra

type Tetra [4]Vec

Tetra is a tetrahedron. (Duh!)

Face ordering is: F0(V3, V2, V1) F1(V2, V3, V0) F2(V1, V0, V3) F3(V0, V1, V2)

func (*Tetra) BoundingSphere

func (t *Tetra) BoundingSphere(sph *Sphere)

BoundingSphere draws a bounding sphere aorund the given tetrahedron.

func (*Tetra) Distance

func (t *Tetra) Distance(ap *AnchoredPluckerVec, bary *TetraFaceBary) float32

Distance calculates the distance from an anchored Plucker vector to a point in a tetrahedron described by the given unscaled barycentric coordinates.

func (*Tetra) Orient

func (t *Tetra) Orient(dir int)

Orient arranges tetrahedron points so that all faces point outward for dir = +1 and inward for dir = -1.

func (*Tetra) Rotate

func (t *Tetra) Rotate(m *mat.Matrix32)

Rotate rotates a tetrahedron by the given rotation matrix.

func (*Tetra) Translate

func (t *Tetra) Translate(dx *Vec)

Translate translates a tetrahedron by the given vector.

func (*Tetra) VertexIdx

func (_ *Tetra) VertexIdx(face, vertex int) int

VertexIdx returns the index into the given tetrahedron corresponding to the specified face and vertex.

func (*Tetra) Volume

func (t *Tetra) Volume() float64

Volume computes the volume of a tetrahedron.

func (*Tetra) ZPlaneSlice

func (t *Tetra) ZPlaneSlice(
	pt *PluckerTetra, z float32, poly *TetraSlice,
) (ok bool)

ZPlaneSlice slices a tetrahedron with a z-aligned plane. ok is returned as true if the sline and the tetrahedron intersect and false otherwise.

type TetraFaceBary

type TetraFaceBary struct {
	// contains filtered or unexported fields
}

TetraFaceBary contains information specifying the barycentric coordinates of a point on a face of a tetrahedron.

type TetraSlice

type TetraSlice struct {
	Xs, Ys, Phis [4]float32

	Lines [4]Line

	Points int
	// contains filtered or unexported fields
}

TetraSlice is a triangle or a convex quadrilateral which is created by slicing a tetrahedron by a z-aligned plane.

By convention, the generic name for a TetraSlice variable is "poly".

func (*TetraSlice) AngleRange

func (poly *TetraSlice) AngleRange() (start, width float32)

AngleRange returns the angular range subtended by a polygon.

func (*TetraSlice) IntersectingLines

func (poly *TetraSlice) IntersectingLines(phi float32) (l1, l2 *Line)

IntersectingLines returns the lines in the given tetrahedron slice which overlap with the given angle.

It's possible that only only line will be intersected (if the polygon encloses the origin), in which case l2 will be returned as nil.

func (*TetraSlice) RSqrMinMax

func (poly *TetraSlice) RSqrMinMax() (rSqrMin, rSqrMax float32)

RSqrMinMax returns the square of the radii of the closest and furthest points in a TetraSlice.

type Vec

type Vec [3]float32

Vec is a three dimensional vector. (Duh!)

func (*Vec) Rotate

func (v *Vec) Rotate(m *mat.Matrix32)

Rotate rotates a vector by the given rotation matrix.

Jump to

Keyboard shortcuts

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