utility

package module
v0.0.0-...-022bd34 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

#utility#

Package utility implements functions that I couldn't figure out where to put.

Documentation

Overview

Package utility implements functions that I couldn't figure out where to put.

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

func LinearInterpolation

func LinearInterpolation(x, y []float64, xNew float64) (float64, error)

LinearInterpolation finds the y value associated with xNew given a list of x and y values using linear interpolation.

func MaxLoc

func MaxLoc(array []float64) (maxloc int)

MaxLoc determines the position of the largest element in the array

func Smooth

func Smooth(x, y []float64, zeroTol float64, zeroEnds bool) ([]float64, []float64, error)

Smooth processes a curve and tries to reduce the number of points by eliminating points where significant error is not incured

zeroTol is used to determine if a value should actually be zero. If it is less than 0 it will be determined from them min and max y.
If zeroEnds is true points with y = 0.0 will be inserted at the begining and end of the resulting lists. It will also ensure
that there are not many zeros at the end of the list.

func TriArea

func TriArea(v1, v2, v3 [3]float64) (area float64)

TriArea returns the area of a triangle

func TriIntersect

func TriIntersect(p1, p2, p3, rayOrigin, rayEnd [3]float64) (intersect bool, t 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 TriIntersectComprehensive

func TriIntersectComprehensive(p1, p2, p3, rayOrigin, rayEnd [3]float64) (intersect bool, front bool, distance float64, point [3]float64)

TriIntersectComprehensive runs TriIntersect and returns more information:

whether the front (positive normal side) was hit, the distance of the intersection from the origin, and the intersection point

func TriMaxSize

func TriMaxSize(v1, v2, v3 [3]float64) (max float64)

TriMaxSize returns the maximum edge length of the facet.

func TriMidPt

func TriMidPt(v1, v2, v3 [3]float64) (midPt [3]float64)

TriMidPt finds the midpoint of the triangle formed by the given points.

func TriMinSize

func TriMinSize(v1, v2, v3 [3]float64) (min float64)

TriMinSize returns the maximum edge length of the facet.

func TriNormal

func TriNormal(p1, p2, p3 [3]float64) (normal [3]float64)

func TriSamplePoints

func TriSamplePoints(v1, v2, v3 [3]float64, min float64, maxDiv int) (samplePoints [][3]float64)

TriSamplePoints creates a list of sample points on a triangle

func TriSamplePointsNew

func TriSamplePointsNew(v1, v2, v3 [3]float64, min float64) (samplePoints [][3]float64)

TriSamplePointsNew creates a list of sample points on a triangle

func TriSubdivide

func TriSubdivide(v1, v2, v3 [3]float64, min float64, maxDiv, currDiv int, samplePoints *[][3]float64)

TriSubdivide adds the center point to samplePoints if the maximum edge length is

<= min.  other wise it it splits the triangle into 4 triangles tries again.

Types

type BspNode

type BspNode struct {
	Objs     []BspObj
	Layer    int
	Dir      DirectionType
	SplitVal float64
	Greater  *BspNode
	Lesser   *BspNode
}

BspNode represents a node of a BSP of facets

func CreateBspTree

func CreateBspTree(objs interface{}) (node *BspNode, err error)

CreateBspTree creates a BSP tree given a list of facets

func (*BspNode) FindIntersections

func (node *BspNode) FindIntersections(ray *Ray, all bool, exception string) (intersections IntersectionList)

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 BspObj

type BspObj interface {
	String() string
	AvgLoc(DirectionType) float64
	MinLoc(DirectionType) float64
	MaxLoc(DirectionType) float64
	Intersect(*Ray) *Intersection
}

BspObj is an interface for an object that can be stored in the bsp tree structure

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   fmt.Stringer // pointer to the thing 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
}

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 {
	RootPt   [3]float64 // The Root point of this ray segment.
	EndPt    [3]float64 // The End point of this ray segment.
	Distance float64
}

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

func (ray *Ray) Dir() (dir [3]float64)

Dir returns the rays direction vector

func (*Ray) MaxLoc

func (ray *Ray) MaxLoc(dir DirectionType) (min float64)

MaxLoc returns the max location on the dir axis

func (*Ray) MinLoc

func (ray *Ray) MinLoc(dir DirectionType) (min float64)

MinLoc returns the min location on the dir axis

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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