Advertisement
gwilliams

cosine polyline

Oct 20th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. def cosine_polyline(pdf, x0, y0, x1, y1, orientation):
  2.     N = 32
  3.     x_points = []
  4.     y_points = []
  5.     if orientation == horizontal:
  6.         w = (x1 - x0)
  7.         h = 0.5 * (y1 - y0)
  8.         y_avg = 0.5 * (y0 + y1)
  9.     elif orientation == vertical:
  10.         w = 0.5 * (x1 - x0)
  11.         h = (y1 - y0)
  12.         x_avg = 0.5 * (x0 + x1)
  13.     else:
  14.         raise Exception()
  15.  
  16.     for i in range(0, N + 1):
  17.         frac = float(i) / N
  18.         angle = math.pi * frac
  19.         if orientation == horizontal:
  20.             x = x0 + w * frac
  21.             y = y_avg + h * math.cos(angle)
  22.         elif orientation == vertical:
  23.             x = x_avg - w * math.cos(angle)
  24.             y = y0 + h * frac
  25.         else:
  26.             raise Exception()
  27.  
  28.         x_points.append(x)
  29.         y_points.append(y)
  30.  
  31.     pdf.draw_polyline(x_points, y_points)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement