Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import math
- import matplotlib.path as mpath
- import matplotlib.patches as mpatches
- import matplotlib.pyplot as plt
- # Pfad zeichnen
- def drawpoly(verts: list):
- Path = mpath.Path
- path_data: list = []
- for v in verts:
- path_data.append((Path.MOVETO, (v[0], v[1])))
- path_data.append((Path.CLOSEPOLY, (verts[0][0], verts[0][1])))
- fig, ax = plt.subplots()
- codes, verts = zip(*path_data)
- path = mpath.Path(verts, codes)
- # plot control points and connecting lines
- x, y = zip(*path.vertices)
- line, = ax.plot(x, y, 'go-')
- ax.grid()
- ax.axis('equal')
- plt.show()
- # Polygon
- verts = [np.array([0,0, 0]),
- np.array([0,1, 0]),
- np.array([0.5,1.5, 0]),
- np.array([1,1, 0]),
- np.array([1,0, 0])]
- #Winkel
- a = 45
- a = math.pi * (2*a/360)
- # Rotationsmatrix
- rotmatrix: np.ndarray = np.array([[math.cos(a), -math.sin(a), 0],
- [math.sin(a), math.cos(a), 0],
- [0,0,1]])
- # Matrix Multiplikation
- for i in range(len(verts)):
- verts[i] = verts[i].dot(rotmatrix)
- drawpoly(verts)
Advertisement
Add Comment
Please, Sign In to add comment