1 {-
    2  -  Fulsom (The Solid Modeller, written in Haskell)
    3  -
    4  -  Copyright 1990,1991,1992,1993 Duncan Sinclair
    5  -
    6  - Permissiom to use, copy, modify, and distribute this software for any 
    7  - purpose and without fee is hereby granted, provided that the above
    8  - copyright notice and this permission notice appear in all copies, and
    9  - that my name not be used in advertising or publicity pertaining to this
   10  - software without specific, written prior permission.  I makes no
   11  - representations about the suitability of this software for any purpose.
   12  - It is provided ``as is'' without express or implied warranty.
   13  - 
   14  - Duncan Sinclair 1993.
   15  - 
   16  - Vector arithmetic routines.
   17  -
   18  -}
   19 
   20 module Vector where
   21 
   22 import Interval
   23 import Types
   24 
   25 makevector :: In -> In -> In -> In -> Vector
   26 makevector a' b' c' d' = (x,y,z)
   27   where
   28     a = unpt a' ; b = unpt b' ; c = unpt c' ; d = unpt d'
   29     x = b - a
   30     y = c - a
   31     z = d - a
   32 
   33 normalise :: Vector -> Vector
   34 normalise xyz@(x,y,z) = (x/l,y/l,z/l)
   35   where l = len xyz
   36 
   37 len :: Vector -> FType
   38 len (x,y,z) = ans
   39   where
   40     ans | sqs /= 0.0 = sqrt sqs
   41         | True       = 1
   42     sqs :: FType
   43     sqs = (x2 + y2 + z2)
   44     x2  = x * x
   45     y2  = y * y
   46     z2  = z * z
   47 
   48 light :: Color -> Vector -> Color
   49 light (RGB r g b) (x,y,z) = RGB (a*r) (a*g) (a*b)
   50     where a = (max ((0.5773*x + 0.5773*y + 0.5773*z) * (1-amb)) 0) + amb
   51 
   52 -- amb = (0.05 :: FType)
   53 amb = (0.50 :: FType)