Author Topic: Cublic spline interpolation  (Read 1614 times)


  • Member
  • **
  • Posts: 207
  • ObjAsm32 - ObjAsm64
    • ObjAsm64
Cublic spline interpolation
« on: October 03, 2015, 12:43:34 AM »
I'm wondering if someone has coded in plain masm a cspline to interplate between an array of (x;y) reals.
I know that there are some examples in the net, but if somebody just did the work, it would save me to do and test it again...

Thanks, Biterider


  • Member
  • *****
  • Posts: 8522
  • Assembler is fun ;-)
    • MasmBasic
Re: Cublic spline interpolation
« Reply #1 on: October 03, 2015, 01:32:53 AM »
SetPoly3 is almost plain Masm (examples attached):
SetPoly3, GetPoly3
      Dim My3Pts(5) As DWORD            ; create an array with 3 XY pairs, i.e. 6 elements (0 .. 5)
      ArraySet My3Pts() = 1, 100, 2, 300, 4, 150      ; assign XY values (ArraySet can be handy but any other array works, too)
      SetPoly3 My3Pts()            ; create coefficients for a 3-point polynomial, i.e. Y=a0+a1*X+a2*X2
      Dim AllPts(11) As REAL4            ; create a destination array with 12 elements
      Print "N", Tb$, "X", Tb$, "Y", Tb$, "Y(ecx)"      ; the last column uses the "direct" variant GetPoly3(X)
      GetPoly3(AllPts())            ; fill starting from X=0, create coefficients for Y=a0+a1*X+a2*X2
      add eax, eax
      push eax
      xor ecx, ecx
      .Repeat            ; print N, X, Y=f(x), Y=f(2*X)
            Print Str$("\n%i\t", ecx/2), Str$("%2f\t", AllPts(ecx)), Str$("%3f\t", AllPts(ecx+1)), Str$("%3f", GetPoly3(ecx))
            fstp st            ; pop the return value from the FPU
            add ecx, 2
      .Until ecx>=stack
      pop eax
Rem      - GetPoly3() returns #XY pairs in eax
      - GetPoly3(array()) sets the whole destination array
      - GetPoly3(X) returns a single value in ST(0)


  • Member
  • ****
  • Posts: 847
  • Assembly is a state of art.
    • RosAsm
Re: Cublic spline interpolation
« Reply #2 on: July 23, 2016, 10:00:41 PM »
Excelent work JJ.

Do you have it n plain masm ? I´m trying to make a closed spline to use as a mask  for bitmap editing. Currently, i´m trying to port  VirtualDub filter and will intend to use a spline to create a mask.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:


  • Member
  • *****
  • Posts: 8522
  • Assembler is fun ;-)
    • MasmBasic
Re: Cublic spline interpolation
« Reply #3 on: July 24, 2016, 02:38:28 AM »
Do you have it n plain masm ?

SetPoly and GetPoly in \Masm32\MasmBasic\ are plain Masm, no call to the lib involved.


  • Member
  • *****
  • Posts: 1010
Re: Cublic spline interpolation
« Reply #4 on: July 25, 2016, 11:53:34 PM »

   A while back, I wrote a Bezier spline routine for a draw program
to add curved lines.  Inputs are screen coordinates, so are integers.
And the code is 16-bit.  But I wrote four versions to get it accurate,
working, and debugged.  The third did the math using the FPU, to
try and get the accurate results.  Fairly crude and rude but it did work.

   Of any interest?


Steve N.