add Point utilities

This commit is contained in:
Hannes Janetzek 2014-02-24 16:31:53 +01:00
parent 9c138beb5d
commit 60438b2925

View File

@ -48,4 +48,25 @@ public class Point {
public String toString() {
return x + " " + y;
}
public void setPerpendicular(Point other) {
x = -other.y;
y = other.x;
}
public void setPerpendicular(Point p1, Point p2) {
x = p1.x + p2.x;
y = p1.y + p2.y;
double a = p2.x * y - p2.y * x;
if (a < 0.01 && a > -0.01) {
/* Almost straight */
x = -p2.y;
y = p2.x;
} else {
x /= a;
y /= a;
}
}
}