Tutorial for Wykobi – A C++ Computational Geometry Library
wykobi.com
wykobi.com
The problem with most computational geometry libraries is that they tend to be 1) riddled with bugs, 2) slow and 3) covered by stupid licenses.
The license is nice. So, how is the accuracy and speed?
Hello, CGAL.
If I understand it correctly - If you are using it academically or in free software you can use it. If you are using it commercially you can pay a reasonable license fee and use it.
Sounds like a better solution than most; what am I missing?
https://www.ordnancesurvey.co.uk/resources/maps-and-geograph...
The problem with that is that you will soon want to construct geometrical entities. For example, if you intersect lines that have their ends on integer coordinates you can't represent the intersection on integers (You will need rationals, in that case). The same applies to floating point - two line segments with floating point coordinates will not have their intersection representable in floating point.
So for proper robustness in all situations you need "exact predicates and exact constructions". A middle ground is "exact predicates and inexact constructions". These modes are different kernels usable in e.g. CGAL. http://doc.cgal.org/latest/Kernel_23/group__kernel__predef.h...
Even something seemingly simple such as saying "is point C to the left or right of the line A->B" is very hard in floating point. It's possible without too much sweat to use kind of series expansion where the length of the expansion depends on the precision needed (you only go as far as you need to answer the predicate, so often only 2-3 terms) https://www.cs.cmu.edu/~quake/robust.html
Is it? ie - construct a normal and take a dot product. That'll work the vast majority of the time. Near the line you'll start running into the FP precision limits. With 64 (...or even 32) bit floats that sort of distance is likely way smaller than anything that represents a practical distance, so just call it and say you are on the line. Of late I've been messing about with problems of this nature and I can't say it's been all that difficult. https://github.com/deadsy/sdfx
You are right that this happens only in edge cases. But you don't want that in a cad program if you have anything doing e.g point-in-polygon, triangulation or other such algorithms.
I know from experience that you really should bake this into the very foundation of a cad package (if you see 2003 me, let him know)
You can solve the problem with extended integers, but not as easily as you would expect. In 2D, it takes something like 2n+logn bits of computation to accurately calculate things for n bits of coordinates. So you need more than 70 bits just to calculate 32 bits accurately. And we almost always need 64 bits, nowadays.
And this requires "binning" which breaks things like measurements of "parallel". It's not an easy problem, and it requires lots of test cases.
"Practical Segment Intersection with Finite Precision Output" http://ect.bell-labs.com/who/hobby/93_2-27.pdf
The problem is that once you start dealing with the actual coordinates of intersections, you have to start picking what properties you wish to keep and which you wish to abandon. Things like parallelism, inside vs outside, winding, handedness, etc. often get very murky once you start dealing with finite precision.
Other things are not suitable for GPUs performance wise. For example, if you have octree data structure and you query a lot, a CPU will perform better, because cache hierarchy (on CPU, the top level[s] of the tree will be in L1, the levels below in L2, etc., GPUs don’t have that), and because branch prediction.
Finally, not everything is computation bound. If your CPU code is fast enough to saturate IO bandwidth, be it HDD or network, you’re fine unless you have a million of servers. If you have a million of them, GPUs might still be worse they because might be more power efficient slightly decreasing your huge electricity bills.
Others you can check out:
- http://paperjs.org (especially "PaperScript" which does some magic to allow adding / multiplying etc. vectors if that's what you're after)
Also worth noting is that for most "computations" there is a likely a package available on npm
https://github.com/williame/csg.js is a fork where I made some performance improvements when I used it in a Ludum Dare game; dev vid https://www.youtube.com/watch?v=7zjz-hpm8No
[1] http://graphics.stanford.edu/courses/cs268-16-fall/Notes/tor...
[2] http://graphics.stanford.edu/courses/cs268-16-fall/notes.htm...