Re: [help] fast intersection calculation between bezier & rectangle



On 2007-05-19, Dave Eberly <dNOSPAMeberly@xxxxxxxxxxxxxxx> wrote:
<Ylem.GL@xxxxxxxxx> wrote in message
news:1179564418.999716.61620@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm currently working on a 2D drawing app which allows users to
drag their mouses in the canvas to select from a lot of bezier curves.
To figure out which bezier curves are selected seems a bit difficult
to me.
I tried to sample the bezier into dozens of line segments and
calculate the intersection between the line segments and the selection
rectangle, but it seems not very efficient (especially when the number
of curves grows to 50+)

Can anyone give me some suggestions on how to figure out the
intersect set much more efficiently, please?

Using your approach, preprocess the line segments of the polylines
that approximate the curves. Compute the axis-aligned bounding boxes
of the segments. Sort the projections of these relative to the x-axis.
Now when a user creates a tracking rectangle, you can quickly locate
which segments the rectangle edges potentially intersect by locating
those axis-aligned boxes that the rectangle edges intersect. The idea
is effectively that of http://www.cs.cmu.edu/~baraff/sigcourse/notesd2.pdf .

Also look at the recent thread in this newsgroup; the subject is
"Intersection of bezier and straight line". You can compute the
intersection of rectangle edge and Bézier curve directly by converting
the problem to computing the roots of a polynomial. Finding roots can
also be computationally expensive. As a quick "no intersection", you
can use Sturm sequences for the polynomial and test whether the
polynomial has no real-valued roots, in which case the edge does not
intersect the curve. These tests involve only basic arithmetic operations.

When all you have is a hammer, everything looks like a nail. My
particular hammer is interval arithemetic, so everything looks like
interval arithmetic to me. I'd note that the Bezier curve should
definitely be selected if any vertex lies within the rectangle, which is
trivial to check. If it isn't, then check to see whether the bounding
box of the control points overlaps with your target rectangle. If it
does not, then it doesn't overlap. If it does, then it might, so do
a Bezier subdivide and try again with the two subcurves, with some
termination criteria (the above solutions also have a termination
criteria for linearization, you can adopt the same here). Note that you
only need to fine ONE subcurve which overlaps, there is no reason to continue
searching once you find one.

Because no actual data structures are computed here, I doubt it will perform
as well as David's proposed method, but on the other hand, no actual data
structures are involved, so I suspect the code will be rather smaller and
easier to debug. YMMV.

Mark

--
Dave Eberly
http://www.geometrictools.com


.



Relevant Pages

  • Re: fast intersection calculation between bezier & rectangle
    ... drag their mouses in the canvas to select from a lot of bezier curves. ... those axis-aligned boxes that the rectangle edges intersect. ... "Intersection of bezier and straight line". ...
    (comp.graphics.algorithms)
  • Re: fast intersection calculation between bezier & rectangle
    ... drag their mouses in the canvas to select from a lot of bezier curves. ... those axis-aligned boxes that the rectangle edges intersect. ... "Intersection of bezier and straight line". ...
    (comp.graphics.algorithms)
  • Re: [help] fast intersection calculation between bezier & rectangle
    ... drag their mouses in the canvas to select from a lot of bezier curves. ... those axis-aligned boxes that the rectangle edges intersect. ... "Intersection of bezier and straight line". ...
    (comp.graphics.algorithms)
  • Re: Curve implicitization from parametrization
    ... it's hard for me to judge the likelihood that Tony knows, ... In general, for K either C or R, there exist polynomials F_1,.., ... it is not always the case that G is such an intersection *as ... space curves G is incomplete and may remain so forever). ...
    (sci.math)
  • Re: Damn you, FEDEX! or Nikon D40 lost in Springfield, MO blackhole.
    ... the 2 mp Mavica he had been using with a Nikon D40. ... After shopping around, he got me to order one for him. ... The shipper had it insured, but from what I have read it could take weeks to sort this crap out. ... You may get your insurance from FedEx and a couple weeks later they find it and deliver it. ...
    (alt.photography)