简体   繁体   中英

How to convert a (x, y) position to an angle in PHP?

Using PHP 7.3,

I have the position of a point with XY coordinates that I need to convert to an angle from 0 to 360.

Assuming (123, 0) is angle 0, (0, 123) is angle 90, (-123, 0) is angle 180, etc.

Is there some function to do that ?

Thx.

I wrote that:

$angle = 180 * atan2($y, $x) / M_PI;
if($angle < 0) {
  $angle += 360;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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