ln

package
v0.0.0-...-12e6c6e Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2017 License: MIT Imports: 11 Imported by: 18

Documentation

Index

Constants

View Source
const EPS = 1e-9
View Source
const INF = 1e9

Variables

View Source
var ClipBox = Box{Vector{-1, -1, -1}, Vector{1, 1, 1}}
View Source
var NoHit = Hit{nil, INF}

Functions

func Degrees

func Degrees(radians float64) float64

func Median

func Median(items []float64) float64

func ParseFloats

func ParseFloats(items []string) []float64

func Radians

func Radians(degrees float64) float64

func SaveBinarySTL

func SaveBinarySTL(path string, mesh *Mesh) error

Types

type Axis

type Axis uint8
const (
	AxisNone Axis = iota
	AxisX
	AxisY
	AxisZ
)

type BooleanShape

type BooleanShape struct {
	Op   Op
	A, B Shape
}

func (*BooleanShape) BoundingBox

func (s *BooleanShape) BoundingBox() Box

func (*BooleanShape) Compile

func (s *BooleanShape) Compile()

func (*BooleanShape) Contains

func (s *BooleanShape) Contains(v Vector, f float64) bool

func (*BooleanShape) Filter

func (s *BooleanShape) Filter(v Vector) (Vector, bool)

func (*BooleanShape) Intersect

func (s *BooleanShape) Intersect(r Ray) Hit

func (*BooleanShape) Paths

func (s *BooleanShape) Paths() Paths

type Box

type Box struct {
	Min, Max Vector
}

func BoxForShapes

func BoxForShapes(shapes []Shape) Box

func BoxForTriangles

func BoxForTriangles(shapes []*Triangle) Box

func BoxForVectors

func BoxForVectors(vectors []Vector) Box

func (Box) Anchor

func (a Box) Anchor(anchor Vector) Vector

func (Box) Center

func (a Box) Center() Vector

func (Box) Contains

func (a Box) Contains(b Vector) bool

func (Box) Extend

func (a Box) Extend(b Box) Box

func (*Box) Intersect

func (b *Box) Intersect(r Ray) (float64, float64)

func (*Box) Partition

func (b *Box) Partition(axis Axis, point float64) (left, right bool)

func (Box) Size

func (a Box) Size() Vector

type ClipFilter

type ClipFilter struct {
	Matrix Matrix
	Eye    Vector
	Scene  *Scene
}

func (*ClipFilter) Filter

func (f *ClipFilter) Filter(v Vector) (Vector, bool)

type Cone

type Cone struct {
	Radius float64
	Height float64
}

func NewCone

func NewCone(radius, height float64) *Cone

func (*Cone) BoundingBox

func (c *Cone) BoundingBox() Box

func (*Cone) Compile

func (c *Cone) Compile()

func (*Cone) Contains

func (c *Cone) Contains(v Vector, f float64) bool

func (*Cone) Intersect

func (shape *Cone) Intersect(ray Ray) Hit

func (*Cone) Paths

func (c *Cone) Paths() Paths

type Cube

type Cube struct {
	Min Vector
	Max Vector
	Box Box
}

func NewCube

func NewCube(min, max Vector) *Cube

func (*Cube) BoundingBox

func (c *Cube) BoundingBox() Box

func (*Cube) Compile

func (c *Cube) Compile()

func (*Cube) Contains

func (c *Cube) Contains(v Vector, f float64) bool

func (*Cube) Intersect

func (c *Cube) Intersect(r Ray) Hit

func (*Cube) Paths

func (c *Cube) Paths() Paths

type Cylinder

type Cylinder struct {
	Radius float64
	Z0, Z1 float64
}

func NewCylinder

func NewCylinder(radius, z0, z1 float64) *Cylinder

func (*Cylinder) BoundingBox

func (c *Cylinder) BoundingBox() Box

func (*Cylinder) Compile

func (c *Cylinder) Compile()

func (*Cylinder) Contains

func (c *Cylinder) Contains(v Vector, f float64) bool

func (*Cylinder) Intersect

func (shape *Cylinder) Intersect(ray Ray) Hit

func (*Cylinder) Paths

func (c *Cylinder) Paths() Paths

type Direction

type Direction int
const (
	Above Direction = iota
	Below
)

type EmptyShape

type EmptyShape struct {
}

func (*EmptyShape) BoundingBox

func (s *EmptyShape) BoundingBox() Box

func (*EmptyShape) Compile

func (s *EmptyShape) Compile()

func (*EmptyShape) Contains

func (s *EmptyShape) Contains(v Vector, f float64) bool

func (*EmptyShape) Intersect

func (s *EmptyShape) Intersect(r Ray) Hit

