convexhull: Convex hull

View source: R/convexhull.R

convexhullR Documentation

Convex hull

Description

Convex hull of a set of 2D or 3D points.

Usage

convexhull(points, faceFamilies = FALSE, epsilon = sqrt(.Machine$double.eps))

Arguments

points

numeric matrix which stores the points, one point per row

faceFamilies

Boolean, for 3D only; faces are always triangular, and the family of a face is the set of faces adjacent and coplanar with this face (in other words, the coplanar neighbors of this face); set this argument to TRUE if you want the face families; this gives a label of the family for each face, or NA is the face is "alone" (has no coplanar neighbor); this is useful for plotting (see the examples in plotConvexHull3D)

epsilon

for 3D only, zero or a small nonnegative number; this number plays a role in the detection of exterior edges: a higher value of epsilon yields less exterior edges; the last example of plotConvexHull3D illustrates the usage of epsilon

Value

The convex hull.

  • If the dimension is 2, the returned value is a list with five fields:

    verticesIds

    The indices (i.e. the row numbers) of the points which form the convex hull.

    vertices

    A matrix giving the coordinates of the points which from the convex hull; they are given by rows in the order defined by verticesIds.

    edges

    A matrix of integers with two columns which represents the edges; each row provides two indices, the the indices of the two points which form the edge.

    surface

    A number, the surface of the convex hull.

    perimeter

    A number, the perimeter of the convex hull.

  • If the dimension is 3, the returned value is a list with five fields:

    vertices

    A list which represents the vertices of the convex hull. This is a list of lists, each sublist represents one vertex, by giving its index and its coordinates.

    edges

    An integer matrix with two columns, representing the edges of the convex hull. So each row is composed of two integers: the indices of the two points which form the edge.

    exteriorEdges

    An integer matrix with two columns, representing the exterior edges of the convex hull.

    faces

    A matrix of integers with three columns which represents the faces (these are triangles); each row provides the indices of the three points which form the face. This matrix has three attributes: areas, which provides the areas of the faces, normals, which provides the normals of the faces, circumcenters, which provides the circumcenters of the faces, and families if you set faceFamilies=TRUE.

    surface

    A number, the surface of the convex hull.

    volume

    A number, the volume of the convex hull.

Examples

library(RCGAL)
# 2D example ####
pts <- rbind(
  c(-1, -1),
  c(-1,  1),
  c( 1, -1),
  c( 1,  1),
  c( 2,  0),
  c( 0,  2),
  c(-2,  0),
  c( 0, -2)
)
hull <- convexhull(pts)
# it's easy to plot a 2D convex hull:
plot(hull[["vertices"]], asp = 1, pch = 19)
polygon(hull[["vertices"]], col = "green")

# a 3D example ####
cube <- rbind(
  c(-1, -1, -1),
  c(-1, -1,  1),
  c(-1,  1, -1),
  c(-1,  1,  1),
  c( 1, -1, -1),
  c( 1, -1,  1),
  c( 1,  1, -1),
  c( 1,  1,  1),
  c( 0,  0,  0)
)
hull <- convexhull(cube)
hull[["vertices"]][[1]]
# the non-border edges are the diagonals of the faces:
hull[["edges"]]
hull[["surface"]]
hull[["volume"]]
# plot:
library(rgl)
open3d(windowRect = c(50, 50, 562, 562))
plotConvexHull3D(hull)

stla/RCGAL documentation built on June 15, 2022, 6:45 a.m.