Stuntkoala

Rotationsmatrix

Oct 6th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. import numpy as np
  2. import math
  3. import matplotlib.path as mpath
  4. import matplotlib.patches as mpatches
  5. import matplotlib.pyplot as plt
  6.  
  7.  
  8. # Pfad zeichnen
  9. def drawpoly(verts: list):
  10.     Path = mpath.Path
  11.     path_data: list = []
  12.     for v in verts:
  13.         path_data.append((Path.MOVETO, (v[0], v[1])))
  14.     path_data.append((Path.CLOSEPOLY, (verts[0][0], verts[0][1])))
  15.  
  16.     fig, ax = plt.subplots()
  17.     codes, verts = zip(*path_data)
  18.     path = mpath.Path(verts, codes)
  19.  
  20.     # plot control points and connecting lines
  21.     x, y = zip(*path.vertices)
  22.     line, = ax.plot(x, y, 'go-')
  23.  
  24.     ax.grid()
  25.     ax.axis('equal')
  26.     plt.show()
  27.  
  28. # Polygon
  29. verts = [np.array([0,0, 0]),
  30.         np.array([0,1, 0]),
  31.         np.array([0.5,1.5, 0]),
  32.         np.array([1,1, 0]),
  33.         np.array([1,0, 0])]
  34.  
  35. #Winkel
  36. a = 45
  37. a = math.pi * (2*a/360)
  38.  
  39. # Rotationsmatrix
  40. rotmatrix: np.ndarray = np.array([[math.cos(a), -math.sin(a), 0],
  41.                     [math.sin(a), math.cos(a), 0],
  42.                     [0,0,1]])
  43.  
  44. # Matrix Multiplikation
  45. for i in range(len(verts)):
  46.     verts[i] = verts[i].dot(rotmatrix)
  47.  
  48. drawpoly(verts)
Advertisement
Add Comment
Please, Sign In to add comment