I’ve been not so busy working on a really quick function for PHP that does pythagoras’ theorem. It works on the sum B2+C2=A2, but this can easily be changed, its just the way I was taught.
Heres the code:
<?php
// PYTHAGORAS’ THEOREM FUNCTION FOR PHP
// by Callum Haywood [callum@network467.co.uk]
// Copyright 2008. All rights reserved.// This works on the calculation B² + C² = A², which
// is what I’ve always been taught. Of course its
// possible to change this, and its easy too.function pythagoras($b, $c)
{
$b1 = $b*$b; // Square value B
$c1 = $c*$c; // Square value C
$a1 = $b1+$c1; // Add them together
$a2 = sqrt($a1); // Find the square root
$a = round($a2, 1); // Round it to 1 DPecho “Side <b>B</b> is <b>$b</b>, and side <b>C</b> is <b>$c</b>. The computer has worked out that side <b>A</b> is <b>$a</b>!”;
}pythagoras(“1″, “2″);
?>
See, it’s simple, just change where it says 1 to the length of side B of your triangle, and where it says 2 to the length of side C of your triangle. Remeber that Pythagoras’ Theorem only works for right-angled triangles. You don’t have to be in KS3, but there is some more info here, that I stumbled across while revising.
Hope someone finds this useful!