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

-=> Quoting David Williams to Rick Pedley <=-
 DW> 270 FOR J = 1 TO 2 'for each non-vertex point
 DW> 280    'calculate x and y relative to vertex
 DW> 290    X = X(J) - X(0)
 DW> 300    Y = Y(J) - Y(0)
 DW> 310    'calculate angle between line from vertex to point and x-axis
 DW> 320    IF X=0 THEN A(J)=SGN(Y)*PI/2 ELSE A(J)=ATN(Y/X)-PI*(X<0)
 DW> 330 NEXT
 DW> 340 '
 DW> 350 'calculate angle between lines
 DW> 360 A=ABS(A(1)-A(2))
 DW> 370 IF A>PI THEN A=2*PI-A
 DW> 380 '
 DW> 390 'print out result
 DW> 400 PRINT "Angle is ";A;" radians, or ";A*180/PI;" degrees."
 DW> Of course, it's just the bit from line 270 to 370 that does all the
 DW> calculations - just seven lines of functional code. I don't think any
 DW> other method could be much simpler than that!
It's pretty good. I would look for some way to reduce or eliminate the
real division, arctan, and multiplication operations which are all
floating point ops. 2*PI and PI/2 are obvious ones, replaced with 6.28 and
1.57.. SGN might also be FP, I forget now.
--- Blue Wave/DOS v2.20
---------------
* Origin: ...the vented spleen - kingston on (613) 544-9332 (1:249/139)

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™.