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

-> Say you want to find the value of the angle at (x1, y1) in this
-> triangle:
->
->                  (x2,y2)
->                 /\
->                /  \
->               /    \
->              /      \
->             /        \
->            /          \
->           /            \
->          /______________\
->         (x3,y3)          (x1,y1)
->
-> The fastest way I can think of is to drop a perpendicular from
-> (x2,y2) to the line between (x3,y3) and (x1,y1). Now you have a
-> right-angled triangle formed by (x2,y2), (x1,y1), and (x4,y4).
->
->                  (x2,y2)
->                 /\
->                /| \
->               / |  \
->              /  |   \
->             /   |    \
->            /    |     \
->           /     |      \
->          /______|_______\
->         (x3,y3) (x4,y4)  (x1,y1)
->
-> Find the length of the perpendicular (y2 - y4). Find the length of
-> the hypotenuse ->  SQR((x1 - x2)^2 + (y2 - y1)^2).
-> The length of the perpendicular divided by the length of the
-> hypotenuse gives the sine of the angle at (x1,y1), which we'll call
-> z. The arcsin of z in radians is found by:
->
-> ATN(z / SQR(-x * x + 1 + 1E-37))
Umm... Unless y1 and y3 are equal, in which case the problem is trivial,
how do you find the length of the perpendicular?
I've already posted one solution to this problem, which I still believe
to be the best one. However, there is another approach, based on the
"cosine rule". Basically, if the three angles of a triangle are A, B and
C, measured in degrees, radians or whatever, and the lengths of the
sides opposite the angles are a, b and c units, the cosine rule says:
a^2 = b^2 + c^2 - 2 * b * c * cos(A)
                  A
                /   \
            b  /     \  c
              /       \
             C _______ B
                  a
Note that if A is a right angle, cos(A) is zero, and the cosine rule
reduces to the Pythagorean Theorem.
The equation can obviously be rearranged to calculate cos(A) if the
lengths of all three sides are known, and in fact they are known if the
co-ordinates of the three angles are given. The distance between any two
points, (x1,y1) and (x2,y2), is just sqr((x1-x2)^2 + (y1-y2)^2) - which
can be derived from the Pythagorean Theorem. So, in our triangle, a, b
and c are known, so cos(A) can be calculated. From there on, it's just a
matter of using an arc-cosine formula, arranged to produce a result
between zero and pi radians, to find the angle A.
This would certainly work. But I still prefer the method I described
previously!
                            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™.