Skip to content

Instantly share code, notes, and snippets.

@karatedog
Created November 12, 2013 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karatedog/7439845 to your computer and use it in GitHub Desktop.
Save karatedog/7439845 to your computer and use it in GitHub Desktop.
de Casteljau method for Bézier curve order decrease
# recursive 'de Casteljau' method. The method multiplies the array's elements in pairs (1st * 2nd, 2nd * 3rd, 3rd * 4th, etc.). Output array is one element less than input array.
# test_ary = [7, 17, 23, 47, 61]
def rec(ary)
if ary.length == 2 then
# base case
return [ ary[0] * ary[1] ]
else
# recursive case
return [ ary[0] * ary[1] ] + rec(ary[1..-1])
end
end
# p rec(test_ary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment