Search code examples
javac#mathgeometrypseudocode

Draw an Arc from a start point, end point and a radius


I'm looking to get a point list of n points on an arc; I will know the start point, end point and radius.

The user would be building an arc with 3 mouse clicks, the first two to define the start and the end and the third to would set the size of the radius.

Thanks.

Edit: I don't just need to render it - I also need the point list, so using a rendering API to do this won't cut it.


Solution

  • Let h be the half distance between the start and end points. By Pythagoras, the distance from the midpoint and the center of the circle is w=√r²-h². You will find that center by drawing a line segment of length w perpendicularly from the midpoint.

    The starting angle of the arc is given by tan(φ)=δy/δx, between the starting point and the center, and similary for the ending point.

    Then your n points have the coordinates

    Xc + r cos(φs + k (φe-φs)/(n-1))
    Yc + r sin(φs + k (φe-φs)/(n-1))
    

    for k= 0,1,...n-1.

    enter image description here