绘制点均匀分布在一个圆上 [英] drawing points evenly distributed on a circle
本文介绍了绘制点均匀分布在一个圆上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在直径为x的圆上得到n个点的坐标。我试过这个:
<?php
header(Content-Type:image / png);
$ img = @imagecreate(900,900)
或die(无法初始化新的GD图像流);
$ background_color = imagecolorallocate($ img,255,255,255);
$ red = imagecolorallocate($ img,255,0,0); $($ 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);
?>
但似乎有错误:
学校和数学和罪恶和COS是很久以前...所以我会很高兴,如果有人可以给我一个提示
解决方案
基本上只使用deg2rad功能。 http://www.php.net/manual/en/function.deg2rad.php
所以改变你的cos和sin调用:
$ y = round(sin(deg2rad($ i))* 400)+450;
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:
school and math and sin&cos is long ago ... so i would be happy if someone could give me a hint
解决方案
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;
这篇关于绘制点均匀分布在一个圆上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文