Problem 4. (3 points) A spaceship in three-dimensional space is equipped with a set of thrusters, described by a configuration matrix T, whose column vectors fj give the orientation (as vector direction) and power (as vector magnitude) of each thruster. Thus,
T =
describes a configuration with three thrusters. If the ship is positioned at (0,0,0), the first thruster is pointing towards coordinates (1,2,3) and has power |f,| = /Ï4.
The thrusters are operated with a command vector c = (c,,c2,c3)r, where c, describes the activation of thruster i. For example, c = (1, 2,0)T activates thruster 1 with power 1, thruster 2 with twice that power but in the “reverse thrust” mode, and leaves thruster 3 unactivated.
(All vectors in this problem are column vectors, and we will be omitting the transpose symbol from now on.)
The product TZ gives a displacement vector d, describing the change in the ships coordinates after a single firing of all thrusters. In our example, 3 = (-3,-4,7). If the ship was positioned at (0,0,0), it will now be at (3,4,7). Issuing a subsequent command c = (1,1,1) will give d = (4,5,9) and bring the ship to (1,1,2).
Use Python, NumPy, and SciPy to write the following functions. When you need to provide specific outputs, use the T defined above. At the same time, your functions need to be generic and work with any T.
a. Write function distance(T.c) that returns the distance traveled by the ship after a single firing of all thrusters.
Determine the distances resulting from commands (1,1,1), (1,1,1), (1,2,3), (3,2,1).
b. Write function reachable(T,p) that returns True if the ship starting at (0,0,0) can reach point p in any number of moves, or False otherwise.
Determine whether the following points are reachable: (0,2,2), (1,1,1), (5,1,-4), (1,3,1).
c. Commands that result in the displacement vector d = (0,0,0) stress the ships structure and are considered dangerous. Write function safe( T,c) that returns True if the command is safe, or False otherwise.
Note that computing d = TZ directly means activating the thrusters with a potentially dangerous command and is not acceptable, so we need to find another way.
Determine the safety of commands (4,7,3), (0,0,0), (0,2,5), (3,2,1).
