A single-file header-only C++ library dedicated to handling 2D lines, points and homographies (2D planar transformations) in Cartesian geometry, using internally homogeneous coordinates. Also handles other geometric primitives, see full manual.
(see other demos here)
- Language: C++14 or C++17
- 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, firstname.lastname@univ-rouen.fr
- 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)
auto pt = l1 * l2; // intersection point (5,5)
Homogr H(2,3); // a translation matrix
std::cout << H * pt; // prints [7,8]
}
- 2024-04-21: switch to c++17, enable runtime polymorphism using
std::variant
, see here - 2024-03-23: added SVG "path" element import
- 2023-12-26: fresh 2.11 release, see https://github.com/skramm/homog2d/releases
- 2023-11-17: added doc index
- 2023-07-11: added online Doxygen-generated reference, through the great https://codedocs.xyz/ see here
- 2023-02-19: 2.10 release, see https://github.com/skramm/homog2d/releases
- 2023-02-12: added support for "big numbers" through the ttmath library, see here) (preliminar!)
(see history for more)
-
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, or Doxygen-generated pages online.
-
Reference: once downloaded, enter
$ make doc
(requires Doxygen), or read online. -
A test file is provided, needs Catch2. 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 other libraries (OpenCv, Boost Geometry) (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,
- enclosing determination
- ...
-
Related libraries:
- CGAL, the reference computational geometry library.
- Boost Geometry, a highly generic library with some overlapping features (but quite harder to use)
- 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 functions, that can be used to generate Svg files. An alternative is to use a supported third-party library (Opencv), but the latter is not needed to use this library.
(*): Except for some additional features, see manual.