Formula to Calculate Overlap of Two Arcs on a CircleDate: 05/27/2005 at 15:55:22 From: Adnan Subject: Intersecting arcs on a circle Hi there, I have a circle and I draw an arc from 0 to 45 degrees with a blue pen, and another from 40 to 60 degrees with a red pen. Now I know that the arcs are intersecting from 40 to 45, but I want to construct a formula with the 4 angle entries and one Boolean output for the intersection answer. One problem is that if one arc is from 340 to 30 (50 deg) and the other from 350 to 355, the 360 to 0 turn has to be calculated separately. It is simple to calculate it with many "if" statements, but I need a one line formula. Date: 05/29/2005 at 22:48:51 From: Doctor Peterson Subject: Re: Intersecting arcs on a circle Hi, Adnan. You want a simple formula (presumably in some computer language or a spreadsheet) that will be true if two arcs, for which the starting and ending angles are given, overlap. The calculation is made easier if we first standardize the angles. Suppose we are given one arc counterclockwise from a to b degrees, and another counterclockwise from c to d. We can first move our point of reference so that we measure 0 degrees at a; then the two arcs are 0 to b-a c-a to d-a Now we can make sure that these angles are between 0 and 360 degrees. One way to do this is to use a "mod" function, which gives the remainder between 0 and 360 after division by 360; we replace each variable as follows: d = mod(d-a, 360) c = mod(c-a, 360) b = mod(b-a, 360) a = 0 If the given angles can be negative, you have to be careful with this, as what is often called the "mod" function (e.g. "%" in C) doesn't do what we need for negative inputs. See this page if you need help with that: What is Mod? http://mathforum.org/library/drmath/sets/select/dm_mod.html Now, we have something like this: a===============b +-----------+---+-------+----+ 0 c===========d 360 The only way the two arcs can NOT overlap is if a<b<c<d: a===========b +-----------+---+-------+----+ 0 c=======d 360 If they do overlap, then either a<c<b<d as in the first picture, or d<c and the second arc wraps around: a===============b +-----------+---+-------+----+ 0===========d c====360 This gives two ways to state the condition: not((b<c) and (c<d)) or (b<c) or (d<c) If you need to get it all in one expression without modifying the variables first, you would use (mod(b-a, 360) < mod(c-a, 360)) or (mod(d-a, 360) < mod(c-a, 360)) If you have any further questions, feel free to write back. - Doctor Peterson, The Math Forum http://mathforum.org/dr.math/ Date: 05/30/2005 at 02:48:48 From: Adnan Subject: Thank you (Intersecting arcs on a circle) Many thanks, Dr. Peterson. It is now clear. The main confusing thing was that I had to move the point of reference to 0 degrees. I love math, it has such simple techniques to solve complicated problems, and thank goodness we have doctors like you to show us the path. Kind regards, Adnan |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994-2015 The Math Forum
http://mathforum.org/dr.math/