Created
September 23, 2014 05:47
-
-
Save dmbfm/9bbce1815cd3927c5a99 to your computer and use it in GitHub Desktop.
Vector
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