3

I am aiming to create the following (a directed arrow that connects two nodes) : Aim

At the moment I have this (a quadratic bezier curve drawn from the center point of one node to the center of another):

Current

(Note I have drawn the bezier above the nodes to show where it begins and ends)


I need a method - heuristic or otherwise - to calculate the point of intersection (circled in red, above) between the bezier curve and the node's (ellipse) circumference.

With this, I could calculate the angle between the node center and the point of intersection to draw the arrow head lines at the correct location and angle.


As a last resort, I could use the quadratic Bézier formula to generate a list of points that lie along the curve and also generate a list of points that lie on the circumference of the circle and use one of the two coordinates that have the least euclidian distance between each other as my intersection point. I'm hoping any answers can leverage geometry or whatever else to better solve it.

5
  • 1
    Does this help any? stackoverflow.com/q/1073336/2754173
    – Geezer
    Aug 12, 2018 at 19:03
  • 1
    @SkepticalEmpiricist That seems concerned with straight line intersection (rather than bezier curves) and is a more generic representation of the problem (it may find two, or zero, points of intersection). Since I know the bezier curve and the circle will always intersect once in the problem I raise, perhaps the solution for my question could be more simple.
    – micycle
    Aug 12, 2018 at 19:10
  • 1
    Found this for the applied math: math.stackexchange.com/q/436216/93685
    – Geezer
    Aug 12, 2018 at 19:16
  • 1
    And here a JavaScript library with the functionality you're looking for (among other, as it supports all kind of shapes), from which to you can check the relevant code and usage examples: github.com/thelonious/kld-intersections/blob/development/…
    – Geezer
    Aug 12, 2018 at 19:19
  • 1
    Note that you wouldn't have to use the formula yourself, as Processing provides a bezierPoint() function. More info in the reference. Aug 13, 2018 at 16:35

1 Answer 1

7

The general problem is uneasy as the intersection equation is quartic ((X(t)-Xc)² + (Y(t)-Yc)²=R²), where X and Y are quadratic polynomials). If you have a quartic solver handy you can use it but you'll have to select the right root.

A more reasonable approach is just to intersect the circle with the line segment between the control points. This is approximate but probably unnoticeable if the circle radius is small. enter image description here

If you want more accuracy, perform one or two Newton's iterations from this point.

1
  • thank you! been looking for a numerically stable way to do this
    – Java Noob
    Dec 30, 2022 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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