All Projects → leomccormack → convhull_3d

leomccormack / convhull_3d

Licence: MIT license
A header-only C implementation of the Quickhull algorithm for building N-dimensional Convex Hulls and Delaunay meshes

Programming Languages

c
50402 projects - #5 most used programming language
matlab
3953 projects

Projects that are alternatives of or similar to convhull 3d

quickhull
Header-only single-class implementation of Quickhull algorithm for convex hulls finding in arbitrary dimension (>1) space.
Stars: ✭ 47 (-56.48%)
Mutual labels:  quickhull, convex-hull
unity-animated-convexhull
Realtime fast convexhull generator for Unity
Stars: ✭ 40 (-62.96%)
Mutual labels:  quickhull, convexhull
tektosyne
The Tektosyne Library for Java provides algorithms for computational geometry and graph-based pathfinding, along with supporting mathematical utilities and specialized collections.
Stars: ✭ 52 (-51.85%)
Mutual labels:  computational-geometry, convex-hull
Cavaliercontours
2D polyline library for offsetting, combining, etc.
Stars: ✭ 135 (+25%)
Mutual labels:  computational-geometry
Cdt
C++ library for constrained Delaunay triangulation (CDT)
Stars: ✭ 165 (+52.78%)
Mutual labels:  computational-geometry
Projects
A list of awesome open source projects Vladimir Agafonkin is involved in.
Stars: ✭ 250 (+131.48%)
Mutual labels:  computational-geometry
hxDelaunay
Delaunay triangulations, Voronoi, convex hull and more. Ported to Haxe 3 from https://github.com/sledorze/hxDelaunay (itself a port of the excellent https://github.com/nodename/as3delaunay)
Stars: ✭ 30 (-72.22%)
Mutual labels:  convex-hull
Data structure and algorithms library
A collection of classical algorithms and data-structures implementation in C++ for coding interview and competitive programming
Stars: ✭ 133 (+23.15%)
Mutual labels:  computational-geometry
Tinfour
Delaunay and Constrained Delaunay Triangulations in Java, providing high-performance utilities for modeling surfaces with support for Lidar LAS files, Digital Elevation Models (DEM), finite element analysis, path planning, natural neighbor interpolation, and other applications of Triangulated Irregular Networks (TIN)
Stars: ✭ 119 (+10.19%)
Mutual labels:  computational-geometry
Skeleton Tracing
A new algorithm for retrieving topological skeleton as a set of polylines from binary images
Stars: ✭ 241 (+123.15%)
Mutual labels:  computational-geometry
Cgal
The public CGAL repository, see the README below
Stars: ✭ 2,825 (+2515.74%)
Mutual labels:  computational-geometry
Isect
Segments intersection detection library
Stars: ✭ 199 (+84.26%)
Mutual labels:  computational-geometry
Robust Predicates
Fast robust predicates for computational geometry in JavaScript
Stars: ✭ 170 (+57.41%)
Mutual labels:  computational-geometry
Geokdbush
The fastest spatial index for geographic locations in JavaScript
Stars: ✭ 251 (+132.41%)
Mutual labels:  computational-geometry
Rbush
RBush — a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles
Stars: ✭ 1,881 (+1641.67%)
Mutual labels:  computational-geometry
inpoly
A fast 'point(s)-in-polygon' test for MATLAB.
Stars: ✭ 17 (-84.26%)
Mutual labels:  computational-geometry
Hxgeomalgo
Small collection of computational geometry algorithms in Haxe.
Stars: ✭ 133 (+23.15%)
Mutual labels:  computational-geometry
Delaunator Cpp
A really fast C++ library for Delaunay triangulation of 2D points
Stars: ✭ 244 (+125.93%)
Mutual labels:  computational-geometry
homog2d
C++ 2D geometry library, handles points, lines, polylines, planar transformations (and other primitives), using homogeneous coordinates. Provided with complete manual and samples.
Stars: ✭ 70 (-35.19%)
Mutual labels:  computational-geometry
SplashGeom
Open-source C++ library for geometry and linear algebra
Stars: ✭ 22 (-79.63%)
Mutual labels:  computational-geometry

convhull_3d

A header only C implementation of the 3-D Quickhull algorithm for building Convex Hulls. The code is also compliant with MSVC and C++ compilers.

New! As of 28.05.2021: Added support for building N-dimensional Convex hulls and Delaunay meshes.

Getting Started

To use this 3-D Convex Hull implementation in a '.c' or '.cpp' file, first add the following:

#define CONVHULL_3D_ENABLE
#include "convhull_3d.h"

Then specify the vertices, which can be optionally extracted from an '.obj' file using the following code:

ch_vertex* vertices = NULL;
int nVertices;
extract_vertices_from_obj_file(OBJ_FILE_NAME, &vertices, &nVertices);
/* Where 'vertices' is a vector of vertices [nVertices].x, .y, .z  */

where 'OBJ_FILE_NAME' is the '.obj' file path (without the extension).

Or they may be defined manually, for example: a random distribution of points on the unit sphere:

int n = 936;
ch_vertex* vertices;
vertices = (ch_vertex*)malloc(n*sizeof(ch_vertex));
for (i = 0; i < n; i++) {
    float elev = rand()/(float)RAND_MAX * M_PI * 2.0;
    float azi = rand()/(float)RAND_MAX * M_PI * 2.0;
    vertices[i].x = cos(azi) * cos(elev) * rand()/(float)RAND_MAX;
    vertices[i].y = sin(azi) * cos(elev) * rand()/(float)RAND_MAX;
    vertices[i].z = sin(elev);
}

The Convex Hull may then be built and subsequently exported (including face normals) as an '.obj' file, using this code:

int* faceIndices = NULL;
int nFaces;
convhull_3d_build(vertices, nVertices, &faceIndices, &nFaces);
/* Where 'faceIndices' is a flat 2D matrix [nFaces x 3] */
convhull_3d_export_obj(vertices, nVertices, faceIndices, nFaces, 1, OUTPUT_OBJ_FILE_NAME);
free(vertices);
free(faceIndices);

where 'OUTPUT_OBJ_FILE_NAME' is the output '.obj' file path (without the extension).

Additional options

By default, the implementation uses double floating point precision to build the hull, while still exporting the results in single floating point precision. However, one may configure convhull_3d to use single precision to build the hull (which is less accurate and reliable, but quicker) by adding the following:

#define CONVHULL_3D_USE_SINGLE_PRECISION /* (optional) */
#define CONVHULL_3D_ENABLE
#include "convhull_3d.h"

If your project has CBLAS linked, then you may also speed up the matrix multiplications by adding:

#define CONVHULL_3D_USE_CBLAS /* (optional) */
#define CONVHULL_3D_USE_SINGLE_PRECISION /* (optional) */
#define CONVHULL_3D_ENABLE
#include "convhull_3d.h"

Test

This repository contains files: 'test/test_convhull_3d.c' and 'test/test_script.m'. The former can be used to generate Convex Hulls of the '.obj' files located in the 'test/obj_files' folder, which can be subsequently verified in MatLab using the latter file; where the 'convhull_3d.h' implementation is compared with MatLab's built-in 'convhull' function, side-by-side. Furthermore, Visual Studio 2017 and Xcode project files have been included in the 'test' folder for convenience.

Examples

The 'test/test_convhull_3d.c' file may also serve as example usage of the convhull_3d implementation. The following images are of the original 'obj' files (left) and the corresponding Convex Hulls (right), depicted using Tim Maxwell's OBJ Viewer:

Convex Hulls of uniformly distributed points on a sphere (180, 840, 5100 points left-to-right):

License

The code is distributed under the MIT license, but contains code that was originally written for MatLab by George Papazafeiropoulos (c) 2014; which was distributed under the BSD (2-clause) license and can be found here.

Contact

If you have any questions, or encounter any bugs, please email: [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].