Search code examples
math2d

How to find arc that connects two segments?


I will start with img that help me discribe my problem:

I have two connected segments AB & BC (and i know coords). How can I calculate arc between first and last green point. First & last green point is located with specified distance from B point (black segment). I want to have all coords of green points in array. Anyone can help me with this problem?


Solution

  • The problem boils down to finding the center of the circle K given a radius r, the point B and the directions BC and BA.

    pic

    Follow these steps:

    1. Find angle φ between BC and AB using any "angle between two planar vectors" algorithm you find (there are many ways).

    2. Calculate the arc inclusive angle ψ with

      ψ = 2*arcsin(cot(φ/2))

    3. Calculate the distance s along BC where the arc ends

      s = r*cot(φ/2)

    4. If the direction of BC is e_BC=(ex,ey) and the normal is n_BC=(ey,-ex) then the end of the arc M is

      (mx,my) = (bx,by) + s*(ex,ey)

    5. And the circle center is

      (kx,ky) = (mx,my) + r*(-ey,ex)

    6. Now take N=4 angle increments to rotate point M about K to get your green points

      i-th point: i=1..4

      gx = kx + (mx-kx)*cos((i/4)*ψ)+(my-ky)*sin((i/4)*ψ)

      gy = ky - (mx-kx)*sin((i/4)*ψ)+(my-ky)*cos((i/4)*ψ)


    Based on other answers on this site on the TTR algorithm (tan-tan-radius), the best way to approach this problem is to offset the lines by the radius r and find the intersection which becomes the center of the arc.

    fig2

    Notice that there are four possible intersection points depending on which side of the line the offset is done. All are valid, and the user much choose/decide which one is wanted.