import java.util.Vector;
Polygon p = new Polygon();
void setup() {
size(300,300);
smooth();
p.addPoint(50,50);
p.addPoint(100,50);
p.addPoint(100,100);
p.addPoint(50,100);
}
void draw() {
background(0);
noStroke();
fill(255);
beginShape();
for (int i=0; i
x1 && px <= x2 && ( py < getY(i) || py <= getY(i+1) ) ) {
final float eps = 0.000001;
/* Calculate the equation of the line */
float dx = getX(i+1) - getX(i);
float dy = getY(i+1) - getY(i);
float k;
if ( abs(dx) < eps ){
k = Float.MAX_VALUE;
}
else {
k = dy/dx;
}
float m = getY(i) - k * getX(i);
/* Find if the ray crosses the line */
float y2 = k * px + m;
if ( py <= y2 ){
crossings++;
}
}
}
return (crossings>0) ? true : false;
}
}