我需要一种算法来计算螺旋路径上的点分布。
该算法的输入参数应为:
- 环的宽度(距最内环的距离)
- 点之间的固定距离
- 要绘制的点数
要绘制的螺旋线是阿基米德螺旋线,获得的点必须彼此等距。
该算法应打印出单点笛卡尔坐标的序列,例如:
第 1 点:(0.0) 第 2 点:(..., ...) ........ 第 N 点 (..., ...)
编程语言并不重要,非常感谢所有帮助!
编辑:
我已经从这个站点获取并修改了这个例子:
//
//
// centerX-- X origin of the spiral.
// centerY-- Y origin of the spiral.
// radius--- Distance from origin to outer arm.
// sides---- Number of points or sides along the spiral's arm.
// coils---- Number of coils or full rotations. (Positive numbers spin clockwise, negative numbers spin counter-clockwise)
// rotation- Overall rotation of the spiral. ('0'=no rotation, '1'=360 degrees, '180/360'=180 degrees)
//
void SetBlockDisposition(float centerX, float centerY, float radius, float sides, float coils, float rotation)
{
//
// How far to step away from center for each side.
var awayStep = radius/sides;
//
// How far to rotate around center for each side.
var aroundStep = coils/sides;// 0 to 1 based.
//
// Convert aroundStep to radians.
var aroundRadians = aroundStep * 2 * Mathf.PI;
//
// Convert rotation to radians.
rotation *= 2 * Mathf.PI;
//
// For every side, step around and away from center.
for(var i=1; i<=sides; i++){
//
// How far away from center
var away = i * awayStep;
//
// How far around the center.
var around = i * aroundRadians + rotation;
//
// Convert 'around' and 'away' to X and Y.
var x = centerX + Mathf.Cos(around) * away;
var y = centerY + Mathf.Sin(around) * away;
//
// Now that you know it, do it.
DoSome(x,y);
}
}
但是点的配置是错误的,点之间的距离不是等距的。
正确的分布示例是左边的图像: