The
java.awt.geom package contains an
Arc2D class with a helpful
contains() method.
Here is a sketch I made some time ago, using this method (press a key to rotate the shape) :
Quote:
PArc2D range;
void setup() {
size(320, 240);
smooth();
range = new PArc2D(width/2, height/2, 100, 0, PI/4);
}
void draw() {
background(255);
noStroke(); fill(200, 200, 200);
if (range.contains(mouseX, mouseY)) fill(255, 200, 50);
range.display();
}
void keyPressed() {
range.turn(-PI/12);
}
class PArc2D {
java.awt.geom.Arc2D arc2D;
PArc2D(float x, float y, float w, float a, float e) {
// x, y : center
// w : width
// a : direction (point at)
// e : extent angle
arc2D = new java.awt.geom.Arc2D.Float(x-w/2, y-w/2, w, w, degrees(-a-e), degrees(e*2), java.awt.geom.Arc2D.PIE);
}
void setXY(float x, float y) {
arc2D.setArcByCenter((double)x, (double)y, arc2D.getWidth()/2, arc2D.getAngleStart(), arc2D.getAngleExtent(), java.awt.geom.Arc2D.PIE);
}
void turn(float ra) {
arc2D.setAngleStart(arc2D.getAngleStart() - degrees(ra));
}
void display() {
float x = (float)arc2D.getX();
float y = (float)arc2D.getY();
float w = (float)arc2D.getWidth();
float as = -radians((float)arc2D.getAngleStart());
float ae = radians((float)arc2D.getAngleExtent());
arc(x + w/2, y + w/2, w, w, as - ae, as);
}
boolean contains(float x, float y) {
return arc2D.contains(x, y);
}
}