func (*EmptyShape) Paths

func (s *EmptyShape) Paths() Paths

type Filter

type Filter interface {
	Filter(v Vector) (Vector, bool)
}

type Function

type Function struct {
	Function  func(x, y float64) float64
	Box       Box
	Direction Direction
}

func (*Function) BoundingBox

func (f *Function) BoundingBox() Box

func (*Function) Compile

func (f *Function) Compile()

func (*Function) Contains

func (f *Function) Contains(v Vector, eps float64) bool

func (*Function) Intersect

func (f *Function) Intersect(ray Ray) Hit

func (*Function) Paths

func (f *Function) Paths() Paths

func (*Function) Paths1

func (f *Function) Paths1() Paths

func (*Function) Paths3

func (f *Function) Paths3() Paths

type Hit

type Hit struct {
	Shape Shape
	T     float64
}

func (Hit) Max

func (a Hit) Max(b Hit) Hit

func (Hit) Min

func (a Hit) Min(b Hit) Hit

func (Hit) Ok

func (hit Hit) Ok() bool

type Matrix

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

func Frustum

func Frustum(l, r, b, t, n, f float64) Matrix

func Identity

func Identity() Matrix

func LookAt

func LookAt(eye, center, up Vector) Matrix

func Orthographic

func Orthographic(l, r, b, t, n, f float64) Matrix

func Perspective

func Perspective(fovy, aspect, near, far float64) Matrix

func Rotate

func Rotate(v Vector, a float64) Matrix

func Scale

func Scale(v Vector) Matrix

func Translate

func Translate(v Vector) Matrix

func (Matrix) Determinant

func (a Matrix) Determinant() float64

func (Matrix) Frustum

func (m Matrix) Frustum(l, r, b, t, n, f float64) Matrix

func (Matrix) Inverse

func (a Matrix) Inverse() Matrix

func (Matrix) Mul

func (a Matrix) Mul(b Matrix) Matrix

func (Matrix) MulBox

func (a Matrix) MulBox(box Box) Box

func (Matrix) MulDirection

func (a Matrix) MulDirection(b Vector) Vector

func (Matrix) MulPosition

func (a Matrix) MulPosition(b Vector) Vector

func (Matrix) MulPositionW

func (a Matrix) MulPositionW(b Vector) Vector

func (Matrix) MulRay

func (a Matrix) MulRay(b Ray) Ray

func (Matrix) Orthographic

func (m Matrix) Orthographic(l, r, b, t, n, f float64) Matrix

func (Matrix) Perspective

func (m Matrix) Perspective(fovy, aspect, near, far float64) Matrix

func (Matrix) Rotate

func (m Matrix) Rotate(v Vector, a float64) Matrix

func (Matrix) Scale

func (m Matrix) Scale(v Vector) Matrix

func (Matrix) Translate

func (m Matrix) Translate(v Vector) Matrix

func (Matrix) Transpose

func (a Matrix) Transpose() Matrix

type Mesh

type Mesh struct {
	Box       Box
	Triangles []*Triangle
	Tree      *Tree
}

func LoadBinarySTL

func LoadBinarySTL(path string) (*Mesh, error)

func LoadOBJ

func LoadOBJ(path string) (*Mesh, error)

func LoadSTL

func LoadSTL(path string) (*Mesh, error)

func NewMesh

func NewMesh(triangles []*Triangle) *Mesh

func (*Mesh) BoundingBox

func (m *Mesh) BoundingBox() Box

func (*Mesh) Compile

func (m *Mesh) Compile()

func (*Mesh) Contains

func (m *Mesh) Contains(v Vector, f float64) bool

func (*Mesh) FitInside

func (m *Mesh) FitInside(box Box, anchor Vector)

func (*Mesh) Intersect

func (m *Mesh) Intersect(r Ray) Hit

func (*Mesh) MoveTo

func (m *Mesh) MoveTo(position, anchor Vector)

func (*Mesh) Paths

func (m *Mesh) Paths() Paths

func (*Mesh) SaveBinarySTL

func (m *Mesh) SaveBinarySTL(path string) error

func (*Mesh) Transform

func (m *Mesh) Transform(matrix Matrix)

func (*Mesh) UnitCube

func (m *Mesh) UnitCube()

func (*Mesh) UpdateBoundingBox

func (m *Mesh) UpdateBoundingBox()

func (*Mesh) Voxelize

func (m *Mesh) Voxelize(size float64) []*Cube

type Node

type Node struct {
	Axis   Axis
	Point  float64
	Shapes []Shape
	Left   *Node
	Right  *Node
}

func NewNode

func NewNode(shapes []Shape) *Node

func (*Node) Intersect

