Ken*_*sen 3 php math trigonometry formula
我遇到了一些代码问题,但找不到错误.我正在尝试计算下面草图上用红色标记的距离.
我的代码返回值:-41.63
正确的价值是:3.75
我的代码:
return round(6.5 * tan(30),2);
Run Code Online (Sandbox Code Playgroud)
基于:http: //php.net/manual/en/function.tan.php
我认为这将是一个简单的任务,但我撞墙 - 看不到错误.我希望你们中的一些人能指出我正确的方向.
谢谢,
肯尼斯
arg参数以弧度为单位.
您正在发送度数和函数期望Radians,因此首先将您的值从Degrees转换为Radians,您将获得预期的结果.
return round(6.5 * tan(deg2rad(30)),2); //3.75
Run Code Online (Sandbox Code Playgroud)