Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import sys
  2.  
  3. p = 13
  4. q = 4 #p // 2
  5.  
  6. try:
  7.     rx, ry, rw, rh = map(int, input().split())
  8.     #rx, ry, rw, rh = (0, 0, 100, 100)
  9. except:
  10.     sys.exit(0)
  11.  
  12. def intersection(s1, s2):
  13.     x1, y1 = s1[0]
  14.     x2, y2 = s1[1]
  15.     x3, y3 = s2[0]
  16.     x4, y4 = s2[1]
  17.     d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
  18.  
  19.     if d == 0:
  20.         return None
  21.     return (((x1*y2 - y1*x2) * (x3 - x4) - (x1 - x2) * (x3*y4 - y3*x4)) / d,
  22.             ((x1*y2 - y1*x2) * (y3 - y4) - (y1 - y2) * (x3*y4 - y3*x4)) / d)
  23.  
  24. # all points on the circle
  25. pts = [(sin(x), -cos(x)) for x in (2*pi / p * i for i in range(p))]
  26.  
  27. shift_list = lambda l, x: l[x:] + l[:x]
  28. forward_segments = list(zip(pts, shift_list(pts, q)))
  29. backward_segments = shift_list(forward_segments, len(forward_segments) // 2 + 4)
  30.  
  31. internal_pts = map(intersection, forward_segments, backward_segments)
  32. all_pts = [ (int(round(rx + x * rw / 2)),
  33.              int(round(ry + y * rh / 2)))
  34.             for pair in zip(pts, internal_pts) for (x, y) in pair ]
  35.  
  36. res_str = ' '.join((str(x) for pair in all_pts for x in pair))
  37. print(res_str)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement