Detecting mouse hover over the circle


I need to detect is my mouse pointer above the circle that I drew.
But for now I need an insane precision to do that.
Is there any way to get my circle area and detect the collide event, or something?



Hi, an easy way to detect collision with circles is to use distance function!


So, in draw or update, you can get the mouse coordinates (OF stores that in variables called mouseX and mouseY for you) and then for every single circle that you have you loop through it and (lets say you have an array of structures that have the x,y ,color and radius stored in them called circles)

if (ofDist(mouseX,mouseY, circles]i].x,circles[i].y) <= circles[i].radius) {
    circles[i].color = ofColor::red;
  circles[i].color = ofColor::blue; // or else it will stay red after your mouse leaves

Let me know if I misunderstood your question, I’m not sure what kind of precision you are in need of. More information about how it needs to be precise would help :slight_smile:


Here is my code:


I would solve that using ofPolyline or ofPath, drawing a circle there and checking with a function “inside”!show_inside

with polyline you have to build your circle (polar coordinates), and with ofPath you can use “arc” function to make the circle.


I’ve done something like that:
And for now it’s working fine.