繁体   English   中英

当我们知道基本的垂直和斜边时,如何在php中找到角度?

[英]How Find angle in php when we know base perpendicular and hypotenuse?

当我们知道基本垂线和斜边时,在php中找到角度?

我正在用PHP创建一个项目,需要我一些计算,但是当我知道基本的垂线和斜边时,我无法想象如何找出角度。

寻找角度

这是:
AB = 3000 =基础
BC = 1000 =垂直
AC =在下面的php脚本中由我找到

但是这是我需要找出AB与AC或A°之间的角度

在PHP中查找HYPOTENUSE的脚本如下

<?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>

您可以使用我制作的类似内容来计算将文本从左下角到右上角放置到图像中的角度。

$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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM