我需要一个算法来计算螺旋路径上点的分布。
该算法的输入参数应为:
- 环宽(从最内圈到环边之间的距离)
- 点之间的固定距离
- 所需绘制的点数
要绘制的螺旋线是一种阿基米德螺旋线,并且得到的点必须等距分布。
该算法应打印出单个点的笛卡尔坐标序列,例如:
Point 1: (0.0) Point 2: (..., ...) ........ Point 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);
}
}
但是点的分布不正确,这些点之间不是等距的。
正确的分布示例是左图所示: