A road consists of a sequence of circular arcs and straight sections. We want
to know the straight line distance between the two ends of the road, treating
the road as a curvy line with negligible width.
The path of the road is specified by a sequence of sections. Each section has a
length (when travelling along the road) and a radius of curvature (telling the radius of
a circle that this section follows). A positive radius is a curve to the right, a negative
radius indicates that the curve is to the left, and a radius of 0 is a special
value indicating that this section is straight.
Each circular arc section of the road is on the circle that is tangential to the path of
the road at both its ends. So, for example, if the road is heading northeast when a section
with radius of curvature equal to -3 begins, the
center of that section's circle is 3 units to the northwest of that point on the road.
Create a class Curvy that contains a method distance that is given int[]s
length and radius and that returns the straight line distance between the two
ends of the road. The i-th elements of length and radius indicate the information
for the i-th section as we travel from start to end.
|