I'm getting carried away with this. Where are the men in white coats?...
I coded up the cosine-rule method. It's not too bad. Just two SQRs and
one ATN in the actual calculation, plus one ATN to find pi.
100 'calculate angle defined by x,y of 3 points
110 '
120 DEFDBL A - Z
130 PI=4*ATN(1)
140 '
150 'input co-ordinates of the 3 points
160 PRINT "First point entered will be vertex of angle"
170 PRINT
180 FOR J = 0 TO 2
190 PRINT "For point # "; J + 1
200 INPUT "X co-ordinate"; X(J)
210 INPUT "Y co-ordinate"; Y(J)
220 PRINT
230 NEXT
240 '
250 ' cosine rule method
260 DEF FNM(X,Y) = (X + Y) MOD 3
270 DEF FND(J,K) = (X(J)-X(K))^2 + (Y(J)-Y(K))^2
280 DEF FNZ(J) = FND(FNM(J,1),FNM(J,2))
290 A=FNZ(0):B=FNZ(1):C=FNZ(2) ' side-lengths *squared*
300 CS = (B + C - A)/(2 * SQR(B * C)) 'cosine rule. CS is cos angle A
310 AN = PI/2 - ATN(CS/(1E-37 + SQR(1 - CS*CS))) 'arc-cosine formula
320 PRINT AN; " radians, "; AN*180/PI; " degrees."
Yes. I admit it. I used your 1E-37 thingy in line 310.
I still think the other way is better, but this does work.
dow
--- PCBoard (R) v15.3 (OS/2) 5
---------------
* Origin: FidoNet: CAP/CANADA Support BBS : 416 287-0234 (1:250/710)
|