I'm writing some code to create an arc between vectors, but i cannot work out how to find the minimum radius for my arc to achieve it.

This is where i am at so far:

enter image description here

The way i am doing this, is finding two perpendicular vectors (in red) relative to my two green vectors.

The intersection of these 2 perpendicular red vectors gives me the origin of the circle.

Then i can easily create an arc from one vector to the next but i am unable to work out the correct radius.

Does any one have any suggestions on how to find the minimum radius to create an arc that curves perfectly between my two green vectors?

  • 1
    $\begingroup$ For most configurations, there won’t be a circular arc that connects the two points and has the required tangents. You need to go to an elliptical arc or something like an Euler spiral. $\endgroup$
    – amd
    Jan 25 '20 at 3:48
  • $\begingroup$ Do you know where i can read more about the math involved to calculate it ? $\endgroup$
    – WDUK
    Jan 25 '20 at 4:04
  • $\begingroup$ If the $4$ points are not coplanar, there will be no arc which can connect the two vectors. $\endgroup$
    – Sam
    Jan 25 '20 at 4:40
  • $\begingroup$ They are guaranteed to always be co-planar in my case. $\endgroup$
    – WDUK
    Jan 25 '20 at 5:18
  • $\begingroup$ @WDUK Your assertion The intersection of these 2 perpendicular red vectors gives me the origin of the circle is valid if and only if the lengths of the two perpendiculars are equal. $\endgroup$
    – YNK
    Jan 26 '20 at 7:28

Unfortunately, for most configurations there is no circular arc that joins the two points and has the required tangents. For that to be possible, the two perpendicular line segments must have the same length.

The simplest way to smoothly join the two line segments is, I think, to use a quadratic Bézier curve, that is, a parabolic arc. You already have two of the control points, and the third is simply the intersection of the extensions of the two given line segments (what you call “vectors”). This will only work if the two directed line segments point “toward” each other, of course. There are well-known standard algorithms for plotting quadratic Bézier curves that you should be able to find with a simple Internet search. One down side of using a quadratic Bézier is that it doesn’t reduce to a circular arc for the cases in which you could use one.

There are many other possibilities for joining the two line segments with a unique curve, such as higher-order Bézier curves, but unlike the quadratic Bézier, you don’t get a unique solution. With other choices, you’ll need to add some arbitrary constraints in order to get a visually satisfying result. For instance, an interesting possibility is to use an Euler spiral. This is the curve used to join segments of road that go in different directions. The computations involved are more complicated, but you can find a starting point in the Wikipedia article that I refer to. To use an Euler spiral for this application will require a couple of arbitrary parameters that roughly correspond to the speeds at which a vehicle would be entering and leaving the arc.

  • $\begingroup$ You mention the line segments must have the same length. But what if i regard it as 2 vector points each with an associated vector tangent which is just a direction of magnitude 1 ? Would that still not let it work ? $\endgroup$
    – WDUK
    Jan 28 '20 at 21:53
  • $\begingroup$ @WDUK No. I’m talking about the lengths of the two perpendiculars that you constructed in your attempted solution. To put it another way, the two points must lie at the ends of radii of the circle, so they must be equidistant from its center. $\endgroup$
    – amd
    Jan 28 '20 at 21:57
  • $\begingroup$ Oh sorry i see, so i'd have to move one of the positions to guarantee equal distance. I originally did bezier, but when the corner was really sharp the bezier anchor point (which i found via intersecting the two lines) was so far away the curve went too crazy. $\endgroup$
    – WDUK
    Jan 28 '20 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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