Guest User

Untitled

a guest
Nov 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import math
  2. intersctionX1 = 0
  3. intersctionY1 = 0
  4. intersctionX2 = 0
  5. intersctionY2 = 0
  6. distance = 0
  7. cx = 150 #position x of the circle
  8. cy = 0 #position y of the circle
  9. radius = 25 #radius of the circle
  10.  
  11. def circleLineIntersection(x1,y1,x2,y2): #Segment position x1,y1,x2,y2
  12. global intersctionX1
  13. global intersctionY1
  14. global intersctionX2
  15. global intersctionY2
  16. global cx
  17. global cy
  18. global radius
  19. dx = x2 - x1
  20. dy = y2 - y1
  21. a = dx * dx + dy * dy
  22. b = 2 * (dx * (x1 - cx) + dy * (y1 - cy))
  23. c = (x1 - cx) * (x1 - cx) + (y1 - cy) * (y1 - cy) - radius * radius
  24.  
  25. det = b * b - 4 * a * c
  26.  
  27. if a <= 0.0000001 or det < 0:
  28. # No solutions.
  29. print "No solutions"
  30. elif det == 0:
  31. # One solution.
  32. t = -b / (2 * a)
  33. intersctionX1 = x1 + t * dx
  34. intersctionY1 = y1 + t * dy
  35. print "One solutions"
  36. print str(intersctionX1) + " ; " + str(intersctionY1)
  37. else:
  38. # Two solutions.
  39. t = ((-b - math.sqrt(det)) / (2 * a))
  40. intersctionX1 = x1 + t * dx
  41. intersctionY1 = y1 + t * dy
  42. t = ((-b + math.sqrt(det)) / (2 * a))
  43. intersctionX2 = x1 + t * dx
  44. intersctionY2 = y1 + t * dy
  45. print "Two solutions"
  46. print str(intersctionX1) + " ; " + str(intersctionY1)
  47. print str(intersctionX2) + " ; " + str(intersctionY2)
  48.  
  49. def distanceBTWTwoPoints(x1,y1,x2,y2):
  50. global distance
  51. distance = math.sqrt(((x2-x1)**2) + ((y2-y1)**2))
  52. print "Distance " + str(distance)
  53.  
  54. def getAngle():
  55. global radius
  56. cb = distance
  57. h = math.sqrt(pow(radius, 2) - pow(cb / 2, 2))
  58. alpha = math.asin(h / radius)
  59. beta = math.pi - (2 * alpha)
  60. total = math.degrees(beta)
  61.  
  62. print "angle a " + str(total)
  63.  
  64.  
  65. circleLineIntersection(163,46,163,31) #pos x1,y1 and pos x2,y2 of the line
  66. distanceBTWTwoPoints(cx,radius,intersctionX1,intersctionY1) # pos x and y of
  67. the second point
  68. getAngle()
Add Comment
Please, Sign In to add comment