homog2d icon indicating copy to clipboard operation
homog2d copied to clipboard

C++ 2D geometry library, handles points, lines, polylines, planar transformations (and other primitives), using homogeneous coordinates. Provided with complete manual and samples.

homog2d

Current test status: Build Status License: MPLv2

A single-file header-only C++ library dedicated to handling 2D lines, points and homographies (2D planar transformations), using (internally) homogeneous coordinates. Also handles other geometric primitives.

showcase1

(see other demos here)

  • Language: C++14
  • Home: https://github.com/skramm/homog2d
  • Usage: just fetch the file homog2d.hpp, put it somewhere, and "#include" it in your source file. No build!
  • Status: beta
  • Author: Sebastien Kramm, [email protected]
  • Licence: MPLv2

Short preview:

#include "homog2d.hpp"
using namespace h2d;
int main()
{
	Line2d l1( Point2d(10,10) );               // a line passing through (0,0) and (10,10)
	Line2d l2( Point2d(0,10), Point2d(10,0) ); // a line passing through (0,10) and (10,0)
	Point2d pt = l1 * l2;                      // intersection point (5,5)
	Homogr H(2,3);                             // a translation matrix
	std::cout << H * pt;                       // prints [7,8]
}

News

  • 2022-08-30: added SVG import
  • 2022-08-02: fresh 2.8 release, see https://github.com/skramm/homog2d/releases
  • 2022-05-18: 2.7 release

(see history for more)

Details

  • Install: to install on your machine, copy file homog2d.hpp somewhere where your compiler can reach it, or $ sudo make install after cloning repo. This will copy that file in /usr/local/include.

  • Audience: any C++ dev requiring some basic computational geometry, without the burden of large scale framework.

  • Usage: see full manual

  • Reference: once downloaded, enter $ make doc (requires Doxygen).

  • A test file is provided, needs Catch. When installed, run $ make test (or $ make testall for testing with all 3 numerical types).

  • Contributing: at present, the best you can do is testing and bug/issue reporting. Don't hesitate, this is still beta but stable release expected soon.

  • Rationale:

    • Usage simplicity, max flexibility
    • No dependency (*)
    • Modern C++, using policy-based design, tag dispatching, sfinae, ...
    • Direct bindings with OpenCv (optional)
  • Geometric features:

    • basic primitives: points, lines, segments, circles, rectangles, polygons, ellipse,
    • planar transformation of any of these (rotation, translation, ...),
    • computing of intersection points between these,
    • easy binding with other libs,
    • ...
  • Related libraries:

    • Opencv the reference CV library, much more algorithms, but no direct support for homogeneous geometry.
    • Wykobi, has much more computational geometry features but no direct support for homogeneous geometry.

Warning: The images shown in the manual are there just there as an illustration of what the library does, but there is no rendering code included. The library provides drawing function whose implementation requires external code. The images are drawn using a third-party library, but it is not needed to use this library.

(*): Except for some additional features, see manual.