1

Find angle in php when we know base perpendicular and hypotenuse ?

I am making a project in PHP and need me some calculations but i am unable to imagine how to find out the angle when know base perpendicular and hypotenuse

Find Angle

Here is:
AB = 3000 = BASE
BC = 1000 = PERPENDICULAR
AC = find by me in php script as below

But here is i need the find out angle among the AB to AC or A°

Script for find HYPOTENUSE in PHP as below

<?php 
if(isset($_GET['f']) and ($_GET['t'])){
    $fr = $_GET['f'];
    $to = $_GET['t'];
    $xf = explode(', ',$fr);
    $xt = explode(', ',$to);

    $ans1   =   $xf[0]-$xt[0];
    $ans2   =   $xf[1]-$xt[1];
    $ans3   =   $ans1*$ans1;
    $ans4   =   $ans2*$ans2;
    $ans5   =   (sqrt($ans3+$ans4))*111.2;
} else {
    $fr = $to = $ans5 = "";
}
?>




<form action="" method="GET">
From:<br>
<input type="text" name="f" value="<?php echo $fr; ?>"></input>
<p></p>
To:<br>
<input type="text" name="t" value="<?php echo $to; ?>"></input>
<p></p>
<button type="submit">CALCULATE</button>
</form>
<hr>
<div>
<?php 
echo 'Distance: <strong>'.round($ans5*1000, 2).'</strong> meter(s)';
echo ' or <strong>'.round(($ans5), 3).'</strong> kilometer(s)<br>';
echo 'Distance: <strong>'.round(($ans5*0.621371), 3).'</strong> Mile(s)<br>';
echo 'Distance: <strong>'.round(($ans5*1000*3.28084), 2).'</strong> Foot';?>
</div>
<hr>
dhna
  • 71
  • 2
  • 10
  • arcSoh-arcCah-arcToa... so arctan(1000/3000) or arctan(1/3) = ? – Jonny Henly Apr 23 '15 at 08:29
  • This might help https://www.mathsisfun.com/algebra/trig-finding-angle-right-triangle.html – 0o'-Varun-'o0 Apr 23 '15 at 08:29
  • This might help as well: PHP's inverse tangent function is `atan()`. So your code would look similar to: `$arctan = atan(1/3);` – Jonny Henly Apr 23 '15 at 08:34
  • This is not working for me because if `atan(1/3) or atan(1000/3000) then return 18.43°` if `atan(1) then return 45°` but return another values please check and confirm please – dhna Apr 23 '15 at 08:52

1 Answers1

1

You could use something like this I made to calculate the angle to put text in an image from left bottom corner to right top corner.

$image_hypotenuse = hypot($image_width, $image_height);
$a = $image_hypotenuse;
$b = $image_height;
$c = $image_width;
$a2 = $a * $a;
$b2 = $b * $b;
$c2 = $c * $c;
$alpha = rad2deg(acos(($b2 + $c2 - $a2) / (2 * $b * $c)));
$beta = rad2deg(acos(($a2 + $c2 - $b2) / (2 * $a * $c)));
$gamma = rad2deg(acos(($a2 + $b2 - $c2) / (2 * $a * $b)));
$text_angle = ceil($beta);
John
  • 1,012
  • 14
  • 22