2D Point in polygon test - Is this good?
Hey i just wanted to get some simple collison detection between a 2D spaceship polygon, and a weapon fire point. Usual stuff so i searched the forums, but not really what i need.
The question is whether this code is any good, or mabye if there is a way to improve it.
Now idon''t have a profiler, so i have to judge code by looks.
Alright this is the code, it just seems to simple to work!
Id appreciate any comments, hopefully constructive!
Thanks alot.
public boolean pointInPoly(Polygon poly,int x,int y){
Rectangle2D rect = poly.getBounds2D();
if(!rect.contains(x,y)){
return false;
}
double center_x = rect.getX() + rect.getWidth() /2;
double center_y = rect.getY() + rect.getHeight() /2;
for(int i=0; i;
int py = poly.ypoints;
int xd = px - x;
int yd = py - y;
if(+xd < center_x ||
+yd < center_y ){
return true;
}
} </i>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement