drawing points evenly distributed on a circle

对着背影说爱祢 提交于 2020-02-05 10:17:28

问题


i want to get the coordinates of n points on a circle with the diameter of x

i tried this:

<?php
header("Content-Type: image/png");
$img = @imagecreate(900, 900)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($img, 255, 255, 255);
$red = imagecolorallocate($img, 255, 0, 0);
for($i=0;$i<=360;$i+=10)
{
$x = round(cos($i)*400)+450;
$y = round(sin($i)*400)+450;
imagefilledellipse($img, $x, $y, 3, 3, $red);
}
imagepng($img);
imagedestroy($img);
?>

but there seems to be an error:

http://imgur.com/EYJe3hB

school and math and sin&cos is long ago ... so i would be happy if someone could give me a hint


回答1:


Basically just use the deg2rad function. http://www.php.net/manual/en/function.deg2rad.php

So change your cos and sin calls to this:

$x = round(cos(deg2rad($i))*400)+450;
$y = round(sin(deg2rad($i))*400)+450;



回答2:


PHP trigonometric functions accept radian values, so you should multiply values of $i by Pi/180.



来源:https://stackoverflow.com/questions/19977755/drawing-points-evenly-distributed-on-a-circle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!