How to detect when mouse is within arc?Help!

edited November 2016 in Questions about Code


I have been trying to figure out how to detect if my mouse (mouseX and mouseY) are within an arc. Its easy to do for something like a rectangle, where you can just specify the outside boundaries for the width and height in an "if" statement. But how can we do that for an irregular object with a curve in it, such as for an arc? I was thinking of something like a for loop where, since you have a slope of 1, the x and y should correspond in some way. But just comparing along the hypotenuse is too small of a detection range, and a for loop is resource intensive to do continually. I would need it to detect the mouse if it is anywhere within the arc, not just the outer border. I'm a newcomer to programming, so I would appreciate to keep things on the simpler side. Thank you!

Any ideas?

void setup()
  arc(0,0, 80, 80, 0, TWO_PI);

void loop ()

  //if(mouseX and mouseY are in the arc, then print something

Better yet, how can we detect if the mouse, or anything else for that matter, goes through that narrow opening for the arc, and goes into the arc, as displayed in the picture?

Image 1


Sign In or Register to comment.