Created
September 23, 2014 06:45
-
-
Save dmbfm/0e8128432d995122dc80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Vector where | |
type Vec3 = (Float, Float, Float) | |
add : Vec3 -> Vec3 -> Vec3 | |
add (x,y,z) (u,v,w) = (x+u,y+v,z+w) | |
mul : Float -> Vec3 -> Vec3 | |
mul a (x,y,z) = (a*x,a*y,a*z) | |
sub : Vec3 -> Vec3 -> Vec3 | |
sub a b = add a (mul -1 b) | |
dot : Vec3 -> Vec3 -> Float | |
dot (x,y,z) (u,v,w) = x*u + y*v + z*w | |
abs : Vec3 -> Float | |
abs v = sqrt (dot v v) | |
unit : Vec3 -> Vec3 | |
unit v = mul (1/(abs v)) v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment