How to add two arcs together if they overlap

243 Views Asked by At

I'm writing some code for various calculations with arcs and lines and need help with some math. I have list of arcs and need to add them together if they "overlap", here is the available variables:
Radius; Center X Y Z; StartAngle; EndAngle;
I can check if the arcs have the same starting point and if their radius is the same, meaning we know that they are a part of the same circle. By adding them together I mean I should get a new arc with new starting and ending angles that cover given two arcs.
This could be solved by checking and comparing a lot of conditions but I'm looking for a more mathematical approach. Few examples Arc{startAngle;endAngle}:
A1{350;340} B1{90;270} -> C1{350;340}
A2{225;20} B2{90;270} -> C2{90;20}
A3{225;300} B3{90;270} -> C3{90;300}
A4{340;45} B4{90;270} -> not overlapping

Edit
Here is a simple illustration to help in understanding my problem as I'm not the best in using math words. Illustration

1

There are 1 best solutions below

3
On BEST ANSWER

You should consider this problem as a problem with subsets of $[0,2\pi)$ (or equivalently, of $[0,360)$ using degrees). Let arc $A=[a,b)$ and $B=[c,d)$ such that $a<c<b<d$. Then $A=[a,c)\cup[c,b)$ and $B=[c,b)\cup[b,d)$ and if we 'add' (take the union) them we get $A\cup B=[a,c)\cup[c,b)\cup [c,b)\cup[b,d)=[a,d)$ which is what we wanted.