TIP: Click on subject to list as thread! ANSI
echo: quik_bas
to: RICK PEDLEY
from: DAVID WILLIAMS
date: 1998-04-27 15:40:00
subject: Help needed (geometry cod

-> I can't think that anything would be much simpler and faster than the
-> method I posted, involving just calculating a couple of ATNs and
-> subtracting the results from each other.
I've a funny feeling that maybe the posting in which I did that somehow
went astray. So here is the program again:
100 'calculate angle defined by x,y of 3 points
110 '
120 DEFDBL A - Z
130 DEFINT J
140 DIM X(2), Y(2), A(2)
150 PI=4*ATN(1)
160 '
170 'input co-ordinates of the 3 points
180 PRINT "First point entered will be vertex of angle"
190 PRINT
200 FOR J = 0 TO 2
210 PRINT "For point # "; J + 1
220    INPUT "X co-ordinate"; X(J)
230    INPUT "Y co-ordinate"; Y(J)
240    PRINT
250 NEXT
260 '
270 FOR J = 1 TO 2 'for each non-vertex point
280    'calculate x and y relative to vertex
290    X = X(J) - X(0)
300    Y = Y(J) - Y(0)
310    'calculate angle between line from vertex to point and x-axis
320    IF X=0 THEN A(J)=SGN(Y)*PI/2 ELSE A(J)=ATN(Y/X)-PI*(X<0)
330 NEXT
340 '
350 'calculate angle between lines
360 A=ABS(A(1)-A(2))
370 IF A>PI THEN A=2*PI-A
380 '
390 'print out result
400 PRINT "Angle is ";A;" radians, or ";A*180/PI;" degrees."
Of course, it's just the bit from line 270 to 370 that does all the
calculations - just seven lines of functional code. I don't think any
other method could be much simpler than that!
                              dow
--- PCBoard (R) v15.3 (OS/2) 5
---------------
* Origin: FidoNet: CAP/CANADA Support BBS : 416 287-0234 (1:250/710)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.