Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. public double distance(Segment other) {
  2. Point p = line.intersection(other.line);
  3. if (p == null) {
  4. if (!other.isInside(other.line.project(line.getPointA())) && !other.isInside(other.line.project(line.getPointB()))
  5. && !isInside(line.project(other.line.getPointA())) && !isInside(line.project(other.line.getPointB()))) {
  6. return Math.min(
  7. Math.min(line.getPointA().distance(other.line.getPointA()),
  8. line.getPointA().distance(other.line.getPointB())),
  9. Math.min(line.getPointB().distance(other.line.getPointB()),
  10. line.getPointB().distance(other.line.getPointA())));
  11. }
  12. return line.distance(other.line);
  13. }
  14. if (isInside(p)) {
  15. return other.distance(p);
  16. }
  17. if (other.isInside(p)) {
  18. return distance(p);
  19. }
  20. return Math.min(
  21. Math.min(line.getPointA().distance(other.line.getPointA()),
  22. line.getPointA().distance(other.line.getPointB())),
  23. Math.min(line.getPointB().distance(other.line.getPointB()),
  24. line.getPointB().distance(other.line.getPointA())));
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement