Guest User

Untitled

a guest
May 3rd, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. instance AdditiveGroup GLfloat     where {zeroV=0.0; (^+^) = (+); negateV = negate}
  2. instance VectorSpace GLfloat where
  3.   type Scalar GLfloat = GLfloat
  4.   (*^) = (*)
  5. instance InnerSpace  GLfloat where (<.>) = (*)
  6.                        
  7. -- Data.VectorSpace it completly braindead, because it defines a scalar
  8. -- as anything, not as a Field, so that it is not possible the get the
  9. -- additive identity, so we can't define this on any InnerSpace
  10. force a b =
  11.         if d == zeroV then
  12.                 zeroV
  13.         else
  14.                 d ^* factor
  15.         where d = a ^-^ b
  16.               distSq = magnitudeSq d
  17.               -- 1/(r^4) works fine
  18.               -- with usual 1/(r^2) als points
  19.               -- on the border
  20.               factor = 1/(distSq*distSq)
  21.  
  22. -- Our point has to be in the unit circle
  23. limited p
  24.         | d > 1     = p^/d
  25.         | otherwise = p
  26.         where d = magnitude p
  27.              
  28. allForces p points = sumV $ map (force p) points
  29.  
  30. applyForce p points t = limited $ p ^+^ t *^ (allForces p points)
  31.  
  32. transformSystem t points = map (\p  -> applyForce p points t) points
Advertisement
Add Comment
Please, Sign In to add comment