-3

I need an algorithm that can round a corner between a line and an arc. The start information that I have is P0-start point, P-corner point, P2-end point, R2-radius of the arc between P and P2 and R-radius of the rounded corner(on the second picture).

Corner between line and arc

Output or wanted points are cross sections C0 and C2 and center point of the rounding circle-O

Rounded corner between line and arc

UsrDS
  • 23
  • 4
  • 1
    Possible duplicate of [efficient algorithm for drawing circle arcs?](https://stackoverflow.com/questions/3044444/efficient-algorithm-for-drawing-circle-arcs) – Dour High Arch Mar 22 '18 at 19:29
  • What are you targetting: Winforms, WPF, ASP..? __Always__ TAG your question correctly! – TaW Mar 22 '18 at 19:58

2 Answers2

3

In my sketch BF is part of given segment (F is not known yet), C is center of given arc, B is point of rough conjugation. c is line, parallel to BF, |GF|=|GH| = r - radius of small arc.

To make smooth conjugation, tangent to small arc in point F should be collinear with BF direction, so GF is perpendicular to BF, and tangents to both arcs in point H should coincide - so radius-vectors CH and GH lie on the same line. enter image description here

Let unit direction vector of BF segment is ud=(dx,dy), so unit normal is un=(-dy, dx). (Negate normal for arcs at another side of BF)

Center of small arc G has coordinates (where t is unknown parameter - length of BF)

G = B + ud * t + un * r

and distance GC is difference of arcs radii, so

 |G - C| = |R - r| 
   or in coordinates:
(B.x + dx * t - dy * r - C.x)^2 + (B.y + dy * t + dx * r - C.y)^2 = (R - r)^2

Open parentheses, solve quadratic equation for unknown t. If solutions exist, choose right root, and you'll get coordinates of center of conjugation arc G and its ends

quick check1: Line Y=5, big arc with R=5, we want small arc with r=2

 B=(5,5)
 ud=(-1,0)
 un=(0,-1)
 (5-t)^2 + (5-2-5)^2 = (5-2)^2
 solution gives 
 t = 5 +/- Sqrt(5), the second root is valid
 E = (5 - (5 - Sqrt(5)), 3) = (2.23, 3)

Resulting smooth arc is c-f

enter image description here

quick check2: Line Y=5, big arc with R=5, we want small arc with r=2

 B=(5,5)
 big arc center (H here) = (1,2)  
 ud=(-1,0)
 un=(0,-1)
 (4-t)^2 + (5-2-2)^2 = (5-2)^2
 solution gives 
 t = 4 +/- Sqrt(8), the second root is valid
 E = (5 - (4 - Sqrt(8)), 3) = (3.83, 3)

Resulting smooth arc is F-G

(In both cases larger root corresponds to conjugation with complementary part of big arc)

enter image description here

MBo
  • 77,366
  • 5
  • 53
  • 86
  • Thank you very much, this works fine but I have a few questions. How do you determine which root is valid? And how to solve for the small circle center if the roots are complex numbers? – UsrDS Mar 26 '18 at 16:07
  • I think that for "good" configurations valid root is smaller positive one (but I did not consider all possible configurations). If roots are complex - then there is no solution with chosen approach for C1-continuity and given small radius) – MBo Mar 26 '18 at 16:34
  • Maybe I calculated the directional unit vector wrongly so that's why I get complex roots. These are the equations I used to calculate dx = (A.X - B.X) / Math.Abs(A.X - B.X) and dy = (A.Y - B.Y) / Math.Abs(A.Y - B.Y) – UsrDS Mar 26 '18 at 17:01
  • Yes, mistake. `Len = Sqrt((A.X - B.X)^2 + (A.Y - B.Y)^2); dx = (A.X - B.X) / Len, dy = (A.Y - B.Y) /Len` (for Len use routine Math.Hypot if available. or vectors supporting routines (Normalize etc)) – MBo Mar 26 '18 at 17:09
  • Can this solution be implemented for rounding a corner between two arcs instead of line and arc – UsrDS Apr 02 '18 at 16:08
  • Equations will differ. Perhaps: find point Cr for |Cr - C1| = |R1 - r|, |Cr - C2| = |R2 - r| (like finding the third triangle vertex for two known verices and known edges) – MBo Apr 02 '18 at 16:40
  • Unit vectors ud and un stay the same ? – UsrDS Apr 02 '18 at 17:25
  • There no such vectors in case of two arcs. System of two quadratic equations for small arc center coordinates. – MBo Apr 03 '18 at 03:48
0

There isn't enough specification to choose a unique arc. You need to figure out what endpoints you want. Then solve for the ellipse that is tangent to both of those points. See Wikipedia/ellipse for the equations. I recommend a math package (e.g. SciKit) to solve for you.

Prune
  • 76,765
  • 14
  • 60
  • 81