Question: Python To avoid redundant code, let's write a single helper function that can handle either case. Complete the function random_direction so that it generates a
Python
To avoid redundant code, let's write a single helper function that can handle either case.
Complete the function random_direction so that it generates a random direction converts it to a Cartesian unit vector, and returns that unit vector as a (x, y, z) three-tuple.
The function should take only one argument, an optional argument named forward_only, that defaults to False. If the function is called with an explicit value of True for this argument, the function should generate a random direction from the +z half-sphere (the "forwards" direction). Otherwise, it should generate one from the full unit sphere (any direction).
function is def random_direction(forwards_only=False):
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
