Parametric surface generation: execution time comparisons

The standard (Igor example) method of generating a parametric surface is to use explicit loops in order to clarify the method. Here are two alternate methods, evolved from the Example method, but without loops. Use is made of the Help description:
Quote:
When drawing parametric surfaces srcWave is a 3D wave where the first layer corresponds to the X-values, the second to the Y-values and the third to the Z-values of data points.
I also give comparative timings below. The speed of execution may be relevant in showing dynamic evolution of parametric functions in Gizmo displays, particularly with the better Gizmo integration in IP7. The examples shown all generate the same Mobius strip.
Function makeMobius(pointsx,pointsy,tmin,tmax) // Igor Example
    Variable pointsx,pointsy,tmin,tmax
   
    Variable i,j,s,arg,ds,tt,dt
    Make/O/n=(pointsx,pointsy,3) mobius
    ds=2*pi/(pointsx-1)
    dt=(tmax-tmin)/(pointsy-1)
   
    for(i=0;i<pointsx;i+=1)
        s=i*ds
        for(j=0;j<pointsy;j+=1)
            tt=tmin+j*dt
            arg=1+cos(s/2)*tt
            mobius[i][j][0]=cos(s)*arg
            mobius[i][j][1]=sin(s)*arg
            mobius[i][j][2]=tt*sin(s/2)
        endfor
    endfor
End

Function makeMobiusP(pointsx, pointsy)
    variable pointsx, pointsy
    // x(u,v) = (1 + (v/2)*cos(u/2) ) * cos(u)
    // y(u,v) = (1 + (v/2)*cos(u/2) ) * sin(u)
    // z(u,v) = (v/2) * sin(u/2)
    Make/O/FREE/N=(pointsx,pointsy)  wX, wY, wZ
    setscale/I x, 0,  2*pi,"", wX, wY, wZ    //  u
    setscale/I y, -1, 1,    "", wX, wY, wZ   // v
    wX =  (1+(y/2)*cos(x/2)) * cos(x)  // above tt -> y/2  (with pointsy)
    wY =  (1+(y/2)*cos(x/2)) * sin(x)
    wZ =  (y/2)*sin(x/2)
    Make/O/N=(pointsx, pointsy,21,3) wMobius
    Concatenate /O  {wX, wY, wZ}, wMobius
End

Function makeMobiusP2(pointsx, pointsy)
    variable pointsx, pointsy
   
    Make/O/N=(pointsx,pointsy,3)  wMobius
    setscale/I x, 0,  2*pi,"", wMobius   // u
    setscale/I y, -1, 1,    "", wMobius  //  v
    wMobius[][][0]  = (1+(y/2)*cos(x/2)) * cos(x)
    wMobius[][][1]  = (1+(y/2)*cos(x/2)) * sin(x)
    wMobius[][][2]  = (y/2)*sin(x/2)
End

The timing results (using 10,000 iterations per test) with 51 x-parameter and 53 y-parameter points are:
  Mobius:   2571.55  microseconds per iteration
  MobiusP:   924.64  microseconds per iteration
  MobiusP2:   745.831  microseconds per iteration

Your mileage may vary.

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More