Find the intersection(s) of a pair of QuadCurve2Ds

早过忘川 提交于 2019-12-05 11:52:52
MvG

Depends on whether you're interested in approximate or in exact solutions (up to double precision). For approximate ones, you could simply parametrize the curves as some function f(t) and then do some interval nesting to find values for t which minimize the distance between the curves.

For exact solutions, you'd have to find the four points where two conic sections intersect. There is a short paragraph about this on wikipedia. The book Perspectives on Projective Geometry has a longer section explaining the details. There certainly are implementations available for various languages; the one for Asymptote comes to my mind just now. The implementation for its general case looks quite frightening, though, so it might be they are doing something overly complicated there.

Once you have all four points of intersection, you'd still have to decide which of them are on the part of the conic section delimited by the endpoints of your QuadCurve, but that should be simple in comparison. So in total, you'd have these three steps:

  1. Compute matrix of conic sections section from endpoints and control points
  2. Intersect conic sections using degenerat elements in their pencil
  3. Decide whether these intersections lie between the endpoints

If you have a problem with the mathematical details of one of these steps, it might be better to ask on the mathematics stack exchange. Not only have people there more experience with solving mathematical problems, the MathJax features for typesetting math will make the answers far more readable than an answer here could hope to be.

As to your note 2 about the straight line: that is easier by far, because if you express that problem in terms of coordinates, you'd only end up with a quadratic equation, instead of an equation of degree 4 for the naive approach to the general problem, and still degree 3 if you solve it as described by the above references. One can write the general aproach in such a way that intersecting a conic with a line is a step in the solution, so having a method for this might work well enough.

A pragmatic approach would be creating two Areas by adding the curves and closing the results, The intersection of these Areas should have all the original points of intersection as endpoints of some segments. So iterate over the resulting path, disregard any Bézier control points, and for the each segment end point encountered, check whether it lies on the original curves.

Or have a look at the implementation of how Area does this, and see if you can adapt this to your needs. If your licensing allows including GPL2 code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!