Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- intersctionX1 = 0
- intersctionY1 = 0
- intersctionX2 = 0
- intersctionY2 = 0
- distance = 0
- cx = 150 #position x of the circle
- cy = 0 #position y of the circle
- radius = 25 #radius of the circle
- def circleLineIntersection(x1,y1,x2,y2): #Segment position x1,y1,x2,y2
- global intersctionX1
- global intersctionY1
- global intersctionX2
- global intersctionY2
- global cx
- global cy
- global radius
- dx = x2 - x1
- dy = y2 - y1
- a = dx * dx + dy * dy
- b = 2 * (dx * (x1 - cx) + dy * (y1 - cy))
- c = (x1 - cx) * (x1 - cx) + (y1 - cy) * (y1 - cy) - radius * radius
- det = b * b - 4 * a * c
- if a <= 0.0000001 or det < 0:
- # No solutions.
- print "No solutions"
- elif det == 0:
- # One solution.
- t = -b / (2 * a)
- intersctionX1 = x1 + t * dx
- intersctionY1 = y1 + t * dy
- print "One solutions"
- print str(intersctionX1) + " ; " + str(intersctionY1)
- else:
- # Two solutions.
- t = ((-b - math.sqrt(det)) / (2 * a))
- intersctionX1 = x1 + t * dx
- intersctionY1 = y1 + t * dy
- t = ((-b + math.sqrt(det)) / (2 * a))
- intersctionX2 = x1 + t * dx
- intersctionY2 = y1 + t * dy
- print "Two solutions"
- print str(intersctionX1) + " ; " + str(intersctionY1)
- print str(intersctionX2) + " ; " + str(intersctionY2)
- def distanceBTWTwoPoints(x1,y1,x2,y2):
- global distance
- distance = math.sqrt(((x2-x1)**2) + ((y2-y1)**2))
- print "Distance " + str(distance)
- def getAngle():
- global radius
- cb = distance
- h = math.sqrt(pow(radius, 2) - pow(cb / 2, 2))
- alpha = math.asin(h / radius)
- beta = math.pi - (2 * alpha)
- total = math.degrees(beta)
- print "angle a " + str(total)
- circleLineIntersection(163,46,163,31) #pos x1,y1 and pos x2,y2 of the line
- distanceBTWTwoPoints(cx,radius,intersctionX1,intersctionY1) # pos x and y of
- the second point
- getAngle()
Add Comment
Please, Sign In to add comment