1 module EdgePlate(Edge,edgeT,edgeH, s,h,t, Plate(Plt),n,
    2                 Input,Object,makeObject) where
    3 import Numbers
    4 import Vectors
    5 {- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    6 -- section 3: Lines and edges
    7 
    8 An edge and a line are defined by
    9 - a support vector (s) and a termination vector (t) differing from s   or
   10 - a support vector (s) and a non-zero heading vector (h)
   11 Below we have chosen for the latter.
   12 -}
   13 
   14 data Edge = Edg Vector Vector
   15 
   16 edgeT, edgeH :: Vector -> Vector -> Edge
   17 edgeH v w = Edg v w
   18 edgeT v w = Edg v (w-v)
   19 
   20 s,h,t :: Edge -> Vector
   21 s (Edg v w)   = v
   22 h (Edg v w)   = w
   23 t (Edg v w)   = v+w
   24 
   25 type Input = [[Vector]]
   26 
   27 {- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   28 -- section 3: Planes and plates
   29 
   30 A plate is a sequence of edges $e_{0},\ldots,e_{n-1}$ such that
   31 - t(e_{i}) == s(e_{i+1}) && not (e_{i} ||| e_{i+1}) for 0<=i<=n-2
   32 - t(e_{n-1}) == s(e_{0}) && not (e_{n-1} ||| e_{0})
   33 (|||) means `is parralel to`, see Geometric.hs
   34 
   35 -}
   36 
   37 data Plate = Plt Int [Edge]
   38 
   39 n :: Plate -> Vector
   40 n(Plt _ (l1:l2:ls)) = norm( h(l1) * h(l2) )
   41 
   42 type Object = [Plate]
   43 
   44 -- `makeObject' transforms the input data to a proper object
   45 makeObject :: Input -> Object
   46 makeObject = zipWith borders [1..]
   47              where borders :: Int -> [Vector] -> Plate
   48                    borders n ps = Plt n (zipWith edgeT ps (ror 1 ps))
   49 
   50 -- rotate right
   51 ror :: Int -> [a] -> [a]
   52 ror n xs =
   53         reverse (take n rvxs) ++ reverse (drop n rvxs)
   54         where rvxs = reverse xs