diff options
author | Cristian Cadar <c.cadar@imperial.ac.uk> | 2015-04-09 17:38:19 +0100 |
---|---|---|
committer | Cristian Cadar <c.cadar@imperial.ac.uk> | 2015-04-09 17:38:19 +0100 |
commit | cac3cc670bf19a055286353d55db3317ccb2301c (patch) | |
tree | f9817d0e1f34d5ccf29a14e88c59dc10debd3949 /utils/hacks/TreeGraphs/Graphics/Geometry/Intersect2D.py | |
parent | 185e2f9d3ad23e9926373979c3dd8dc362ad6857 (diff) | |
download | klee-cac3cc670bf19a055286353d55db3317ccb2301c.tar.gz |
Normalised line endings
Diffstat (limited to 'utils/hacks/TreeGraphs/Graphics/Geometry/Intersect2D.py')
-rw-r--r-- | utils/hacks/TreeGraphs/Graphics/Geometry/Intersect2D.py | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/utils/hacks/TreeGraphs/Graphics/Geometry/Intersect2D.py b/utils/hacks/TreeGraphs/Graphics/Geometry/Intersect2D.py index a600a64f..d310c20a 100644 --- a/utils/hacks/TreeGraphs/Graphics/Geometry/Intersect2D.py +++ b/utils/hacks/TreeGraphs/Graphics/Geometry/Intersect2D.py @@ -1,59 +1,59 @@ -import vec2, math - -def intersectLineCircle((p, no), (C, r)): - x = vec2.sub(p,C) - b = 2.*vec2.dot(no, x) - c = vec2.sqr(x) - r*r - dist = b*b - 4*c - - if dist<0: - return None - else: - d = math.sqrt(dist) - t0 = (-b - d)*.5 - t1 = (-b + d)*.5 - return (t0,t1) - -#def intersectLineCircle((lineP,lineN),(circleP,circleR)): -# dx,dy = vec2.sub(lineP,circleP) -# nx,ny = lineN -# -# a = (nx*nx + ny*ny) -# b = 2*(dx*nx + dy*ny) -# c = (dx*dx + dy*dy) - circleR*circleR -# -# k = b*b - 4*a*c -# if k<0: -# return None -# else: -# d = math.sqrt(k) -# t1 = (-b - d)/2*a -# t0 = (-b + d)/2*a -# return t0,t1 - -def intersectCircleCircle(c0P, c0R, c1P, c1R): - v = vec2.sub(c1P, c0P) - d = vec2.length(v) - - R = c0R - r = c1R - - try: - x = (d*d - r*r + R*R)/(2*d) - except ZeroDivisionError: - if R<r: - return 'inside',() - elif r>R: - return 'outside',() - else: - return 'coincident',() - - k = R*R - x*x - if k<0: - if x<0: - return 'inside',() - else: - return 'outside',() - else: - y = math.sqrt(k) - return 'intersect',(vec2.toangle(v),vec2.toangle((x,y))) +import vec2, math + +def intersectLineCircle((p, no), (C, r)): + x = vec2.sub(p,C) + b = 2.*vec2.dot(no, x) + c = vec2.sqr(x) - r*r + dist = b*b - 4*c + + if dist<0: + return None + else: + d = math.sqrt(dist) + t0 = (-b - d)*.5 + t1 = (-b + d)*.5 + return (t0,t1) + +#def intersectLineCircle((lineP,lineN),(circleP,circleR)): +# dx,dy = vec2.sub(lineP,circleP) +# nx,ny = lineN +# +# a = (nx*nx + ny*ny) +# b = 2*(dx*nx + dy*ny) +# c = (dx*dx + dy*dy) - circleR*circleR +# +# k = b*b - 4*a*c +# if k<0: +# return None +# else: +# d = math.sqrt(k) +# t1 = (-b - d)/2*a +# t0 = (-b + d)/2*a +# return t0,t1 + +def intersectCircleCircle(c0P, c0R, c1P, c1R): + v = vec2.sub(c1P, c0P) + d = vec2.length(v) + + R = c0R + r = c1R + + try: + x = (d*d - r*r + R*R)/(2*d) + except ZeroDivisionError: + if R<r: + return 'inside',() + elif r>R: + return 'outside',() + else: + return 'coincident',() + + k = R*R - x*x + if k<0: + if x<0: + return 'inside',() + else: + return 'outside',() + else: + y = math.sqrt(k) + return 'intersect',(vec2.toangle(v),vec2.toangle((x,y))) |