Documentation
¶
Overview ¶
Package raytrace implements functions to rapidly find intersections between a ray segment and a set of triangles.
Index ¶
- func GeoDesicPoints(depth int, radius float64) (spherePoints [][3]float64)
- type BspNode
- type DirectionType
- type Intersection
- type IntersectionList
- type Ray
- func (ray *Ray) GetDir() [3]float64
- func (ray *Ray) GetDist() float64
- func (ray *Ray) GetEnd() [3]float64
- func (ray *Ray) GetLength() float64
- func (ray *Ray) GetNDir() [3]float64
- func (ray *Ray) GetRoot() [3]float64
- func (ray *Ray) MaxLoc(dir DirectionType) float64
- func (ray *Ray) MinLoc(dir DirectionType) float64
- type Tri
- func (tp *Tri) AvgLoc(dir DirectionType) float64
- func (tp *Tri) AvgPos() [3]float64
- func (tp *Tri) GetD(normal [3]float64) float64
- func (tp *Tri) GetID() int
- func (tp *Tri) GetMinorAxisIdxs() (i1, i2 int)
- func (tp *Tri) GetNormal() [3]float64
- func (tp *Tri) GetPt(i int) [3]float64
- func (tp *Tri) GetSamplePoints(min float64) (samplePoints [][3]float64)
- func (tp *Tri) MaxLoc(dir DirectionType) float64
- func (tp *Tri) MinLoc(dir DirectionType) float64
- func (tp *Tri) String() string
- func (tp *Tri) TriIntersect(ray *Ray) (intersect bool, t float64, front bool, distance float64, point [3]float64, ...)
- func (tp *Tri) TriIntersectB(ray *Ray) (intersect bool, front bool, distance float64, point [3]float64, err error)
- func (tp *Tri) TriIntersectInfo(ray *Ray) (front bool, distance float64, point [3]float64)
- type TriList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GeoDesicPoints ¶
GeoDesicPoints returns a list of points equally distributed over a sphere depth 0 returns 12 points, 1 returns 72 points, 2 returns 312 points, 3 returns 1272 points radius sets the radius of the points about the origin
Types ¶
type BspNode ¶
type BspNode struct {
// contains filtered or unexported fields
}
BspNode represents a node of a BSP of facets
func CreateBspTree ¶
CreateBspTree creates a BSP tree given a list of facets
func (*BspNode) FindIntersections ¶
func (node *BspNode) FindIntersections(ray *Ray, all bool, exceptions []int) (intersections IntersectionList, err error)
FindIntersections creates a sorted list of intersections between a ray and the facets in a bsptree if all is true if all is false FindIntersection returns when the first intersection is found.
type DirectionType ¶
type DirectionType int
DirectionType specifies the X, Y, or Z directions
const ( X DirectionType = 0 Y DirectionType = 1 Z DirectionType = 2 )
Enums for DirectionType
type Intersection ¶
type Intersection struct { Obj *Tri // pointer to the tri hit Front bool // did the ray hit the front (positive normal) side of the facet Dist float64 // distance of the intersection from the root point of the ray Loc [3]float64 // location in 3d of the inersection Ray *Ray // local ray segment that intersected the triangle }
Intersection describes the where a ray and a facet intersect
func (*Intersection) String ¶
func (x *Intersection) String() string
type IntersectionList ¶
type IntersectionList []*Intersection
IntersectionList is a list of intersections that can be sorted from smallest Distance to largest
func (IntersectionList) Len ¶
func (a IntersectionList) Len() int
func (IntersectionList) Less ¶
func (a IntersectionList) Less(i, j int) bool
func (IntersectionList) String ¶
func (a IntersectionList) String() string
func (IntersectionList) Swap ¶
func (a IntersectionList) Swap(i, j int)
type Ray ¶
type Ray struct {
// contains filtered or unexported fields
}
Ray defines a ray or a segment of a ray with rootpt and an endpt. Distance from the RootPt to the actual root point (to allow for ray splitting) if the whole ray is represented by RootPt and EndPt this number would be 0.
func (*Ray) MaxLoc ¶
func (ray *Ray) MaxLoc(dir DirectionType) float64
MaxLoc returns the max location on the dir axis
func (*Ray) MinLoc ¶
func (ray *Ray) MinLoc(dir DirectionType) float64
MinLoc returns the min location on the dir axis
type Tri ¶
type Tri struct {
// contains filtered or unexported fields
}
Tri defines a triangle with three ordered points and an id
func (*Tri) AvgLoc ¶
func (tp *Tri) AvgLoc(dir DirectionType) float64
AvgLoc returns the average position in the dir (x, y, or z) direction
func (*Tri) GetMinorAxisIdxs ¶
GetMinorAxisIdxs returns minor axis indexes for a triangle with the given normal for use in TriIntersect
func (*Tri) GetSamplePoints ¶
GetSamplePoints creates a list of sample points on a triangle
func (*Tri) MaxLoc ¶
func (tp *Tri) MaxLoc(dir DirectionType) float64
MaxLoc returns the average position in the dir (x, y, or z) direction
func (*Tri) MinLoc ¶
func (tp *Tri) MinLoc(dir DirectionType) float64
MinLoc returns the average position in the dir (x, y, or z) direction
func (*Tri) TriIntersect ¶
func (tp *Tri) TriIntersect(ray *Ray) (intersect bool, t float64, front bool, distance float64, point [3]float64, err error)
TriIntersect determines whether a line segment defined by rayOrigin and rayEnd intersects a triangle defined by the points p1, p2, p3. This algorithm was originally from an efficient ray-polygon intersection by Didier Badouel from the book Graphics Gems I */
func (*Tri) TriIntersectB ¶
func (tp *Tri) TriIntersectB(ray *Ray) (intersect bool, front bool, distance float64, point [3]float64, err error)
TriIntersectB determines whether a ray segment intersects a triangle. This algorithm was originally from Moller-Trumbore intersection algorithm */
func (*Tri) TriIntersectInfo ¶
TriIntersectInfo assuming there is an intersection at the ray endpt
this function returns whether the front (positive normal side) was hit, the distance of the intersection from the origin, and the intersection point