TIP: Click on subject to list as thread! ANSI
echo: quik_bas
to: MIKE WYNNE
from: DAVID WILLIAMS
date: 1998-04-19 10:35:00
subject: Help needed (geometry cod

-> Calculate the angle (radians) subtended at a point by two lines
-> joining from 2 other points, given the x & y coordinates of all 3
-> points.
->
-> ie: the internal angle at the apex of a triangle,  errrr if you get
-> my meaning
Well... If you do some subtractions so as to put the apex point at the
origin, so the coordinates of the other two points are referred to it,
then you can easily calculate the angle between the (new) X-axis and
each of the lines from the origin to the other two points. Basically,
it's just ATN(Y/X), where X and Y are the coordinates of the other
point. However, you'd have to put in some coding to deal with the
possibility that X might be zero, in which case the angle would be
SGN(Y)*PI/2, and also to add PI to the ATN result if X is negative. (I
think that's right!)
When you've got the two angles between the X-axis and the two lines, all
you have to do is subtract these angles to get the angle between the two
lines. Take its ABSolute value and, if necessary, subtract from 2*PI so
as to make the result no greater than PI. (Presumably, you want to
calculate the *internal* angle of the triangle!)
I think this strategy would work, and would be faster than solving the
equation that you can derive from the "cosine rule". Of course, that
would be an alternative approach...
                           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™.