triangle

package
v0.0.0-...-9c88ebf Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: BSD-3-Clause Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Small = 1e-6

Functions

This section is empty.

Types

type BT

type BT struct {
	Pt   d3.Pt
	U, V d3.V
}

BT is a triangle expressed barycentrically

func (*BT) PtB

func (bt *BT) PtB(b barycentric.B) d3.Pt

PtB translates a barycentric coordinate to a d3 Pt

func (*BT) Triangle

func (bt *BT) Triangle() *Triangle

Triangle translates from a Barycentric representation to 3 d3.Pts

type ErrCoincidentVerticies

type ErrCoincidentVerticies struct{}

ErrCoincidentVerticies indicates that a Triangle has at least 2 identical points.

func (ErrCoincidentVerticies) Error

Error fulfils the error interface

type Intersection

type Intersection struct {
	U, V, T float64
	Does    bool
}

Intersection of a line an a triangle. The U and V values indicate the coordinate on the triangle and T indicates the point on the line. Does indicates if there was any intersection. If a line intersects a triangle and a transformation is applied to both, the Intersection will still give the correct values.

type Triangle

type Triangle [3]d3.Pt

Triangle in 3D

func (Triangle) BT

func (t Triangle) BT(origin, u int, buf *BT) *BT

BT translates a Triangle into a Barycentric representation of a triangle

func (*Triangle) Intersection

func (t *Triangle) Intersection(l line.Line) Intersection

Intersection returns the intersection point if there is one and bool indicating if there was an intersection.

func (*Triangle) Intersections

func (t *Triangle) Intersections(l line.Line) []float64

Intersections returns the intersection as a []float64

func (*Triangle) Intersector

func (t *Triangle) Intersector() *TriangleIntersector

Intersector creates a TriangleIntersector that caches some of the computation for finding the intersections between the triangle and a line.

func (*Triangle) LineIntersection

func (t *Triangle) LineIntersection(l line.Line) (float64, bool)

LineIntersection returns the intersection point if there is one and bool indicating if there was an intersection.

func (*Triangle) Normal

func (t *Triangle) Normal() d3.V

Normal returns a vector that is perpendicular to the plane of the triangle.

func (*Triangle) Validate

func (t *Triangle) Validate() error

Validate that a triangle has 3 unique points.

type TriangleIntersector

type TriangleIntersector struct {
	T0     d3.Pt
	V1, V2 d3.V
}

TriangleIntersector expresses a triangle as a point and 2 vectors which is the first step of computing line intersections.

func (*TriangleIntersector) Intersection

func (t *TriangleIntersector) Intersection(l line.Line) Intersection

Intersection checks if the given line intersects the triangle.

func (*TriangleIntersector) LineIntersection

func (t *TriangleIntersector) LineIntersection(l line.Line) (float64, bool)

LineIntersection checks if the line intersects the triangle. It can only intersect once so the return is a float and a bool. The float indicates where the intersection occured and the bool indicates if there was an intersection.

func (*TriangleIntersector) RawIntersection

func (t *TriangleIntersector) RawIntersection(l line.Line) Intersection

RawIntersection saves overhead by doing all the calculation in place rather than calling functions. For raytracing it was shown to be a significant improvement.

Jump to

Keyboard shortcuts

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