You will write three functions that measure a path by adding up short straight pieces. The checker uses a straight line, a circle and a point that turns back.
The idea. In a short time the point moves almost in a straight line, so the piece has length . Adding many pieces gives the length of the path. For a point on a line, the distance adds the sizes of the steps, and the displacement is the final position minus the first.
Your tasks.
piece(x1, y1, x2, y2). Return the straight distance between the two points.path_length(fx, fy, t0, t1, n). Split the time from t0 to t1 into n equal steps and add the piece lengths between the points (fx(t), fy(t)).distance_and_displacement(fx, t0, t1, n) for a point on a line. Return the pair (distance, displacement) using n steps.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…