module Wumpus.Basic.Kernel.Geometry.Paths
(
rectanglePath
, diamondPath
, polygonPoints
, isoscelesTrianglePath
, isoscelesTrianglePoints
, equilateralTrianglePath
, equilateralTrianglePoints
)
where
import Wumpus.Core
import Data.AffineSpace
import Data.List ( unfoldr )
rectanglePath :: Num u => u -> u -> Point2 u -> PrimPath u
rectanglePath w h bl = primPath bl [ lineTo br, lineTo tr, lineTo tl ]
where
br = bl .+^ hvec w
tr = br .+^ vvec h
tl = bl .+^ vvec h
diamondPath :: Num u => u -> u -> Point2 u -> PrimPath u
diamondPath hw hh ctr = primPath s [ lineTo e, lineTo n, lineTo w]
where
s = ctr .+^ vvec (hh)
e = ctr .+^ hvec hw
n = ctr .+^ vvec hh
w = ctr .+^ hvec (hw)
polygonPoints :: Floating u => Int -> u -> Point2 u -> [Point2 u]
polygonPoints n radius ctr = unfoldr phi (0,(pi*0.5))
where
theta = (pi*2) / fromIntegral n
phi (i,ang) | i < n = Just (ctr .+^ avec ang radius, (i+1,ang+theta))
| otherwise = Nothing
isoscelesTrianglePoints :: Floating u
=> u -> u -> Point2 u -> (Point2 u, Point2 u, Point2 u)
isoscelesTrianglePoints bw h ctr = (bl, br, top)
where
hw = 0.5*bw
theta = atan $ h / hw
centroid_h = hw * tan (0.5*theta)
top = ctr .+^ vvec (h centroid_h)
br = ctr .+^ V2 hw (centroid_h)
bl = ctr .+^ V2 (hw) (centroid_h)
isoscelesTrianglePath :: Floating u => u -> u -> Point2 u -> PrimPath u
isoscelesTrianglePath bw h ctr = primPath bl [ lineTo br, lineTo top ]
where
hw = 0.5*bw
theta = atan $ h / hw
centroid_h = hw * tan (0.5*theta)
top = ctr .+^ vvec (h centroid_h)
br = ctr .+^ V2 hw (centroid_h)
bl = ctr .+^ V2 (hw) (centroid_h)
equilateralTrianglePoints :: Floating u
=> u -> Point2 u -> (Point2 u, Point2 u, Point2 u)
equilateralTrianglePoints sl = isoscelesTrianglePoints sl h
where
h = sl * sin (pi/3)
equilateralTrianglePath :: Floating u => u -> Point2 u -> PrimPath u
equilateralTrianglePath sl ctr = primPath bl [ lineTo br, lineTo top ]
where
(bl,br,top) = equilateralTrianglePoints sl ctr