I\'m looking for an algorithm that allows me to create rounded corners from a polygon. In Input, I get an array of points that represents the polygon (red line) and in outpu
Here is a way using some geometry :-
- the two lines are tangent to circle inscribed
- The normal to the tangent meet at centre of the circle.
- Let angle between lines be X
- Angle subtended at centre of the circle will be K = 360-90*2-X = 180-X
- Lets decide the two point of tangents as (x1,y) and (x2,y)
- The chord joining the points has length l = (x2-x1)
- Inside the circle, the chord and two normals of length r (radius) form isosceles triangle
- The pendicular divide the traingle in to equal halved right angled triangles.
- One of angle is K/2 and side is l/2
- using properties of right angle triangle sin(K/2) = (l/2)/r
- r = (l/2)/sin(K/2)
- but K = 180-X so r = (l/2)/sin(90-X/2) = (l/2)/cos(X/2)
- hence r = (x2-x1)/(2*cos(X/2))
- Now simply draw a arc from (x1,y) to (x2,y) using radius r
Note:-
The above is explained for only for lines which meet at origin and the Y axis divides the angle between them into half. But it is equally applicable for all corner just need to apply a rotation and translation before applying the above. Moreover you need to select some x values of intersection from where you want to draw the arc . The values should not be too far or close to origin