A 3x4 rectangle has sides 3,4,3,4 and diagonals 5,5. Its "weight" is said to be 3+4+3+4+5+5 = 24. Find a quadrilateral with all sides and diagonals having integer length and whose weight is smaller than 24.
The program considers two back-to-back triangles sharing a segment that forms one of the diagonals of the quadrilateral:
DECLARE FUNCTION cvdg# (x#)
DECLARE FUNCTION angle1# (a#, b#, c#)
DEFDBL A-Z
DIM SHARED pi
pi = ATN(1) * 4
CLS
FOR t = 5 TO 24
FOR a = 1 TO t / 2
b = t - a
FOR d1 = b - a + 1 TO a + b - 1
angleA = angle1(a, b, d1)
angleB = angle1(b, a, d1)
FOR t2 = d1 + 1 TO 24
FOR c = 1 TO t2 - 1
d = t2 - c
IF d1 + c > d AND d1 + d > c THEN
angleC = angle1(c, d, d1)
angleD = angle1(d, c, d1)
d2sq = b * b + c * c - 2 * b * c * COS(angleA + angleD)
d2 = SQR(d2sq)
d2rnd = INT(d2 + .5)
IF ABS(d2rnd - d2) < .000001 THEN
IF a + b + c + d + d1 + d2 < 24 THEN
PRINT a; b; c; d, d1; d2, a + b + c + d + d1 + d2
PRINT USING "####.####"; cvdg(angle1(d1, a, b)); cvdg(angleA + angleD);
PRINT USING "####.####"; cvdg(angle1(d1, c, d)); cvdg(angleB + angleC)
PRINT
END IF
END IF
END IF
NEXT
NEXT t2
NEXT d1
NEXT a
NEXT t
FUNCTION angle1 (a, b, c)
cosA = (b * b + c * c - a * a) / (2 * b * c)
IF cosA = 0 THEN angleA = pi / 2: EXIT FUNCTION
sinA = SQR(1 - cosA * cosA)
angleA = ATN(sinA / cosA)
IF angleA < 0 THEN angleA = angleA + pi
angle1 = angleA
END FUNCTION
FUNCTION cvdg (x)
cvdg = x * 180 / pi
END FUNCTION
sides diagonals total
2 3 2 4 4 4 19
104.4775 104.4775 75.5225 75.5225 angles
2 4 4 5 3 2 20
46.5675 28.9550 36.8699 157.6076 angles
2 4 2 3 4 4 19
75.5225 75.5225 104.4775 104.4775 angles
2 4 3 5 4 2 20
75.5225 28.9550 53.1301 112.3924 angles
3 4 2 1 2 4 16
28.9550 75.5225 75.5225 180.0000 angles
The smallest without a 180° angle would have sides 2, 3, 2, 4, giving a weighted total of 19. Then, 2, 4, 4, 5 or 2, 4, 3, 5 would have a total of 20.
|
Posted by Charlie
on 2013-07-25 15:57:08 |