geometry

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoIntersection = errors.New("no intersection")

ErrNoIntersection is thrown when Intersection() contains no intersection

Functions

This section is empty.

Types

type AABB added in v0.3.0

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

func NewAABB added in v0.3.0

func NewAABB(center, size vector3.Float64) AABB

func NewAABBFromPoints added in v0.3.0

func NewAABBFromPoints(points ...vector3.Float64) AABB

func NewEmptyAABB added in v0.3.0

func NewEmptyAABB() AABB

func (AABB) Center added in v0.3.0

func (aabb AABB) Center() vector3.Float64

func (AABB) ClosestPoint added in v0.3.0

func (aabb AABB) ClosestPoint(v vector3.Float64) vector3.Float64

func (AABB) Contains added in v0.3.0

func (aabb AABB) Contains(p vector3.Float64) bool

func (*AABB) EncapsulateBounds added in v0.3.0

func (aabb *AABB) EncapsulateBounds(b AABB)

func (*AABB) EncapsulatePoint added in v0.3.0

func (aabb *AABB) EncapsulatePoint(p vector3.Float64)

func (*AABB) Expand added in v0.3.0

func (aabb *AABB) Expand(amount float64)

func (AABB) IntersectsRayInRange added in v0.3.0

func (aabb AABB) IntersectsRayInRange(ray Ray, min, max float64) bool

IntersectsRayInRange determines whether or not a ray intersects the bounding box with the range of the ray between min and max

Intersection method by Andrew Kensler at Pixar, found in the book "Ray Tracing The Next Week" by Peter Shirley

func (AABB) MarshalJSON added in v0.8.0

func (aabb AABB) MarshalJSON() ([]byte, error)

func (AABB) Max added in v0.3.0

func (aabb AABB) Max() vector3.Float64

func (AABB) Min added in v0.3.0

func (aabb AABB) Min() vector3.Float64

func (*AABB) SetMinMax added in v0.3.0

func (aabb *AABB) SetMinMax(min, max vector3.Float64)

func (AABB) Size added in v0.3.0

func (aabb AABB) Size() vector3.Float64

func (*AABB) UnmarshalJSON added in v0.8.0

func (aabb *AABB) UnmarshalJSON(data []byte) error

type Line2D

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

Line2D represents a line segment

func NewLine2D

func NewLine2D(p1, p2 vector2.Float64) Line2D

NewLine2D create a new line

func (Line2D) ClosestPointOnLine

func (l Line2D) ClosestPointOnLine(p vector2.Float64) vector2.Float64

func (Line2D) Dir

func (l Line2D) Dir() vector2.Float64

Dir is end point - starting point

func (Line2D) ExtendEnd added in v0.10.0

func (l Line2D) ExtendEnd(amount float64) Line2D

func (Line2D) ExtendStart added in v0.10.0

func (l Line2D) ExtendStart(amount float64) Line2D

func (Line2D) GetEndPoint

func (l Line2D) GetEndPoint() vector2.Float64

GetEndPoint returns the end point of the line segment

func (Line2D) GetStartPoint

func (l Line2D) GetStartPoint() vector2.Float64

GetStartPoint returns the starting point of the line segment

func (Line2D) Intersection

func (l Line2D) Intersection(other Line2D) (vector2.Float64, error)

Intersection finds where two lines intersect https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect

func (Line2D) Intersects

func (l Line2D) Intersects(other Line2D) bool

Intersects determines whether two lines intersect eachother

func (Line2D) ScaleOutwards

func (l Line2D) ScaleOutwards(amount float64) Line2D

ScaleOutwards multiplies the current length of the line by extending it out further in the two different directions it's heading

type Line3D

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

Line3D is a series of ordered points that make up a line segment through 3D space.

func NewLine3D

func NewLine3D(p1, p2 vector3.Float64) Line3D

NewLine3D create a new line

func (Line3D) ClosestPointOnLine

func (l Line3D) ClosestPointOnLine(p vector3.Float64) vector3.Float64

func (Line3D) ClosestTimeOnLine added in v0.10.0

