fork download
  1. def (a, b, c) = [[x: 17, y: 13], [x: 21, y: 27], [x: 38, y: 7]]
  2.  
  3. boolean isOrthogonalVectors(int mx, int my, int nx, int ny) {
  4. return (mx*nx + my*ny == 0);
  5. }
  6.  
  7. boolean isRightTriangle(a, b, c) {
  8. boolean result = false;
  9.  
  10. int abx = a.x - b.x;
  11. int aby = a.y - b.y;
  12. int acx = a.x - c.x;
  13. int acy = a.y - c.y;
  14.  
  15. if (isOrthogonalVectors(abx, aby, acx, acy)) {
  16. result = true;
  17. }
  18. else {
  19. int bcx = c.x - a.x;
  20. int bcy = c.y - a.y;
  21.  
  22. result = isOrthogonalVectors(abx, aby, bcx, bcy) || isOrthogonalVectors(acx, acy, bcx, bcy);
  23. }
  24.  
  25. return result;
  26. }
  27.  
  28. println "$a, $b, $c"
  29. println isRightTriangle(a, b, c)
  30.  
  31. (b, c) = [c, b]
  32. println "$a, $b, $c"
  33. println isRightTriangle(a, b, c)
  34.  
  35. c.x++
  36. println "$a, $b, $c"
  37. println isRightTriangle(a, b, c)
Success #stdin #stdout 1.58s 332352KB
stdin
Standard input is empty
stdout
[x:17, y:13], [x:21, y:27], [x:38, y:7]
true
[x:17, y:13], [x:38, y:7], [x:21, y:27]
true
[x:17, y:13], [x:38, y:7], [x:22, y:27]
false