-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path82-NatureOfQuadrilaterals.js
63 lines (56 loc) · 1.64 KB
/
82-NatureOfQuadrilaterals.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const n = parseInt(readline())
for (let i = 0; i < n; i++) {
var inputs = readline().split(' ')
const A = inputs[0]
const xA = parseInt(inputs[1])
const yA = parseInt(inputs[2])
const B = inputs[3]
const xB = parseInt(inputs[4])
const yB = parseInt(inputs[5])
const C = inputs[6]
const xC = parseInt(inputs[7])
const yC = parseInt(inputs[8])
const D = inputs[9]
const xD = parseInt(inputs[10])
const yD = parseInt(inputs[11])
const abY = Math.abs(yB - yA)
const abX = Math.abs(xB - xA)
const bcY = Math.abs(yC - yB)
const bcX = Math.abs(xC - xB)
const cdY = Math.abs(yD - yC)
const cdX = Math.abs(xD - xC)
const daY = Math.abs(yA - yD)
const daX = Math.abs(xA - xD)
let flags = new Set()
if (abY / abX === cdY / cdX && bcY / bcX === daY / daX) {
flags.add('PARALLELOGRAM')
}
if (
Math.hypot(abY, abX) === Math.hypot(cdY, cdX) &&
Math.hypot(abY, abX) === Math.hypot(bcY, bcX)
) {
flags.add('RHOMBUS')
}
if (
Math.abs(((Math.atan2(yD - yA, xD - xA) - Math.atan2(yB - yA, xB - xA)) * (180 / Math.PI)) % 90) === 0 &&
Math.abs(((Math.atan2(yB - yC, xB - xC) - Math.atan2(yD - yC, xD - xC)) * (180 / Math.PI)) % 90) === 0
) {
flags.add('RECTANGLE')
}
displayFlag(A + B + C + D, flags)
}
function displayFlag(value, flags) {
let res
if (flags.has('RECTANGLE') && flags.has('RHOMBUS')) {
res = 'square'
} else if (flags.has('RECTANGLE')) {
res = 'rectangle'
} else if (flags.has('RHOMBUS')) {
res = 'rhombus'
} else if (flags.has('PARALLELOGRAM')) {
res = 'parallelogram'
} else {
res = 'quadrilateral'
}
console.log(value + ' is a ' + res + '.')
}