func (node *Node) Intersect(r Ray, tmin, tmax float64) Hit

func (*Node) IntersectShapes

func (node *Node) IntersectShapes(r Ray) Hit

func (*Node) Partition

func (node *Node) Partition(size int, axis Axis, point float64) (left, right []Shape)

func (*Node) PartitionScore

func (node *Node) PartitionScore(axis Axis, point float64) int

func (*Node) Split

func (node *Node) Split(depth int)

type Op

type Op int
const (
	Intersection Op = iota
	Difference
)

type OutlineCone

type OutlineCone struct {
	Cone
	Eye Vector
	Up  Vector
}

func NewOutlineCone

func NewOutlineCone(eye, up Vector, radius, height float64) *OutlineCone

func (*OutlineCone) Paths

func (c *OutlineCone) Paths() Paths

type OutlineCylinder

type OutlineCylinder struct {
	Cylinder
	Eye Vector
	Up  Vector
}

func NewOutlineCylinder

func NewOutlineCylinder(eye, up Vector, radius, z0, z1 float64) *OutlineCylinder

func (*OutlineCylinder) Paths

func (c *OutlineCylinder) Paths() Paths

type OutlineSphere

type OutlineSphere struct {
	Sphere
	Eye Vector
	Up  Vector
}

func NewOutlineSphere

func NewOutlineSphere(eye, up, center Vector, radius float64) *OutlineSphere

func (*OutlineSphere) Paths

func (s *OutlineSphere) Paths() Paths

type Path

type Path []Vector

func (Path) BoundingBox

func (p Path) BoundingBox() Box

func (Path) Chop

func (p Path) Chop(step float64) Path

func (Path) Filter

func (p Path) Filter(f Filter) Paths

func (Path) Print

func (p Path) Print()

func (Path) Simplify

func (p Path) Simplify(threshold float64) Path

func (Path) String

func (p Path) String() string

func (Path) ToSVG

func (p Path) ToSVG() string

func (Path) Transform

func (p Path) Transform(matrix Matrix) Path

type Paths

type Paths []Path

func (Paths) BoundingBox

func (p Paths) BoundingBox() Box

func (Paths) Chop

func (p Paths) Chop(step float64) Paths

func (Paths) Filter

func (p Paths) Filter(f Filter) Paths

func (Paths) Print

func (p Paths) Print()

func (Paths) Simplify

func (p Paths) Simplify(threshold float64) Paths

func (Paths) String

func (p Paths) String() string

func (Paths) ToSVG

func (p Paths) ToSVG(width, height float64) string

func (Paths) Transform

func (p Paths) Transform(matrix Matrix) Paths

func (Paths) WriteToPNG

func (p Paths) WriteToPNG(path string, width, height float64)

func (Paths) WriteToSVG

func (p Paths) WriteToSVG(path string, width, height float64) error

func (Paths) WriteToTXT

func (p Paths) WriteToTXT(path string) error

type Plane

type Plane struct {
	Point  Vector
	Normal Vector
}

func (*Plane) IntersectMesh

func (p *Plane) IntersectMesh(m *Mesh) Paths

func (*Plane) IntersectSegment

func (p *Plane) IntersectSegment(v0, v1 Vector) (Vector, bool)

func (*Plane) IntersectTriangle

func (p *Plane) IntersectTriangle(t *Triangle) (Vector, Vector, bool)

type Ray

type Ray struct {
	Origin, Direction Vector
}

func (Ray) Position

func (r Ray) Position(t float64) Vector

type STLHeader

type STLHeader struct {
	Count uint32
	// contains filtered or unexported fields
}

type STLTriangle

type STLTriangle struct {
	V1, V2, V3 [3]float32
	// contains filtered or unexported fields
}

type Scene

type Scene struct {
	Shapes []Shape
	Tree   *Tree
}

func (*Scene) Add

func (s *Scene) Add(shape Shape)

func (*Scene) Compile

func (s *Scene) Compile()

func (*Scene) Intersect

func (s *Scene) Intersect(r Ray) Hit

func (*Scene) Paths

func (s *Scene) Paths() Paths

func (*Scene) Render

func (s *Scene) Render(eye, center, up Vector, width, height, fovy, near, far, step float64) Paths

func (*Scene) RenderWithMatrix

func (s *Scene) RenderWithMatrix(matrix Matrix, eye Vector, width, height, step float64) Paths

func (*Scene) Visible

func (s *Scene) Visible(eye, point Vector) bool

type Shape

type Shape interface {
	Compile()
	BoundingBox() Box
	Contains(Vector, float64) bool
	Intersect(Ray) Hit
	Paths() Paths
}

func NewBooleanShape

