def (a, b, c) = [[x: 17, y: 13], [x: 21, y: 27], [x: 38, y: 7]]
boolean isOrthogonalVectors(int mx, int my, int nx, int ny) {
return (mx*nx + my*ny == 0);
}
boolean isRightTriangle(a, b, c) {
boolean result = false;
int abx = a.x - b.x;
int aby = a.y - b.y;
int acx = a.x - c.x;
int acy = a.y - c.y;
if (isOrthogonalVectors(abx, aby, acx, acy)) {
result = true;
}
else {
int bcx = c.x - a.x;
int bcy = c.y - a.y;
result = isOrthogonalVectors(abx, aby, bcx, bcy) || isOrthogonalVectors(acx, acy, bcx, bcy);
}
return result;
}
println "$a, $b, $c"
println isRightTriangle(a, b, c)
(b, c) = [c, b]
println "$a, $b, $c"
println isRightTriangle(a, b, c)
c.x++
println "$a, $b, $c"
println isRightTriangle(a, b, c)
ZGVmIChhLCBiLCBjKSA9IFtbeDogMTcsIHk6IDEzXSwgW3g6IDIxLCB5OiAyN10sIFt4OiAzOCwgeTogN11dCgpib29sZWFuIGlzT3J0aG9nb25hbFZlY3RvcnMoaW50IG14LCBpbnQgbXksIGludCBueCwgaW50IG55KSB7CiAgICByZXR1cm4gKG14Km54ICsgbXkqbnkgPT0gMCk7Cn0KCmJvb2xlYW4gaXNSaWdodFRyaWFuZ2xlKGEsIGIsIGMpIHsKICAgIGJvb2xlYW4gcmVzdWx0ID0gZmFsc2U7CiAgICAKICAgIGludCBhYnggPSBhLnggLSBiLng7CiAgICBpbnQgYWJ5ID0gYS55IC0gYi55OwogICAgaW50IGFjeCA9IGEueCAtIGMueDsKICAgIGludCBhY3kgPSBhLnkgLSBjLnk7CiAgICAKICAgIGlmIChpc09ydGhvZ29uYWxWZWN0b3JzKGFieCwgYWJ5LCBhY3gsIGFjeSkpIHsKICAgICAgICByZXN1bHQgPSB0cnVlOwogICAgfQogICAgZWxzZSB7CiAgICAgICAgaW50IGJjeCA9IGMueCAtIGEueDsKICAgICAgICBpbnQgYmN5ID0gYy55IC0gYS55OwogICAgICAgIAogICAgICAgIHJlc3VsdCA9IGlzT3J0aG9nb25hbFZlY3RvcnMoYWJ4LCBhYnksIGJjeCwgYmN5KSB8fCBpc09ydGhvZ29uYWxWZWN0b3JzKGFjeCwgYWN5LCBiY3gsIGJjeSk7CiAgICB9CiAgICAKICAgIHJldHVybiByZXN1bHQ7Cn0KCnByaW50bG4gIiRhLCAkYiwgJGMiCnByaW50bG4gaXNSaWdodFRyaWFuZ2xlKGEsIGIsIGMpCgooYiwgYykgPSBbYywgYl0KcHJpbnRsbiAiJGEsICRiLCAkYyIKcHJpbnRsbiBpc1JpZ2h0VHJpYW5nbGUoYSwgYiwgYykKCmMueCsrCnByaW50bG4gIiRhLCAkYiwgJGMiCnByaW50bG4gaXNSaWdodFRyaWFuZ2xlKGEsIGIsIGMp
[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