Skip to content

3D convex hull (quickhull) algorithm in Go

License

Notifications You must be signed in to change notification settings

marccardinal/quickhull-go

 
 

Repository files navigation

quickhull-go

A 3D Quickhull implementation in Go.

Big thanks to @akuukka for their public domain C++ implementation which was used as a reference.

This is different from Google's S2 Geometry implementation because it works in ℝ³ instead of S².

GoDoc Build Status codecov Go Report License FOSSA Status

Go Get

go get -u github.com/markus-wa/quickhull-go

Example

Example with a simple, planar point-cloud.

package main

import (
	"fmt"

	r3 "github.com/golang/geo/r3"
	quickhull "github.com/markus-wa/quickhull-go"
)

func main() {
	pointCloud := []r3.Vector{
		{X: 1, Y: 2, Z: 1},
		{X: 4, Y: 7, Z: 1},
		{X: 7, Y: 2, Z: 1},
		{X: 4, Y: 4, Z: 1}, // This point is inside the hull
	}

	hull := new(QuickHull).ConvexHull(pointCloud, true, false, 0)

	fmt.Println(hull.Vertices) // does not contain (4,4,1)
	fmt.Println(hull.Triangles()) // triangles that make up the convex hull - [][3]r3.Vector, where each vector is a corner of the triangle
}

License

This project is licensed under the MIT license.

FOSSA Status

About

3D convex hull (quickhull) algorithm in Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%