How to find intersection points between two cubic bezier curve

时光怂恿深爱的人放手 提交于 2019-11-28 11:43:56
MBo

There are two main methods to find a Bezier curve intersection:

  1. Recursive subdivision exploits the convex hull property of Bezier curves and usually checks the intersection of bounding boxes of its curve segments.

Code from book Graphics Gems IV with some textual description

  1. Numerical solution of the system of two cubic equations. It leads to a polynomial equation of the 9th order and may have 9 real roots (case of two S-shaped curves). Note that the solution is numerically unstable.

JS code and interactive demonstration And I think C++ code might be in Geometric Tools WildMagic library.

A cubic bezier curve is just a cubic polynomial equation. If you want to find when two cubics intersect, then you want to find when the two cubics are equal, i.e.

a1x3 + b1x2 + c1x + d1 = a2x3 + b2x2 + c2x + d2

Then that's the same as finding the roots of the cubic equation

(a1 - a2)x3 + (b1 - b2)x2 + (c1 - c2)x + (d1 - d2) = 0

Cubic equations, like that can be solved analytically, see e.g. Cardano's method. Alternatively, a method such as Newton–Raphson can be used to iterate to the solution. Beware, though, cubics can have up to 3 points where they're equal to zero.

My suggestion may be not very efficient but it can work. You can try comparing distances between points of two curves, and the closest two points would be your cross "points".

If some approximation is permitted, you could convert the bezier curves into lots of small straight lines and then compute intersections between pairs of them generated from both curves. This is a much easier problem to solve as you only have to solve linear equations and may provide sufficient performance and accuracy for your use case.

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