In races in which racers go around at least one turn of a curved track, the starting positions for each racer are staggered, so that each racer travels the same distance around the track (otherwise, the racer in the innermost lane would have a huge advantage).
Given the lengths of the major and minor axes (or semi-major and semi-minor, if you'd prefer) of an elliptical track and the number of lanes in the track, output the distances from the innermost lane's starting point that each lane should be staggered.
Specifications
- Each lane is an ellipse with semi-major axes 5 units longer than the next-shortest lane. For simplicity, assume that the lanes have 0 width.
- The innermost lane always starts at 0, and every other starting point is a positive integer greater than or equal to the previous starting point.
- Input and output may be in any convenient and reasonable format.
- The inputs will always be integers.
- You must calculate the circumference of the track to within 0.01 units of the actual value.
- Outputs are to be rounded down to the nearest integer (floored).
- The finish line is the starting point for the innermost racer. There is only one lap in the race.
- The lengths of the axes are measured using the innermost lane of the track.
- Outputting the 0 for the innermost lane's offset is optional.
Test Cases
Format: a, b, n -> <list of offsets, excluding innermost lane>
20, 10, 5 -> 30, 61, 92, 124
5, 5, 2 -> 31
15, 40, 7 -> 29, 60, 91, 121, 152, 183
35, 40, 4 -> 31, 62, 94
These test cases were generated with the following Python 3 script, which uses an approximation of the circumference of an ellipse devised by Ramanujan:
#!/usr/bin/env python3
import math
a = 35 # semi-major axis
b = 40 # semi-minor axis
n = 4 # number of lanes
w = 5 # spacing between lanes (constant)
h = lambda a,b:(a-b)**2/(a+b)**2
lane_lengths = [math.pi*(a+b+w*i*2)*(1+3*h(a+w*i,b+w*i)/(10+math.sqrt(4-3*h(a+w*i,b+w*i)))) for i in range(n)]
print("{}, {}, {} -> {}".format(a, b, n, ', '.join([str(int(x-lane_lengths[0])) for x in lane_lengths[1:]])))
The approximation used is:
Finally, here is a helpful diagram for understanding the calculations of the offsets:
h**5
, which is well under0.01
for a wide range of values. \$\endgroup\$