# Rounding corners of polygon given vertices of its corners

Given a polygon (regular or irregular, convex or concave), I want to round its corner, with a given radius; let's say 'x'. I have the code to draw an arc given 2 points, but how can I find the start and end points of the arc?

All I have is a list of points representing each corner of the polygon.

Here's a simple example: I have a list of vertices of corners of the figure (1). The figure (2) is what I need so I could draw the arcs to round the corners.

PS: I'm developing a CAD drawing generator using .netdxf API (https://github.com/haplokuon/netDxf)

Since you're working on CAD software, you probably want some precise results. Here an algorithm that could work:

For each side:

• Compute the segment's equation.
• Compute each round corner's circle equation.
• Compute the intersections between the segment and each circle.
• The 2 intersection points are the new endpoints for the line segment.

This doesn't handle the case where a side is smaller than the rounded corner radius. You could reduce the rounded corner's radius in this case based on the segment's length.

Ok, Xenapior and Reynolds together have the right idea. But the explanation is a bit lacking so here is a image to explain it all and some further musings. First let us start by drawing an image (yes i know that is what they say in school for you to do but nobody does it).

From the image we can see that there are 2 equal right triangles $V_2, A, C$ and $V_1, B, C$. In this triangle we have one unknown that we can define namely rounding radius $r$, also we know right angle is 90°. The angle between the line $V_1-V_2 = \vec a$ and line $V_2-V_3 = \vec b$ is easy to compute with the formulation fo angle between vectors

$$\cos(\beta) = \frac{\vec a·\vec b}{ |\vec a|·|\vec b|}$$

That in turn can be simplified if the vectors already are normal. Thus three things of the triangle is known, which means all is known. So if you know the rounding radius to use the calculating the points $A$, $B$ and $C$. So finally:

a = normalize(V2-V1);
b = normalize(V2-V3);
halfang = acos(dot(a, b))/2.;
// skip center if you iuse splines
C = V2 - r / sin(halfang) * normalize((a+b)/2);
A = V2 - r/tan(halfang)*a;
B = V2 - r/tan(halfang)*b;


You can simplify this a bit with trigonometric identities. Or if you use rational B-splines you can skip the calculation of C

Note: that this is only one possible formulation

The cut length from the vertex is x*ctan(t/2), where t is the angle at this vertex.