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; //
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);
}
The cos() and sin() functions expect the argument in radians, not in degrees.
Use the deg2rad() function to convert
EDIT
CODE:
function positionX($numItems,$thisNum){
$alpha = 360/$numItems; // angle between the elements
$r = 1000; // radius
$angle = $alpha * $thisNum; // angle for N element
$x = $r * cos(deg2rad($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(deg2rad($angle)); // Y coordinates
return $y;
}
echo round(positionX(4,1))."<br>";
echo round(positionY(4,1))."<br><br>";
echo round(positionX(4,2))."<br>";
echo round(positionY(4,2))."<br><br>";
echo round(positionX(4,3))."<br>";
echo round(positionY(4,3))."<br><br>";
echo round(positionX(4,4))."<br>";
echo round(positionY(4,4))."<br><br>";
RESULTS:
0
1000
-1000
0
-0
-1000
1000
-0