Function:s2funuva
From S2PLOT
(Difference between revisions)
Revision as of 02:24, 29 August 2011
s2funuva
Plot a parametric function (generally a surface) defined by functions fx(u,v), fy(u,v) and fz(u,v) with transparency.
Prototype
void s2funuva(float(*fx)(float*, float*), float(*fy)(float*, float*), float(*fz)(float*, float*),
float(*fcol)(float*,float*),
char trans, float(*falpha)(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). Transparency is applied to the surface with falpha(u,v), defining the opacity in the range [0,1]. The range of u and v values are specified by umin,umax and vmin, vmax, and the number of divisions by uDIV and vDIV.
For a constant opacity, implement falpha(u,v){return const_value;}.
See Also
s2scir | Set the range of colour indices used for shading. |
s2funuv | Plot a parametric function. |
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);
}
inline float falpha(float *u, float *v) {
if ((*v) < pi) return 0.0;
else return 1.0;
}
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 */
char trans = 't'; /* Transparency type */
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 */
s2funuva(tkx, tky, tkz, fcol, trans, falpha, 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.