Skip to content

Instantly share code, notes, and snippets.

@raichoo
Last active December 19, 2015 21:29
Show Gist options
  • Save raichoo/6020369 to your computer and use it in GitHub Desktop.
Save raichoo/6020369 to your computer and use it in GitHub Desktop.
module Bezier
Point : Type -> Nat -> Type
Point = Vect
-- parametric line between two points:
line : Num a => Point a d -> Point a d -> a -> Point a d
line p q t = zipWith interpolate p q
where interpolate a b = (1 - t)*a + t*b
-- bezier of just one point is fixed at that point,
-- and bezier of a list of points is just linear interpolation
-- between bezier of the initial part of the list
-- and bezier of the tail of the list:
bezier : Num a => Vect (Point a d) (S n) -> a -> Point a d
bezier (p :: Nil) t = p
bezier (p1 :: p2 :: ps) t =
let points = (p1 :: p2 :: ps) in
line (bezier (init points) t) (bezier (tail points) t) t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment