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; // angle between the elements
$r = 1000; // radius
$angle = $alpha * $thisNum; // angle for N element
$x = $r * cos($angle); // X coordinates
return $x;
}
function positionY($numItems,$thisNum){
$alpha = 360/$numItems; // angle between the elements
$r = 1000; // radius
$angle = $alpha * $thisNum; // angle for N element
$y = $r * sin($angle); // Y coordinates
return $y;
}
But my code isn’t work.. These functions produce strange coordinates.
image example: http://cl.ly/image/453E2w1Y0w0d
UPD:
echo positionX(4,1)."<br>";
echo positionY(4,1)."<br><br>";
echo positionX(4,2)."<br>";
echo positionY(4,2)."<br><br>";
echo positionX(4,3)."<br>";
echo positionY(4,3)."<br><br>";
echo positionX(4,4)."<br>";
echo positionY(4,4)."<br><br>";
4 – All elements;
1,2,3,4 – Number of element.
These code gives me result:
-448.073616129
893.996663601
-598.460069058
0
984.381950633
-176.045946471
-283.691091487
958.915723414
On the circle it does not work.
The cos() and sin() functions expect the argument in radians, not in degrees.
Use the deg2rad() function to convert
EDIT
CODE:
RESULTS: