Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP trigonometry TAN

Tags:

php

I try to figure out an angle of a triangle.

If one side of the triangle is 100 and the other side is 100.

How do I get that to be 45 degrees.

If I run tan-1(100/100) on my calculator i get 45. How do I do this in PHP?

like image 446
Daniel Avatar asked Jun 24 '26 03:06

Daniel


2 Answers

Use the atan function.

tan-1(100/100) on the calculator is the equivalent to atan(100/100) in Php.

Edit: Sorry, here's the same output as the calculator:

$input = 100 / 100;
print atan($input) * (180 / pi());
//Ouputs 45
like image 159
rzetterberg Avatar answered Jun 25 '26 17:06

rzetterberg


Since you have both rise and run what you really want to use is atan2(), which will handle the difference between e.g. 1/4*pi and -3/4*pi properly.

like image 25
Ignacio Vazquez-Abrams Avatar answered Jun 25 '26 15:06

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!