[Nottingham] Trigonometry!

Duncan John Fyfe djf at star.le.ac.uk
Thu Jan 25 10:53:42 GMT 2007


On Wed, 2007-01-24 at 23:41 +0000, Jonathan wrote:
> If you have two pairs of coordinates (x_1, y_1) and (x_2, y_2) in the
> first quadrant of R^2 (x_1, x_2 > 0 and y_1, y_2 > 0) and want to
> determine the angle the line x = x_1 forms with the hypotenuse (which
> from your description is what you want to do...I think!) just use a
> bit of elementary trig:
> 
> Consider the triangle formed with opposite 'y_2 - y_1' and adjacent
> 'x_2 - x_1'.
> tan(theta) = opposite / adjacent = (y_2 - y_1) / (x_2 - x_1).
> Now just apply the inverse tan function...
> 'atan' in C, not sure about PHP...
> 

Pay attention to units! 
Most languages I know (including php) assume angles are in radians so
the numbers you get out might not look like those you are expecting.

See also: http://uk.php.net/atan

There are also links from there to atan2 and rad2deg a php function to
do as the name suggests if you are more used to angles in degrees.

Have fun,
Duncan






More information about the Nottingham mailing list