How to get the coordinates of several points on the circle with php

前端 未结 2 418
有刺的猬
有刺的猬 2021-01-16 06:00

I have a few points. I need to put those points on a circle and get their coordinates.

function positionX($numItems,$thisNum){ 
  $alpha = 360/$numItems; //          


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 06:51

    Thats because you are not using radiants in your sin() and cos() functions. You need to convert angels into radiants. Look at the function description of sin(), there you find that the arg is in radiants.

    Reminder

    1° = 2 PI / 360;
    

    Edit

    I can't seem to find the error in your code, try this one instead

    function($radius, $points, $pointToFind) {
    
     $angle = 360 / $points * 2 * pi(); //angle in radiants
    
     $x = $radius * cos($angle * $pointToFind);
     $y = $radius * sin($angle * $pointToFind);
    
    }
    

提交回复
热议问题