quickhull

package module
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: MIT Imports: 3 Imported by: 6

README

quickhull-go

image

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/v2

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/v2"
)

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConvexHull

type ConvexHull struct {
	Vertices []r3.Vector
	Indices  []int
	// contains filtered or unexported fields
}

func (ConvexHull) Triangles

func (hull ConvexHull) Triangles() [][3]r3.Vector

type Face

type Face struct {
	HalfEdge int // Index of a bounding HalfEdge
}

Face of a half edge. See: https://www.openmesh.org/media/Documentations/OpenMesh-6.3-Documentation/a00010.html

type HalfEdge

type HalfEdge struct {
	EndVertex int // Index of end vertex
	Opp       int // Index of opposite HalfEdge
	Face      int // Index of Face it belongs to
	Next      int // Index of next HalfEdge
}

HalfEdge is a half edge. See: https://www.openmesh.org/media/Documentations/OpenMesh-6.3-Documentation/a00010.html

type HalfEdgeMesh

type HalfEdgeMesh struct {
	Vertices  []r3.Vector
	Faces     []Face
	HalfEdges []HalfEdge
}

HalfEdgeMesh is a mesh consisting of half edges. See: https://www.openmesh.org/media/Documentations/OpenMesh-6.3-Documentation/a00010.html

type QuickHull

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

QuickHull can be used to calculate the convex hull of a point cloud. See: https://en.wikipedia.org/wiki/Quickhull

func (*QuickHull) ConvexHull

func (qh *QuickHull) ConvexHull(pointCloud []r3.Vector, ccw bool, useOriginalIndices bool, epsilon float64) ConvexHull

ConvexHull calculates the convex hull of the given point cloud using the Quickhull algorithm. If epsilon is <= 0 a default value will be used.

func (*QuickHull) ConvexHullAsMesh

func (qh *QuickHull) ConvexHullAsMesh(pointCloud []r3.Vector, epsilon float64) HalfEdgeMesh

ConvexHull calculates the convex hull of the given point cloud using the Quickhull algorithm and returns it as a HalfEdgeMesh. If epsilon is <= 0 a default value will be used.

Jump to

Keyboard shortcuts

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