-> (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(-z * z + 1 + 1E-37))
DW> Umm... Unless y1 and y3 are equal, in which case the problem is
DW> trivial, how do you find the length of the perpendicular?
True, the triangle must be oriented correctly for the trivial solution.
It always works perfectly in trig class :)
DW> I've already posted one solution to this problem, which I still
DW> believe to be the best one. However, there is another approach, based
DW> on the "cosine rule".
Yeah, I know about that one, problem is you must first find the lengths
of all three sides, involving 3 square root operations, not the fastest
method (and the emphasis is on speed), plus another square root in the
arccos formula.
DW> This would certainly work. But I still prefer the method I described
DW> previously!
I don't see a really fast method in any of these. I betcha there is a
much faster method lurking out there, involving a little bit of approx-
imation, error, and downright cheating, but fast enough and accurate
enough for, say, game purposes. One example: if all the possible cosine
or sine values were known for a specific application, they could be
stored in a look-up table matched with their corresponding angles, thus
avoiding the arcsin/arccos calculation. A binary search would be needed
to locate the sin/cos value however and a speed comparison would have
to be done to see if this is faster than a straight calculation.
--- Blue Wave/DOS v2.20
---------------
* Origin: ...the vented spleen - kingston on (613) 544-9332 (1:249/139)
|