Function:s2funuv

From S2PLOT

(Difference between revisions)
Jump to: navigation, search

Revision as of 01:54, 28 October 2007

s2funuv

Plot a parametric function (generally a surface) defined by functions fx(u,v), fy(u,v) and fz(u,v).

Prototype

void s2funuv(float(*fx)(float*, float*), float(*fy)(float*, float*), float(*fz)(float*, float*), 
float(*fcol)(float*,float*),float umin, float umax, int uDIV, float vmin, float vmax, int vDIV);

Description

Plot the parametric function (generally a surface) defined by { (fx(u,v), fy(u,v), fz(u,v) }, coloured by fcol(u,v) with fcol required to fall in the range [0,1]. fcol is then mapped to the current colormap index range (set with s2scir). The range of u and v values are specified by umin,umax and vmin, vmax, and the number of divisions by uDIV and vDIV.

See Also

s2scir Set the range of colour indices used for shading.


Code Example

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "s2plot.h"

#define LIMIT 0.7
#define pi 3.14159265359

/* amplitude, number of twists, major radius, minor radius */
#define AMP 0.4         /* Amplitude */
#define NTW 1.5         /* Number of twists */
#define R1 2.0          /* Major radius */
#define R2 0.5          /* Minor radius */


/* Parametric functions for surface */
inline float tkx(float *u, float *v) {
  return R2 * cos(*v) * cos(*u) + R1 * cos(*u) * (1. + AMP * cos(*u * NTW));
}
inline float tky(float *u, float *v) {
  return R2 * sin(*v) + AMP * sin(*u * NTW);
}
inline float tkz(float *u, float *v) {
  return R2 * cos(*v) * sin(*u) + R1 * sin(*u) * (1. + AMP * cos(*u * NTW));
}
inline float fcol(float *u, float *v) {
  return 0.5 + sin(0.5 * *u) * AMP * sin(*v);
}

int main(int argc, char *argv[])
{

   float x1 = -LIMIT, x2 = LIMIT;               /* x world coord range */
   float y1 = -LIMIT, y2 = LIMIT;               /* y world coord range */
   float z1 = -LIMIT, z2 = LIMIT;               /* z world coord range */

   s2opend("/?",argc, argv);                    /* Open the display */
   s2swin(x1, x2, y1, y2, z1, z2);              /* Set the window coordinates */

   s2icm("rainbow", 100, 500);                  /* Install colour map */
   s2scir(100, 500);                            /* Set colour range */

   s2funuv(tkx, tky, tkz, fcol, 0., 4.*pi, 320, 0., 2.*pi, 90);
                                /* call the parametric surface function */

   s2show(1);                                   /* Open the s2plot window */

   return 1;

}



Back to S2PLOT function list.


Personal tools