Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import random as rd
  2. import math as mt
  3. import matplotlib.pyplot as plt
  4.  
  5. ## set this to whatever
  6. distance = 2
  7.  
  8. x = rd.random()*10000
  9. y = rd.random()*10000
  10.  
  11. start_pt = [x,y]
  12.  
  13. angle = rd.uniform(0, 360)
  14. x_1 = x + distance * mt.cos(angle)
  15. y_1 = y + distance * mt.sin(angle)
  16.  
  17. end_pt = [x_1,y_1]
  18.  
  19. distance_check = mt.sqrt(((start_pt[0]-end_pt[0])**2)+((start_pt[1]-end_pt[1])**2) )
  20.  
  21. ## check
  22. print(start_pt)
  23. print(distance_check)
  24. print(end_pt)
  25. print(angle)
  26.  
  27. ## count how many lines you've crossed
  28.  
  29. def find_int_between(x,y):
  30. if y > x:
  31. return max(0,mt.ceil(y) - mt.floor(x)-1)
  32. else:
  33. return max(0, mt.ceil(x) - mt.floor(y)-1)
  34.  
  35. x_axis_cross = find_int_between(end_pt[0],(start_pt[0]))
  36. y_axis_cross = find_int_between(end_pt[1],(start_pt[1]))
  37.  
  38. ## number of lines crossed
  39. total_cross = abs(x_axis_cross) + abs(y_axis_cross)
  40.  
  41. ## check to visualize what you're doing
  42.  
  43. x = [start_pt[0],end_pt[0]]
  44. y = [start_pt[1],end_pt[1]]
  45. plt.plot(x, y)
  46. plt.grid(True)
  47. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement