{"id":13420532,"url":"https://github.com/danfis/libccd","last_synced_at":"2025-10-21T04:59:05.454Z","repository":{"id":4464804,"uuid":"5603558","full_name":"danfis/libccd","owner":"danfis","description":"Library for collision detection between two convex shapes","archived":false,"fork":false,"pushed_at":"2023-12-04T14:46:54.000Z","size":468,"stargazers_count":498,"open_issues_count":33,"forks_count":109,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-10-10T14:07:09.514Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danfis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-08-29T16:52:37.000Z","updated_at":"2024-10-10T05:13:34.000Z","dependencies_parsed_at":"2023-07-05T18:18:30.352Z","dependency_job_id":null,"html_url":"https://github.com/danfis/libccd","commit_stats":{"total_commits":142,"total_committers":8,"mean_commits":17.75,"dds":"0.21830985915492962","last_synced_commit":"7931e764a19ef6b21b443376c699bbc9c6d4fba8"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danfis%2Flibccd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danfis%2Flibccd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danfis%2Flibccd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danfis%2Flibccd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danfis","download_url":"https://codeload.github.com/danfis/libccd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221553292,"owners_count":16841999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:01:35.628Z","updated_at":"2025-10-21T04:59:00.402Z","avatar_url":"https://github.com/danfis.png","language":"C","readme":"# libccd [![Build Status](https://travis-ci.org/danfis/libccd.svg?branch=master)](https://travis-ci.org/danfis/libccd)\n\n***libccd*** is library for a collision detection between two convex shapes.\nlibccd implements variation on Gilbert–Johnson–Keerthi algorithm plus Expand\nPolytope Algorithm (EPA) and also implements algorithm Minkowski Portal\nRefinement (MPR, a.k.a. XenoCollide) as described in Game Programming Gems 7.\n\nlibccd is the only available open source library of my knowledge that include\nMPR algorithm working in 3-D space.  However, there is a library called\n[mpr2d](http://code.google.com/p/mpr2d/), implemented in D programming\nlanguage, that works in 2-D space.\n\nlibccd is currently part of:\n\n1. [ODE](http://www.ode.org/) library (see ODE's *./configure --help* how to enable it),\n2. [FCL](http://www.ros.org/wiki/fcl) library from [Willow Garage](http://www.willowgarage.com/),\n3. [Bullet3](http://bulletphysics.org/) library (https://github.com/bulletphysics/bullet3).\n\nFor implementation details on GJK algorithm, see\nhttp://www.win.tue.nl/~gino/solid/jgt98convex.pdf.\n\n\n## Dependencies\n\nThis library is currently based only on standard libraries.\nThe only exception are testsuites that are built on top of CU\n(https://github.com/danfis/cu) library licensed under LGPL, however only\ntesting depends on it and libccd library itself can be distributed without it.\n\n\n## License\n\nlibccd is licensed under OSI-approved 3-clause BSD License, text of license\nis distributed along with source code in BSD-LICENSE file.\nEach file should include license notice, the rest should be considered as\nlicensed under 3-clause BSD License.\n\n\n## Compile And Install\n\nlibccd contains several mechanisms for compiling and installing. Using a simple Makefile, using autotools, and using CMake.\n\n### 1. Using Makefile\n\nDirectory src/ contains Makefile that should contain everything needed for compilation and installation:\n```sh\n  $ cd src/\n  $ make\n  $ make install\n```\n\nLibrary libccd is by default compiled in double precision of floating point numbers - you can change this by options *USE_SINGLE/USE_DOUBLE*, i.e.:\n```sh\n  $ make USE_SINGLE=yes\n```\nwill compile library in single precision.\n\nInstallation directory can be changed by options PREFIX, INCLUDEDIR and LIBDIR. \nFor more info type 'make help'.\n\n### 2. Using Autotools\n\nlibccd also contains support for autotools:\nGenerate configure script etc.:\n```sh\n  $ ./bootstrap\n```\n\nCreate new build/ directory:\n```sh\n  $ mkdir build \u0026\u0026 cd build\n```\n\nRun configure script:\n```sh\n  $ ../configure\n```\n\nRun make and make install:\n```sh\n  $ make \u0026\u0026 make install\n```\n\nconfigure script can change the way libccd is compiled and installed, most significant option is *--enable-double-precision* which enables double precision (single is default in this case).\n\n### 3. Using CMake\n\nTo build using `make`:\n```sh\n  $ mkdir build \u0026\u0026 cd build\n  $ cmake -G \"Unix Makefiles\" ..\n  $ make \u0026\u0026 make install\n```\n\nTo build using `ninja`:\n```sh\n  $ mkdir build \u0026\u0026 cd build\n  $ cmake -G Ninja ..\n  $ ninja \u0026\u0026 ninja install\n```\n\nOther build tools may be using by specifying a different generator. For example:\n```sh\n  $ cmake -G Xcode ..\n```\n\n```bat\n  \u003e cmake -G \"Visual Studio 14 2015\" ..\n```\n\nTo compile using double precision, set the `ENABLE_DOUBLE_PRECISION` option:\n```sh\n  $ mkdir build \u0026\u0026 cd build\n  $ cmake -G \"Unix Makefiles\" -DENABLE_DOUBLE_PRECISION=ON ..\n  $ make \u0026\u0026 make install\n```\n\nTo build libccd as a shared library, set the `BUILD_SHARED_LIBS` option:\n```sh\n  $ mkdir build \u0026\u0026 cd build\n  $ cmake -G \"Unix Makefiles\" -DBUILD_SHARED_LIBS=ON ..\n  $ make \u0026\u0026 make install\n```\n\nTo build the test suite, set the `BUILD_TESTING` option:\n```sh\n  $ mkdir build \u0026\u0026 cd build\n  $ cmake -G \"Unix Makefiles\" -DBUILD_TESTING=ON ..\n  $ make \u0026\u0026 make test\n```\n\nThe installation directory may be changed using the `CMAKE_INSTALL_PREFIX` variable:\n```sh\n  $ mkdir build \u0026\u0026 cd build\n  $ cmake -G \"Unix Makefiles\" -DCMAKE_INSTALL_PREFIX=/path/to/install ..\n  $ make \u0026\u0026 make install\n```\n\n## GJK - Intersection Test\n\nThis section describes how to use libccd for testing if two convex objects intersects (i.e., 'yes/no' test) using Gilbert-Johnson-Keerthi (GJK) algorithm.\n\nProcedure is very simple (and is similar for usages of library):\n\n1. Include *\u003cccd/ccd.h\u003e* file.\n2. Implement support function for specific shapes. Support function is function that returns furthest point from object (shape) in specified direction.\n3. Set up *ccd_t* structure.\n4. Run ccdGJKIntersect() function on desired objects.\n\nHere is skeleton of simple program:\n```cpp\n  #include \u003cccd/ccd.h\u003e\n  #include \u003cccd/quat.h\u003e // for work with quaternions\n\n  /** Support function for box */\n  void support(const void *obj, const ccd_vec3_t *dir, ccd_vec3_t *vec)\n  {\n      // assume that obj_t is user-defined structure that holds info about\n      // object (in this case box: x, y, z, pos, quat - dimensions of box,\n      // position and rotation)\n      obj_t *obj = (obj_t *)_obj;\n      ccd_vec3_t dir;\n      ccd_quat_t qinv;\n\n      // apply rotation on direction vector\n      ccdVec3Copy(\u0026dir, _dir);\n      ccdQuatInvert2(\u0026qinv, \u0026obj-\u003equat);\n      ccdQuatRotVec(\u0026dir, \u0026qinv);\n\n      // compute support point in specified direction\n      ccdVec3Set(v, ccdSign(ccdVec3X(\u0026dir)) * box-\u003ex * CCD_REAL(0.5),\n                    ccdSign(ccdVec3Y(\u0026dir)) * box-\u003ey * CCD_REAL(0.5),\n                    ccdSign(ccdVec3Z(\u0026dir)) * box-\u003ez * CCD_REAL(0.5));\n\n      // transform support point according to position and rotation of object\n      ccdQuatRotVec(v, \u0026obj-\u003equat);\n      ccdVec3Add(v, \u0026obj-\u003epos);\n  }\n\n  int main(int argc, char *argv[])\n  {\n      ...\n\n      ccd_t ccd;\n      CCD_INIT(\u0026ccd); // initialize ccd_t struct\n\n      // set up ccd_t struct\n      ccd.support1       = support; // support function for first object\n      ccd.support2       = support; // support function for second object\n      ccd.max_iterations = 100;     // maximal number of iterations\n\n      int intersect = ccdGJKIntersect(obj1, obj2, \u0026ccd);\n      // now intersect holds true if obj1 and obj2 intersect, false otherwise\n  }\n```\n\n## GJK + EPA - Penetration Of Two Objects\n\nIf you want to obtain also penetration info about two intersection objects ccdGJKPenetration() function can be used.\n\nProcedure is almost same as for previous case:\n```cpp\n  #include \u003cccd/ccd.h\u003e\n  #include \u003cccd/quat.h\u003e // for work with quaternions\n\n  /** Support function is same as in previous case */\n\n  int main(int argc, char *argv[])\n  {\n      ...\n      ccd_t ccd;\n      CCD_INIT(\u0026ccd); // initialize ccd_t struct\n\n      // set up ccd_t struct\n      ccd.support1       = support; // support function for first object\n      ccd.support2       = support; // support function for second object\n      ccd.max_iterations = 100;     // maximal number of iterations\n      ccd.epa_tolerance  = 0.0001;  // maximal tolerance fro EPA part\n\n      ccd_real_t depth;\n      ccd_vec3_t dir, pos;\n      int intersect = ccdGJKPenetration(obj1, obj2, \u0026ccd, \u0026depth, \u0026dir, \u0026pos);\n      // now intersect holds 0 if obj1 and obj2 intersect, -1 otherwise\n      // in depth, dir and pos is stored penetration depth, direction of\n      // separation vector and position in global coordinate system\n  }\n```\n\n## MPR - Intersection Test\n\nlibccd also provides MPR - Minkowski Portal Refinement algorithm that can be used for testing if two objects intersects.\n\nProcedure is similar to the one used for GJK algorithm. Support function is same but also function that returns center (or any point near center) of given object must be implemented:\n```cpp\n  #include \u003cccd/ccd.h\u003e\n  #include \u003cccd/quat.h\u003e // for work with quaternions\n\n  /** Support function is same as in previous case */\n\n  /** Center function - returns center of object */\n  void center(const void *_obj, ccd_vec3_t *center)\n  {\n      obj_t *obj = (obj_t *)_obj;\n      ccdVec3Copy(center, \u0026obj-\u003epos);\n  }\n\n  int main(int argc, char *argv[])\n  {\n      ...\n      ccd_t ccd;\n      CCD_INIT(\u0026ccd); // initialize ccd_t struct\n\n      // set up ccd_t struct\n      ccd.support1       = support; // support function for first object\n      ccd.support2       = support; // support function for second object\n      ccd.center1        = center;  // center function for first object\n      ccd.center2        = center;  // center function for second object\n      ccd.mpr_tolerance  = 0.0001;  // maximal tolerance\n\n      int intersect = ccdMPRIntersect(obj1, obj2, \u0026ccd);\n      // now intersect holds true if obj1 and obj2 intersect, false otherwise\n  }\n```\n\n\n## MPR - Penetration Of Two Objects\n\nUsing MPR algorithm for obtaining penetration info about two intersection objects is equally easy as in previous case instead ccdMPRPenetration() function is used:\n```cpp\n  #include \u003cccd/ccd.h\u003e\n  #include \u003cccd/quat.h\u003e // for work with quaternions\n\n  /** Support function is same as in previous case */\n  /** Center function is same as in prevous case */\n\n  int main(int argc, char *argv[])\n  {\n      ...\n      ccd_t ccd;\n      CCD_INIT(\u0026ccd); // initialize ccd_t struct\n\n      // set up ccd_t struct\n      ccd.support1       = support; // support function for first object\n      ccd.support2       = support; // support function for second object\n      ccd.center1        = center;  // center function for first object\n      ccd.center2        = center;  // center function for second object\n      ccd.mpr_tolerance  = 0.0001;  // maximal tolerance\n\n      ccd_real_t depth;\n      ccd_vec3_t dir, pos;\n      int intersect = ccdMPRPenetration(obj1, obj2, \u0026ccd, \u0026depth, \u0026dir, \u0026pos);\n      // now intersect holds 0 if obj1 and obj2 intersect, -1 otherwise\n      // in depth, dir and pos is stored penetration depth, direction of\n      // separation vector and position in global coordinate system\n  }\n```\n","funding_links":[],"categories":["TODO scan for Android support in followings","Physics","[Libraries](#awesome-collision-detection)"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanfis%2Flibccd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanfis%2Flibccd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanfis%2Flibccd/lists"}