It would be nice to get the distance to another point squared, to avoid using sqrt().
You could divide this method ...
Code:
/**
* Get the distance from this point to another
*
* @param other The other point we're measuring to
* @return The distance to the other point
*/
public float distance(Vector2f other) {
float dx = other.getX() - getX();
float dy = other.getY() - getY();
return (float) Math.sqrt((dx*dx)+(dy*dy));
}
.. into these:
Code:
/**
* Get the distance squared from this point to another
*
* @param other The other point we're measuring to
* @return The distance squared to the other point
*/
public float distanceSquared(Vector2f other) {
float dx = other.getX() - getX();
float dy = other.getY() - getY();
return (float) (dx*dx)+(dy*dy);
}
/**
* Get the distance from this point to another
*
* @param other The other point we're measuring to
* @return The distance to the other point
*/
public float distance(Vector2f other) {
return (float) Math.sqrt(distanceSquared(other));
}
Thanks a lot!
Greets Lufti