morty346 morty346 - 1 month ago 23
PHP Question

php cos not working?

I have a lat, in this case,

29
or
45


I plot it in here

$lonchangepermile = cos($startlat) * 69.172;

var_dump($startlat);
var_dump('b');
var_dump($lonchangepermile);


and I get the results
-51.744
and
36.33
(see screenshot)

according to my brain, and my windows calculator it should be
48.911
and
60.499


Whats the deal?


Answer

You're using degrees. PHP, like many other languages uses radians. Use deg2rad() on your inputs.