func (l Line3D) ClosestTimeOnLine(p vector3.Float64) float64

func (Line3D) GetEndPoint

func (l Line3D) GetEndPoint() vector3.Float64

GetEndPoint returns the end point of the line segment

func (Line3D) GetStartPoint

func (l Line3D) GetStartPoint() vector3.Float64

GetStartPoint returns the starting point of the line segment

func (Line3D) IntersectionPointOnPlane added in v0.6.0

func (l Line3D) IntersectionPointOnPlane(plane Plane) (vector3.Float64, bool)

func (Line3D) IntersectionTimeOnPlane added in v0.6.0

func (l Line3D) IntersectionTimeOnPlane(plane Plane) (float64, bool)

func (Line3D) Length added in v0.10.0

func (l Line3D) Length() float64

func (Line3D) ScaleOutwards

func (l Line3D) ScaleOutwards(amount float64) Line3D

ScaleOutwards assumes line segment 3d is only two points multiplies the current length of the line by extending it out further in the two different directions it's heading

func (Line3D) SetEndPoint

func (l Line3D) SetEndPoint(newEnd vector3.Float64) Line3D

func (Line3D) SetStartPoint

func (l Line3D) SetStartPoint(newStart vector3.Float64) Line3D

func (Line3D) Translate

func (l Line3D) Translate(amt vector3.Float64) Line3D

func (Line3D) YIntersection

func (l Line3D) YIntersection(x float64, z float64) float64

YIntersection Uses the paremetric equations of the line

type Orientation

type Orientation int
const (
	Colinear Orientation = iota
	Clockwise
	Counterclockwise
)

type Plane

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

func NewPlaneFromPoints

func NewPlaneFromPoints(a, b, c vector3.Float64) Plane

func (Plane) ClosestPoint

func (p Plane) ClosestPoint(point vector3.Float64) vector3.Float64

func (Plane) Normal

func (p Plane) Normal() vector3.Float64

func (Plane) Origin

func (p Plane) Origin() vector3.Float64

type Ray added in v0.3.0

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

func NewRay added in v0.3.0

func NewRay(origin vector3.Float64, direction vector3.Float64) Ray

func (Ray) At added in v0.3.0

func (r Ray) At(t float64) vector3.Float64

func (Ray) Direction added in v0.3.0

func (r Ray) Direction() vector3.Float64

func (Ray) Origin added in v0.3.0

func (r Ray) Origin() vector3.Float64

type Shape

type Shape []vector2.Float64

Shape is a flat (2D) arrangement of points.

func (Shape) GetBoundingBoxDimensions

func (s Shape) GetBoundingBoxDimensions() (width, height float64)

func (Shape) GetBounds

func (s Shape) GetBounds() (vector2.Float64, vector2.Float64)

func (Shape) IsInside

func (s Shape) IsInside(p vector2.Float64) bool

IsInside returns true if the point p lies inside the polygon[] with n vertices

func (Shape) Len

func (s Shape) Len() int

Len returns the number of points in the polygon

func (Shape) Less

func (s Shape) Less(i, j int) bool

Less determines which point is more oriented more clockwise from the center than the other

func (Shape) RandomPointInShape

func (s Shape) RandomPointInShape() vector2.Float64

RandomPointInShape returns a random point inside of the shape

func (Shape) Rotate

func (s Shape) Rotate(amount float64, pivot vector2.Float64) Shape

Rotate will rotate all points in the shape around the pivot by the passed in amount

func (Shape) Scale

func (s Shape) Scale(amount float64, origin vector2.Float64) Shape

Scale shifts all points towards or away from the origin

func (Shape) Split

func (s Shape) Split(vericalLine float64) ([]Shape, []Shape)

Split figures out which points land on which side of the vertical line and builds new shapes from that

func (Shape) Swap

func (s Shape) Swap(i, j int)

Swap switches two points indeces so the polygon is ordered a different way

func (Shape) Translate

func (s Shape) Translate(amount vector2.Float64) Shape

Translate Moves all points over by the specified amount

Jump to

Keyboard shortcuts

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