We are about to switch to a new forum software. Until then we have removed the registration on this forum.

- All Categories 25.7K
- Announcements & Guidelines 13
- Common Questions 30
- Using Processing 22.1K
- Programming Questions 12.2K
- Questions about Code 6.4K
- How To... 4.2K
- Hello Processing 72
- GLSL / Shaders 292
- Library Questions 4K
- Hardware, Integration & Other Languages 2.7K
- Kinect 668
- Arduino 1K
- Raspberry PI 188
- Questions about Modes 2K
- Android Mode 1.3K
- JavaScript Mode 413
- Python Mode 205
- Questions about Tools 100
- Espanol 5
- Developing Processing 548
- Create & Announce Libraries 211
- Create & Announce Modes 19
- Create & Announce Tools 29
- Summer of Code 2018 93
- Rails Girls Summer of Code 2017 3
- Summer of Code 2017 49
- Summer of Code 2016 4
- Summer of Code 2015 40
- Summer of Code 2014 22
- p5.js 1.6K
- p5.js Programming Questions 947
- p5.js Library Questions 315
- p5.js Development Questions 31
- General 1.4K
- Events & Opportunities 289
- General Discussion 365

Subject says it all. I'm drawing a number of arc's like this:

```
arc(x1, y1, w1, h1, start1, stop1, PIE);
arc(x2, y2, w2, h2, start2, stop2, PIE);
```

... and I'd like to find out before I draw them if the arcs intersect/overlap/share pixels (using these terms synonymously). It's not enough to check the two ellipses because the ellipses can overlap long before the arcs overlap.

Would prefer some nice elegant math, but I do have one duct-tape idea:

Draw both arcs to some kind of off screen buffer using semi-transparent fill colors, then scan the buffer for pixels colored to reflect an overlap. Big buffer, so probably check the ellipses first, then just check pixels within the ellipses somehow.

Very grateful for any suggestions!

## Answers

do circle-circle collision first (distance between centres). if true then work out the (two) intersections. then check to see if these two intersections are on the drawn arcs.

http://mathworld.wolfram.com/Circle-CircleIntersection.html

and you'll probably need atan2() for the last bit

(um, might only work if w=h)

You can get Processing code to find the intersection points

heresee page 3Super grateful for the suggestions! Thank you!

Struggling with two issues though.

The bigger issue: the intersection points only seem useful in some instances. For example, in the image below on the left neither point is on an arc, but the arcs overlap. And on the right, both points are on an arc, but the arcs don't overlap.

(can't get the image to display inline in the forum, I uploaded it here http://postimg.org/image/vfaqya7y9)

A smaller issue is with positive and negative radians. I'm taking the intersection points from the code at Quark's place and using atan2() to find their radians on (or not on) an arc. This is working 90% of the time. But a few situations stumble. For example, I have a 9:00-12:00 arc (drawn from 3.1 to 4.7 or PI to 1.25*PI). I have an intersection point right on the arc at about 11:30, but atan2() gives me radians of -1.6, and in code -1.6 does not fall between 3.1 and 4.7.

It's better than it used to be. I used to draw my arcs (pie chart slices) starting vertically at 4.71 and moving clockwise, always positive. So I

usedto draw this same 9:00-12:00 arc as 9.4 - 11.0 (radians). It drew fine, but using atan2() was only working in the first quadrant.More concerned with the first issue. Sorry for the long post.

atan2 return a value -PI to +Pi this needs to be converted to 0 to 2Pi. The following code will do that.

`angle = (angle < 0) : angle + TWO_PI : angle;`

The other problem is shown in your first picture where the arc straddles the 0 degree position. This sketch has a function that determines whether an angle falls within an arc range defined in the clockwise direction.

You will need to check both arcs to ensure that the arcs intersect.

no they don't. when you say arc do you mean sector?

http://www.nextlevelmaths.com/resources/other_resources/parts_of_a_circle/

My bad Koogs! I've read close to 20 articles, references, and help posts related to drawing 'arc's with programming languages, and this is the first distinction I've seen between the one part of the stroke, and the rest of what gets drawn (albeit a math reference). Even 'arc's with noStroke() get called 'arc's.

So yes, trying to figure out if two sectors overlap, like when their 2 transparent fill colors would create a third shade.

Again, sorry for the disconnect.

Awesome fixes Quark, thanks a million! I really struggle with trig and geometry issues. And maybe authority, too.