geometry

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MIT Imports: 5 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 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) 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) 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) Intersection

func (l Line3D) Intersection(plane Plane) vector3.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 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