module Numeric.Geometric.Predicates.Rational where
import Numeric.Geometric.Primitives
ccw ∷ Vector2 Rational → Vector2 Rational → Vector2 Rational
→ Ordering
ccw (x1,y1) (x2,y2) (x3,y3) = compare result 0
where
result = (x1*y2) + (x2*y3) + (x3*y1) (x1*y3) (x2*y1) (x3*y2)
incircle ∷ (Vector2 Rational, Vector2 Rational, Vector2 Rational)
→ Vector2 Rational
→ Ordering
incircle (p1,p2,p3) p4 = compare result 0
where
result = (d p1) * (ccw' p2 p3 p4)
(d p2) * (ccw' p1 p3 p4)
+ (d p3) * (ccw' p1 p2 p4)
(d p4) * (ccw' p1 p2 p3)
d (x,y) = (x*x) + (y*y)
ccw' (x1,y1) (x2,y2) (x3,y3) = (x1*y2) + (x2*y3) + (x3*y1) (x1*y3) (x2*y1) (x3*y2)
cintt ∷ Rational
→ Rational
→ Rational
→ Bool
cintt x1 x2 p | x1 == x2 = p == x1
| otherwise = t >= 0 && t <= 1
where
t = (u p) / (v)
u = x1
v = x2 x1
isctp ∷ LineSegment (Vector2 Rational) → LineSegment (Vector2 Rational) → Vector2 Rational
isctp ((ax,ay),(bx,by)) ((cx,cy),(dx,dy)) = (x,y)
where
rtop = (aycy)*(dxcx)(axcx)*(dycy)
rbot = (bxax)*(dycy)(byay)*(dxcx)
r = rtop/rbot
x = ax + r * (bx ax)
y = ay + r * (by ay)