Last active
December 19, 2015 21:29
-
-
Save raichoo/6020369 to your computer and use it in GitHub Desktop.
Idris version of https://github.com/hrldcpr/Bezier.hs/blob/master/Bezier.hs
This file contains 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 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