convexhull | R Documentation |
Convex hull of a set of 2D or 3D points.
convexhull(points, faceFamilies = FALSE, epsilon = sqrt(.Machine$double.eps))
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 |
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
|
The convex hull.
If the dimension is 2, the returned value is a list with five fields:
The indices (i.e. the row numbers) of the points which form the convex hull.
A matrix giving the coordinates of the
points which from the convex hull; they are given by rows in
the order defined by verticesIds
.
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.
A number, the surface of the convex hull.
A number, the perimeter of the convex hull.
If the dimension is 3, the returned value is a list with five fields:
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.
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.
An integer matrix with two columns, representing the exterior edges of the convex hull.
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
.
A number, the surface of the convex hull.
A number, the volume of the convex hull.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.