Created
November 12, 2013 22:20
-
-
Save karatedog/7439845 to your computer and use it in GitHub Desktop.
de Casteljau method for Bézier curve order decrease
This file contains hidden or 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
# 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