Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public double distance(Segment other) {
- Point p = line.intersection(other.line);
- if (p == null) {
- if (!other.isInside(other.line.project(line.getPointA())) && !other.isInside(other.line.project(line.getPointB()))
- && !isInside(line.project(other.line.getPointA())) && !isInside(line.project(other.line.getPointB()))) {
- return Math.min(
- Math.min(line.getPointA().distance(other.line.getPointA()),
- line.getPointA().distance(other.line.getPointB())),
- Math.min(line.getPointB().distance(other.line.getPointB()),
- line.getPointB().distance(other.line.getPointA())));
- }
- return line.distance(other.line);
- }
- if (isInside(p)) {
- return other.distance(p);
- }
- if (other.isInside(p)) {
- return distance(p);
- }
- return Math.min(
- Math.min(line.getPointA().distance(other.line.getPointA()),
- line.getPointA().distance(other.line.getPointB())),
- Math.min(line.getPointB().distance(other.line.getPointB()),
- line.getPointB().distance(other.line.getPointA())));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement