The MASM Forum

General => The Workshop => Topic started by: Biterider on October 03, 2015, 12:43:34 AM

Title: Cublic spline interpolation
Post by: Biterider on October 03, 2015, 12:43:34 AM
Hi
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
Title: Re: Cublic spline interpolation
Post by: jj2007 on October 03, 2015, 01:32:53 AM
SetPoly3 (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1124) 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)
Title: Re: Cublic spline interpolation
Post by: guga 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.
Title: Re: Cublic spline interpolation
Post by: jj2007 on July 24, 2016, 02:38:28 AM
Quote from: guga on July 23, 2016, 10:00:41 PMDo you have it n plain masm ?

SetPoly and GetPoly in \Masm32\MasmBasic\MasmBasic.inc are plain Masm, no call to the lib involved.
Title: Re: Cublic spline interpolation
Post by: FORTRANS on July 25, 2016, 11:53:34 PM
Hi,

   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?

Regards,

Steve N.