func NewBooleanShape(op Op, shapes ...Shape) Shape

func NewDifference

func NewDifference(shapes ...Shape) Shape

func NewFunction

func NewFunction(function func(x, y float64) float64, box Box, direction Direction) Shape

func NewIntersection

func NewIntersection(shapes ...Shape) Shape

func NewTransformedOutlineCone

func NewTransformedOutlineCone(eye, up, v0, v1 Vector, radius float64) Shape

func NewTransformedOutlineCylinder

func NewTransformedOutlineCylinder(eye, up, v0, v1 Vector, radius float64) Shape

func NewTransformedShape

func NewTransformedShape(s Shape, m Matrix) Shape

type Sphere

type Sphere struct {
	Center Vector
	Radius float64
	Box    Box
}

func NewSphere

func NewSphere(center Vector, radius float64) *Sphere

func (*Sphere) BoundingBox

func (s *Sphere) BoundingBox() Box

func (*Sphere) Compile

func (s *Sphere) Compile()

func (*Sphere) Contains

func (s *Sphere) Contains(v Vector, f float64) bool

func (*Sphere) Intersect

func (s *Sphere) Intersect(r Ray) Hit

func (*Sphere) Paths

func (s *Sphere) Paths() Paths

func (*Sphere) Paths2

func (s *Sphere) Paths2() Paths

func (*Sphere) Paths3

func (s *Sphere) Paths3() Paths

func (*Sphere) Paths4

func (s *Sphere) Paths4() Paths

type TransformedShape

type TransformedShape struct {
	Shape
	Matrix  Matrix
	Inverse Matrix
}

func (*TransformedShape) BoundingBox

func (s *TransformedShape) BoundingBox() Box

func (*TransformedShape) Contains

func (s *TransformedShape) Contains(v Vector, f float64) bool

func (*TransformedShape) Intersect

func (s *TransformedShape) Intersect(r Ray) Hit

func (*TransformedShape) Paths

func (s *TransformedShape) Paths() Paths

type Tree

type Tree struct {
	Box  Box
	Root *Node
}

func NewTree

func NewTree(shapes []Shape) *Tree

func (*Tree) Intersect

func (tree *Tree) Intersect(r Ray) Hit

type Triangle

type Triangle struct {
	V1, V2, V3 Vector
	Box        Box
}

func NewTriangle

func NewTriangle(v1, v2, v3 Vector) *Triangle

func (*Triangle) BoundingBox

func (t *Triangle) BoundingBox() Box

func (*Triangle) Compile

func (t *Triangle) Compile()

func (*Triangle) Contains

func (t *Triangle) Contains(v Vector, f float64) bool

func (*Triangle) Intersect

func (t *Triangle) Intersect(r Ray) Hit

func (*Triangle) Paths

func (t *Triangle) Paths() Paths

func (*Triangle) UpdateBoundingBox

func (t *Triangle) UpdateBoundingBox()

type Vector

type Vector struct {
	X, Y, Z float64
}

func LatLngToXYZ

func LatLngToXYZ(lat, lng, radius float64) Vector

func RandomUnitVector

func RandomUnitVector() Vector

func (Vector) Add

func (a Vector) Add(b Vector) Vector

func (Vector) AddScalar

func (a Vector) AddScalar(b float64) Vector

func (Vector) Cross

func (a Vector) Cross(b Vector) Vector

func (Vector) Distance

func (a Vector) Distance(b Vector) float64

func (Vector) DistanceSquared

func (a Vector) DistanceSquared(b Vector) float64

func (Vector) Div

func (a Vector) Div(b Vector) Vector

func (Vector) DivScalar

func (a Vector) DivScalar(b float64) Vector

func (Vector) Dot

func (a Vector) Dot(b Vector) float64

func (Vector) Length

func (a Vector) Length() float64

func (Vector) LengthSquared

func (a Vector) LengthSquared() float64

func (Vector) Max

func (a Vector) Max(b Vector) Vector

func (Vector) Min

func (a Vector) Min(b Vector) Vector

func (Vector) MinAxis

func (a Vector) MinAxis() Vector

func (Vector) MinComponent

func (a Vector) MinComponent() float64

func (Vector) Mul

func (a Vector) Mul(b Vector) Vector

func (Vector) MulScalar

func (a Vector) MulScalar(b float64) Vector

func (Vector) Normalize

func (a Vector) Normalize() Vector

func (Vector) SegmentDistance

func (p Vector) SegmentDistance(v Vector, w Vector) float64

func (Vector) Sub

func (a Vector) Sub(b Vector) Vector

func (Vector) SubScalar

func (a Vector) SubScalar(b float64) Vector

Jump to

Keyboard shortcuts

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