module Geometry.Circle where
import Geometry
data Circle a = Circle
{ forall a. Circle a -> Point a
centerC :: !(Point a)
, forall a. Circle a -> a
radiusC :: !a
}
deriving (Circle a -> Circle a -> Bool
(Circle a -> Circle a -> Bool)
-> (Circle a -> Circle a -> Bool) -> Eq (Circle a)
forall a. Eq a => Circle a -> Circle a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Circle a -> Circle a -> Bool
== :: Circle a -> Circle a -> Bool
$c/= :: forall a. Eq a => Circle a -> Circle a -> Bool
/= :: Circle a -> Circle a -> Bool
Eq, Int -> Circle a -> ShowS
[Circle a] -> ShowS
Circle a -> String
(Int -> Circle a -> ShowS)
-> (Circle a -> String) -> ([Circle a] -> ShowS) -> Show (Circle a)
forall a. Show a => Int -> Circle a -> ShowS
forall a. Show a => [Circle a] -> ShowS
forall a. Show a => Circle a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Circle a -> ShowS
showsPrec :: Int -> Circle a -> ShowS
$cshow :: forall a. Show a => Circle a -> String
show :: Circle a -> String
$cshowList :: forall a. Show a => [Circle a] -> ShowS
showList :: [Circle a] -> ShowS
Show)
inCircle :: (Num a, Ord a) => Point a -> Circle a -> Bool
inCircle :: forall a. (Num a, Ord a) => Point a -> Circle a -> Bool
inCircle (P a
x0 a
y0) (Circle (P a
x a
y) a
r) = a
dx a -> a -> a
forall a. Num a => a -> a -> a
* a
dx a -> a -> a
forall a. Num a => a -> a -> a
+ a
dy a -> a -> a
forall a. Num a => a -> a -> a
* a
dy a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
r a -> a -> a
forall a. Num a => a -> a -> a
* a
r
where
!dx :: a
dx = a
x a -> a -> a
forall a. Num a => a -> a -> a
- a
x0
!dy :: a
dy = a
y a -> a -> a
forall a. Num a => a -> a -> a
- a
y0
triangleCenter ::
(Fractional a) =>
a ->
a ->
a ->
Point a ->
Point a ->
Point a ->
Point a
triangleCenter :: forall a.
Fractional a =>
a -> a -> a -> Point a -> Point a -> Point a -> Point a
triangleCenter a
wa a
wb a
wc Point a
a Point a
b Point a
c =
(a -> a) -> Point a -> Point a
forall a b. (a -> b) -> Point a -> Point b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
(a -> a
forall a. Fractional a => a -> a
recip (a
wa a -> a -> a
forall a. Num a => a -> a -> a
+ a
wb a -> a -> a
forall a. Num a => a -> a -> a
+ a
wc) *)
((a -> a) -> Point a -> Point a
forall a b. (a -> b) -> Point a -> Point b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
wa *) Point a
a Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
+ (a -> a) -> Point a -> Point a
forall a b. (a -> b) -> Point a -> Point b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
wb *) Point a
b Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
+ (a -> a) -> Point a -> Point a
forall a b. (a -> b) -> Point a -> Point b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
wc *) Point a
c)
incenter ::
(Floating a) =>
Point a ->
Point a ->
Point a ->
Point a
incenter :: forall a. Floating a => Point a -> Point a -> Point a -> Point a
incenter Point a
a Point a
b Point a
c =
a -> a -> a -> Point a -> Point a -> Point a -> Point a
forall a.
Fractional a =>
a -> a -> a -> Point a -> Point a -> Point a -> Point a
triangleCenter a
aa a
bb a
cc Point a
a Point a
b Point a
c
where
cc :: a
cc = Point a -> a
forall a. Floating a => Point a -> a
norm (Point a
a Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
- Point a
b)
aa :: a
aa = Point a -> a
forall a. Floating a => Point a -> a
norm (Point a
b Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
- Point a
c)
bb :: a
bb = Point a -> a
forall a. Floating a => Point a -> a
norm (Point a
c Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
- Point a
a)
centroid :: (Fractional a) => Point a -> Point a -> Point a -> Point a
centroid :: forall a. Fractional a => Point a -> Point a -> Point a -> Point a
centroid Point a
a Point a
b Point a
c = (a -> a) -> Point a -> Point a
forall a b. (a -> b) -> Point a -> Point b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> a
forall a. Fractional a => a -> a
recip a
3.0 *) (Point a
a Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
+ Point a
b Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
+ Point a
c)
circumcenter :: (Fractional a) => Point a -> Point a -> Point a -> Point a
circumcenter :: forall a. Fractional a => Point a -> Point a -> Point a -> Point a
circumcenter Point a
a Point a
b Point a
c =
a -> a -> a -> Point a -> Point a -> Point a -> Point a
forall a.
Fractional a =>
a -> a -> a -> Point a -> Point a -> Point a -> Point a
triangleCenter
(a
aa a -> a -> a
forall a. Num a => a -> a -> a
* (a
bb a -> a -> a
forall a. Num a => a -> a -> a
+ a
cc a -> a -> a
forall a. Num a => a -> a -> a
- a
aa))
(a
bb a -> a -> a
forall a. Num a => a -> a -> a
* (a
cc a -> a -> a
forall a. Num a => a -> a -> a
+ a
aa a -> a -> a
forall a. Num a => a -> a -> a
- a
bb))
(a
cc a -> a -> a
forall a. Num a => a -> a -> a
* (a
aa a -> a -> a
forall a. Num a => a -> a -> a
+ a
bb a -> a -> a
forall a. Num a => a -> a -> a
- a
cc))
Point a
a
Point a
b
Point a
c
where
aa :: a
aa = Point a -> a
forall a. Num a => Point a -> a
sqrNorm (Point a
b Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
- Point a
c)
bb :: a
bb = Point a -> a
forall a. Num a => Point a -> a
sqrNorm (Point a
c Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
- Point a
a)
cc :: a
cc = Point a -> a
forall a. Num a => Point a -> a
sqrNorm (Point a
a Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
- Point a
b)
orthocenter :: (Num a) => Point a -> Point a -> Point a -> Point a
orthocenter :: forall a. Num a => Point a -> Point a -> Point a -> Point a
orthocenter Point a
a Point a
b Point a
c = Point a
a Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
+ Point a
b Point a -> Point a -> Point a
forall a. Num a => a -> a -> a
+ Point a
c