5

Is there a simple geometry library for C++?

Just classes for points and lines, and the most basic and common functions such as getting the line length via Pythagorean theorem, calculating the intersection point of 2 lines, checking if 2 lines are parallel, things like that.

Bonus points if it is just a header and source file so I can include it directly into projects without building it separately.

Old Stack Overflow question for reference: Geometry library in C++.

2

You can use the Cairo libraries,

They may not be the easiest around, but they sure are enstablished. Inkscape and many other top notch projects use them. They also provide font rendering and a lot of other stuff.

They were proposed to become part of the standard library in the next iteration of ISO C++.

Not sure if that proposal went through, but you get the idea of how interoperable and well built those libraries are.

  • 2
    I see Cairo is for drawing graphics. I just want to clarify that my question was about the computational part. Such a library could be used by programs that read a bunch of coordinates from a text file and store the results in a text file. – sashoalm Feb 5 '15 at 9:14
1

Depends on what you want.

Boost has two geometry libraries, boost::geometry which is not robust but has advanced stuff like non-euclidean geometry (such as latitude/longitude on the Earth) and boost::polygon which is robust but doesn't have as many features.

CGAL is another popular one, which is also robust but can sometimes be slow. Some parts of CGAL are not free software.

Wykobi is less popular but still very good. It is not robust.

Robust libraries always provide things like topological guarantees, exact predicates etc. Non-robust libraries are usually faster but may produce geometrically incorrect results in some situations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.