Gaetano Caruana gcaruana at gmail.com
Mon Apr 16 11:04:41 EDT 2007

```Hi all. I am new to this list ;) Today I have encountered something new that
has never happened to me in the past 6 months that I have been using ghci

I wrote this function:

type Line = (Point,Point)
type Point = (Float,Float)

circleLineIntersection :: Float -> Float -> Float -> Line -> Maybe [Point]
circleLineIntersection h k r ((x1,y1),(x2,y2)) = do
let
perpdist =
calcPerpDist (h,k) ((x1,y1),(x2,y2))
noSolution =
perpdist > r
oneSolution =
perpdist  == r
twoSolutions =
perpdist < r
in
do
if noSolution then
Nothing
else
let
dx = x2 -
x1
dy = y2 -
y1
dr = sqrt
(dx * dx + dy * dy)
bigD = x1
* y2 - x2 * y1
x1 = (
bigD * dy + sign (dy) * dx  * sqrt( r * r * dr * dr - bigD * bigD  ) ) / (dr
* dr)
y1 = -
bigD * dx + abs(dy) * sqrt( r * r * dr * dr - bigD * bigD  )  / (dr * dr)
x2 = (
bigD * dy - sign (dy) * dx  * sqrt( r * r * dr * dr - bigD * bigD  ) ) / (dr
* dr)
y2 = -
bigD * dx - abs(dy) * sqrt( r * r * dr * dr - bigD * bigD  )  / (dr * dr)

in
if oneSolution
then
do
Just
[(x1,y1)]
else
do
Just
[(x1,y1),(x2,y2)]

Compiling is fine...
When I run the function like this....

circleLineIntersection 1 1 1 ((1,1),(2,2))

it simply outputs....
Just [(

No CPU usage.
I am using fglasgow-exts