1

I guess only 1 stack wouldn't be enough, because the following logic doesn't look very viable to me:

enter image description here

De-Casteljau's-algorithm

plasmacel
  • 8,183
  • 7
  • 53
  • 101
user366312
  • 16,949
  • 65
  • 235
  • 452
  • From the picture, it does look like De Casteljau algorithm. For example, V01, V12, V23 are computed sequentially and replace the 4 original points in the stack. Having said this, I still don't quite get what a "stack" exactly is though. – fang Aug 12 '15 at 18:20

1 Answers1

3

Everything can be done with a stack.

De Casteljau's algorithm is an iterative algorithm that replaces:

{a,b,c,d,...,z}

with:

{a'=lerp(a,b), b'=lerp(b,c), c'=lerp(c,d), ..., y'=lerp(y,z)}

and runs that reduction until there is only one value left.

Using a stack, we take the two bottom stack elements, lerp them (based on some ratio value), and then overwrite the bottom element with the resulting value. We move up one spot, and repeat, move and repeat, move and repeat, until we reach the top of the stack. Then we discard the topmost element. To find the final point, we run that algorithm until the stack is size 1.

So, in pseudo-code:

reduceOnce(stack, ratio):
  n = stack.length
  for(i = 0 to n-1):
    stack[i] = (1-ratio) * stack[i] + ratio * stack[i+1]
  stack.pop()

stackReduce(stack, ratio):
  while(stack size > 1):
    reduceOnce(stack, ratio)

And done: one stack needed.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
  • Why do you link the Wikipedia article of Universal Turing Machine? The reference is too broad this way. – plasmacel Jun 08 '17 at 23:03
  • No, the reference is exactly what is necessary to underline the statement that if you have a stack, you can implement anything you could ever do on a computer, because a stack lets you implement a universal Turing machine. – Mike 'Pomax' Kamermans Jun 09 '17 at 00:17