I need an algorithm to calculate the distribution of points on a spiral path.
The input parameters of this algorithm should be:
- Width of the loop (distance from the innermost loop)
- Fixed distance between the points
- The number of points to draw
The spiral to draw is an archimedean spiral and the points obtained must be equidistant from each other.
The algorithm should print out the sequence of the Cartesian coordinates of single points, for example:
Point 1: (0.0)
Point 2: (..., ...)
........
Point N (..., ...)
The programming language isn't important and all help greatly appreciated!
EDIT:
I already get and modify this example from this site:
//
//
// 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);
}
}
But the disposition of point is wrong, the points aren't equidistant from each other.
The correct distribution example is is the image on the left:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…