围绕圆动态调整数字间距
我试图弄清楚如何动态地将数字放置在一个圆圈周围(类似于钟面),但是如果圆圈周围的数字数量是 5 或 27,那么它们会正确地间隔开。
我发现一些代码(如下)看起来可能有帮助,但我在实现它时遇到了麻烦。我不知道如何将其与圆圈和数字联系起来。
任何帮助将不胜感激。 谢谢
function getNPointsOnCircle( center:Point, radius:Number, n:Number = 10 ) : Array
{
var alpha:Number = Math.PI * 2 / n;
var points:Array = new Array( n );
var i:int = -1;
while( ++i < n )
{
var theta:Number = alpha * i;
var pointOnCircle:Point = new Point( Math.cos( theta ) * radius, Math.sin( theta ) * radius );
points[ i ] = center.add( pointOnCircle );
}
return points;
}
I'm trying to figure out how to dynamically place numbers around a circle (similar to a clock face) but dynamically so if the number of numbers around the circle is 5 or 27.. they would space out correctly.
I found some code (below) that looked like it might help but I'm having trouble implementing it. I don't know how I actually tie this back to the circle and numbers.
Any help would be much appreciated.
Thanks
function getNPointsOnCircle( center:Point, radius:Number, n:Number = 10 ) : Array
{
var alpha:Number = Math.PI * 2 / n;
var points:Array = new Array( n );
var i:int = -1;
while( ++i < n )
{
var theta:Number = alpha * i;
var pointOnCircle:Point = new Point( Math.cos( theta ) * radius, Math.sin( theta ) * radius );
points[ i ] = center.add( pointOnCircle );
}
return points;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该代码完美运行。使用方法如下:
That code works perfectly. This is how to use it: