code_junkie

Is this a reasonable implementation of the quadratic B?zier function in OCaml?

Nov 11th, 2011
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. let rec b2 n =
  2. let p1 = -10. in
  3. let p2 = 10. in
  4. let q = n*.n in
  5. let rec b2i n i hd =
  6. if i > n then
  7. List.rev hd
  8. else
  9. let t = i /. n in
  10. b2i n (i+.1.) ((((1.-.t)**2.)*.p1+.(2.*.t*.(1.-.t)*.q)+.(t**2.)*.p2) :: hd)
  11. in b2i n 0. []
  12. ;;
  13. let floatprint lst = List.iter (fun f -> Printf.printf "%f; " f) lst ;;
  14. floatprint (b2 8.);;
  15.  
  16. let b i =
  17. let t = i /. n in
  18. let tminus = (1.-.t) in
  19. (tminus *. tminus *. p0) +. (2. *. t *. tminus *. p1) +. (t *. t * p2)
  20. in
  21. List.map b ([generate list 1.0; 2.0; ... n.0])
  22.  
  23. let rec count m n = if m > n then [] else m :: (count (m+.1.) n)
Add Comment
Please, Sign In to add comment