geometry

package
v0.0.0-...-a30bc99 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package geometry provides a geometry coordinate system and attendant functions for dealing with grids.

Index

Constants

View Source
const EAST = 2
View Source
const NORTH = 0
View Source
const NORTHEAST = 1
View Source
const NORTHWEST = 7
View Source
const SOUTH = 4
View Source
const SOUTHEAST = 3
View Source
const SOUTHWEST = 5
View Source
const WEST = 6

Variables

This section is empty.

Functions

func DirectionWord

func DirectionWord(direction int) string

DirectionWord returns the string description of a direction

func Distance

func Distance(a Point, b Point) float64

Distance returns the distance between two points

func InSlice

func InSlice(c Point, target []Point) bool

InSlice tests to see if a point is in a slice of points

func NearestPointIndex

func NearestPointIndex(p Point, coords []Point) int

NearestPointIndex finds the index in a slice of points of the nearest point to the given one

func OppositeDirection

func OppositeDirection(original int) int

OppositeDirection returns the opposite of a given compass direction

func PointInTriangle

func PointInTriangle(pt Point, t Triangle) bool

PointInTriangle determines if the given point is in the given triangle

func RandomDirection

func RandomDirection() int

RandomDirection returns a random compass direction

Types

type Circle

type Circle struct {
	Center Point
	Radius float64
}

Circle is a circle

func Circumcircle

func Circumcircle(triangle Triangle) Circle

Circumcircle calculates the circumcircle for a given triangle

type Edge

type Edge struct {
	A Point
	B Point
}

Edge is an undirected line

func GetUniqueEdges

func GetUniqueEdges(edges []Edge) []Edge

GetUniqueEdges returns all the unique edges in a slice

func (Edge) Equals

func (edge Edge) Equals(b Edge) bool

func (Edge) InSlice

func (edge Edge) InSlice(edges []Edge) bool

func (Edge) IsSharedByTriangles

func (e Edge) IsSharedByTriangles(triangles []Triangle) bool

IsEdgeSharedByTriangles checks to see if the given edge is shared by any of the triangles in the given slice

func (Edge) Length

func (edge Edge) Length() float64

Length returns the length of an edge

func (Edge) Slope

func (edge Edge) Slope() float64

Slope returns the slope of an edge

type Grid

type Grid struct {
	Coordinates [][]Point
	Height      int
	Width       int
}

Grid is a geometry

func GenerateGrid

func GenerateGrid(height int, width int) Grid

GenerateGrid procedurally generates a grid

type Point

type Point struct {
	X float64
	Y float64
}

Point is an x, y location

func Centroid

func Centroid(points []Point) Point

Centroid returns a point that is in the center of a polygon defined by the given points

func Circumcenter

func Circumcenter(triangle Triangle) Point

Circumcenter finds the circumcenter for a given triangle

func GenerateRandomPoints

func GenerateRandomPoints(height int, width int, number int) []Point

GenerateRandomPoints generates a set of random points inside the given height and width according to the number given

func GenerateRandomPointsByDimensions

func GenerateRandomPointsByDimensions(height int, width int, density float64) []Point

GenerateRandomPointsByDimensions generates a set of random points of the given height, width, and density. Density is a floating point number between 0 and 1.

func GetUniquePoints

func GetUniquePoints(points []Point) []Point

GetUniquePoints returns only unique points from a slice of points

func RandomPoint

func RandomPoint(height int, width int) Point

RandomPoint returns a random point in the given height and width

func RemoveClumps

func RemoveClumps(points []Point, distance float64) []Point

RemoveClumps removes all points from a given set of points that are closer than N distance

func RemovePoints

func RemovePoints(pointsToRemove []Point, target []Point) []Point

RemovePoints returns a slice of points with a set removed

func SortPointsByDistance

func SortPointsByDistance(source []Point) []Point

SortPointsByDistance sorts points by distance

func (Point) Equals

func (a Point) Equals(b Point) bool

Equals tests the equality of two points

func (Point) InCircle

func (p Point) InCircle(c Circle) bool

InCircle checks to see if the given point is in the given circle

type Polygon

type Polygon struct {
	Edges  []Edge
	Points []Point
}

Polygon is a polygon

func PolygonFromPoints

func PolygonFromPoints(points []Point) Polygon

PolygonFromPoints returns a polygon built from the given slice of points

type Triangle

type Triangle struct {
	A  Point
	B  Point
	C  Point
	AB Edge
	BC Edge
	CA Edge
}

Triangle is a triangle

func SuperTriangle

func SuperTriangle(points []Point) Triangle

SuperTriangle returns a triangle big enough to contain all of the given points

func TriangleFromPoints

func TriangleFromPoints(points []Point) Triangle

TriangleFromPoints returns a triangle based on a set of points

func (Triangle) Edges

func (t Triangle) Edges() []Edge

Edges returns all the edges of a triangle

func (Triangle) Equals

func (t Triangle) Equals(other Triangle) bool

Equals checks to see if a triangle equals another triangle

func (Triangle) RemoveFrom

func (t Triangle) RemoveFrom(triangles []Triangle) []Triangle

RemoveFrom removes a triangle from a slice of triangles

func (Triangle) ToPolygon

func (t Triangle) ToPolygon() Polygon

ToPolygon turns a triangle into a polygon

func (Triangle) Vertices

func (t Triangle) Vertices() []Point

Vertices returns a slice of the points of the given triangle

type TriangleMesh

type TriangleMesh struct {
	Triangles []Triangle
	Nodes     []Point // the centroids of each triangle
	Vertices  []Point
	Edges     []Edge
}

TriangleMesh is a mesh of triangles

func BowyerWatson

func BowyerWatson(points []Point) TriangleMesh

BowyerWatson returns a Delaunay triangulation of the given points using the Bowyer-Watson algorithm.

Jump to

Keyboard shortcuts

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