3
$\begingroup$

Given shapes like these, which contain just Arcs and lines, I want to round all its corners with certain radius. I know the vertices of the lines & arcs these shapes.

enter image description here

I can round the corners of a polygon (when two lines meet to form a corner), but can't figure out how to round a corner formed by an Arc and a Line.

I used this post to round the corners of polygon:

Algorithm for creating rounded corners in a polygon | Stack Overflow

Could you please share a code snippet, or just explain/list the math/algorithm behind achieving this? Thanks!

PS: I'm developing a CAD drawing generator using C# & .netDxf library

$\endgroup$

1 Answer 1

2
$\begingroup$

I suppose you want an arc of C0 and C1 continuity between the line and an arc. Rounding corner illustration

As illustrated above, you already have a vertex A which is the intersection of an edge and an arc of which the center positioned at O and radius equal to R. The question is thus pure mathematical: given A,O,R, edge direction BA, and a corner radius r, find C,B, and T. For simplicity, here let's assume that the black dotted line has the form of $C_y=kC_x+b$, where k is the same as edge BA while b is easily derived by combining k and rounding radius r. Therefore, three constraint equations can be listed to solve $C_x$:

  1. The distance TC is r: $(T_x-C_x)^2+(T_y-C_y)^2=r^2$
  2. The big arc equation: $(T_x-O_x)^2+(T_y-O_y)^2=R^2$
  3. Point C is on OT: $\frac{T_y-C_y}{T_x-C_x}=\frac{T_y-O_y}{T_x-O_x}$

Solve for Cx and you'll obtain four solutions (I used Mathematica):

$C_x=\frac{-bk+O_x+kO_y\pm\sqrt{-(O_y-kO_x-b)^2+(1+k^2)(R-r)^2}}{1+k^2}$ $C_x=\frac{-bk+O_x+kO_y\pm\sqrt{-(O_y-kO_x-b)^2+(1+k^2)(R+r)^2}}{1+k^2}$

The second expression is out of the arc, so you should use the first solutions. Given the two Cx values, they can be used to derive Cy values to make a candidate list for point C. Pick the correct C using manual check.

Now you have the center C of the round corner arc as well as its radius r. It should be relatively easy to determine point B and point T, and draw an arc through the two points.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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