You will write three small functions: one that finds the direction ratios of the line through two points, one that turns direction ratios into direction cosines, and one that tests whether three numbers can be direction cosines.
The idea. The direction ratios of the line from to are the differences of the coordinates. Dividing them by the length gives the direction cosines. A set of direction cosines must have squares that add to .
Your tasks.
direction_ratios(p, q). Return the three differences as a tuple.direction_cosines(a, b, c). Divide each ratio by the length.is_direction_cosines(l, m, n). Return True when is within 1e-9 of .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…