raytrace

package module
v0.0.0-...-18c12a8 Latest Latest
Warning

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

Go to latest
Published: May 2, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

README

#raytrace#

Package raytrace implements functions to rapidly find intersections between a ray segment and a set of triangles.

Documentation

Overview

Package raytrace implements functions to rapidly find intersections between a ray segment and a set of triangles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeoDesicPoints

func GeoDesicPoints(depth int, radius float64) (spherePoints [][3]float64)

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

func CreateBspTree(minNodeSize float64, objs TriList) (rootNode *BspNode, err error)

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.

func (*BspNode) Sprint

func (node *BspNode) Sprint() (output string)

Sprint prints a tree

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 NewRay

func NewRay(rootpt, endpt [3]float64) (newray *Ray)

NewRay creates a new ray struct

func (*Ray) GetDir

func (ray *Ray) GetDir() [3]float64

GetDir returns the ray's direction vector

func (*Ray) GetDist

func (ray *Ray) GetDist() float64

GetDist return the distance of this split ray's root from the actual ray root

func (*Ray) GetEnd

func (ray *Ray) GetEnd() [3]float64

GetEnd returns the end point of the ray

func (*Ray) GetLength

func (ray *Ray) GetLength() float64

GetLength returns the ray's normalized direction vector

func (*Ray) GetNDir

func (ray *Ray) GetNDir() [3]float64

GetNDir returns the ray's normalized direction vector

func (*Ray) GetRoot

func (ray *Ray) GetRoot() [3]float64

GetRoot returns the root point of the ray

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 NewTri

func NewTri(ptid int, pt1, pt2, pt3 [3]float64) (newtri *Tri)

NewTri creates a new Tri and returns a pointer to it

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) AvgPos

func (tp *Tri) AvgPos() [3]float64

AvgPos returns the average position of the tri

func (*Tri) GetD

func (tp *Tri) GetD(normal [3]float64) float64

GetD returns the d value of a triangle for use in TriIntersect

func (*Tri) GetID

func (tp *Tri) GetID() int

GetID returns the normal vector of the Tri

func (*Tri) GetMinorAxisIdxs

func (tp *Tri) GetMinorAxisIdxs() (i1, i2 int)

GetMinorAxisIdxs returns minor axis indexes for a triangle with the given normal for use in TriIntersect

func (*Tri) GetNormal

func (tp *Tri) GetNormal() [3]float64

GetNormal returns the normal vector of the Tri

func (*Tri) GetPt

func (tp *Tri) GetPt(i int) [3]float64

GetPt returns the Tri point specified by the index

func (*Tri) GetSamplePoints

func (tp *Tri) GetSamplePoints(min float64) (samplePoints [][3]float64)

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) String

func (tp *Tri) String() string

String returns a string representation of the triangle

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

func (tp *Tri) TriIntersectInfo(ray *Ray) (front bool, distance float64, point [3]float64)

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

type TriList

type TriList []*Tri

TriList is a list of Tri pointers

func (TriList) GetAvgPos

func (tpl TriList) GetAvgPos() (avgPos [3]float64)

GetAvgPos returns the average position of the trilist

func (TriList) GetMaxRadius

func (tpl TriList) GetMaxRadius() (center [3]float64, max float64)

GetMaxRadius returns the center of the triList and the

distance from the center to the most distant point

Jump to

Keyboard shortcuts

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