Installation Program_Execution Data_Structures Data_Input Data_Handling Functions Data_Manipulation

Goal

Hands-on practice for the work with matrices (np.array), and with the generation of simple plots using matplotlib.pyplot.

Additional Information

Here you can find additional information on ...


Translating Data

Write a Python script that:
  • specifies two points, P_0 = [0, 0] and P_1 = [2, 1]. Each point should be expressed as a Python list([a,b])
  • combines these two points to a np.array,
  • shifts those data, by adding 3 to the first coordinate, and 1 to the second,
  • plots a line from the original P_0 to the original P_1, and on the same figure also plots a line between the shifted values.
Translation

Rotating a Vector

Write a Python script that specifies two points, P_0 = [0, 0] and P_1 = [2, 1], and calculates the vector from P_0 to P_1. Then write a Python-function that:
  • takes a vector and an angle as input parameters,
  • rotates the vector by 25 degrees,
  • and returns the rotated vector.
Tip: A 2D rotation matrix is defined by
			R = np.array([[np.cos(alpha), -np.sin(alpha)],
				      [np.sin(alpha),  np.cos(alpha)]])
        
If you want to experiment a bit with plots, you can try to
  • plot a green line from P_0 to P_1,
  • superpose this plot with a coordinate system, from -2 to +2,
  • superpose the rotated line in red, with increased line-thickness. (You can modify the width of a line with the plot parameter linewidth=... )
Rotation

Solution