Skip to content

Instantly share code, notes, and snippets.

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