Function:s2vect3
From S2PLOT
(Difference between revisions)
Revision as of 08:44, 27 October 2007 S2plot admin (Talk | contribs) ← Previous diff |
Current revision S2plot admin (Talk | contribs) |
||
Line 6: | Line 6: | ||
<code><pre> | <code><pre> | ||
- | void s2vect3(float ***a, float ***b, float ***c, int adim, int bdim, int cdim, int a1, int a2, int b1, int b2, int c1, int c2, float scale, int nc, float *tr, float minlength, int colbylength, float minl, float maxl); | + | void s2vect3(float ***a, float ***b, float ***c, int adim, int bdim, int cdim, int a1, int a2, int b1, int b2, int c1, int c2, |
+ | float scale, int nc, float *tr, float minlength, int colbylength, float minl, float maxl); | ||
</pre></code> | </pre></code> | ||
Line 17: | Line 18: | ||
* nc controls positioning of the vectors. nc<0 places the head of the vector on the coordinates; nc>0 places the vector base on the coords, and nc == 0 centres the vector on the coords. | * nc controls positioning of the vectors. nc<0 places the head of the vector on the coordinates; nc>0 places the vector base on the coords, and nc == 0 centres the vector on the coords. | ||
* tr is the transformation matrix which maps indexes into the arrays onto the x, y and z axes of the 3D space. NOTE: this transformation IS NOT APPLIED to the vector components!!! The standard (non-rotated, non-skewed) transformation would have tr[2], tr[3], tr[5], tr[7], tr[9]and tr[10] all zero. | * tr is the transformation matrix which maps indexes into the arrays onto the x, y and z axes of the 3D space. NOTE: this transformation IS NOT APPLIED to the vector components!!! The standard (non-rotated, non-skewed) transformation would have tr[2], tr[3], tr[5], tr[7], tr[9]and tr[10] all zero. | ||
- | + | ** x = tr[0] + tr[1] * ia + tr[2] * ib + tr[3] * ic | |
- | x = tr[0] + tr[1] * ia + tr[2] * ib + tr[3] * ic | + | ** y = tr[4] + tr[5] * ia + tr[6] * ib + tr[7] * ic |
- | + | ** z = tr[8] + tr[9] * ia + tr[10]* ib + tr[11]* ic | |
- | y = tr[4] + tr[5] * ia + tr[6] * ib + tr[7] * ic | + | |
- | + | ||
- | z = tr[8] + tr[9] * ia + tr[10]* ib + tr[11]* ic | + | |
- | + | ||
* Vectors with length (sqrt(a[...]^2 + b[...]^2 + c[...]^2)) less than minlength are not drawn. | * Vectors with length (sqrt(a[...]^2 + b[...]^2 + c[...]^2)) less than minlength are not drawn. | ||
* If colbylength > 0, the the vectors will be coloured by mapping those of length minl or smaller to the start of the current colour index range, and those of length maxl or greater to the end of the current colour index range. | * If colbylength > 0, the the vectors will be coloured by mapping those of length minl or smaller to the start of the current colour index range, and those of length maxl or greater to the end of the current colour index range. | ||
Line 41: | Line 38: | ||
#include <stdlib.h> | #include <stdlib.h> | ||
#include <math.h> | #include <math.h> | ||
+ | #include <time.h> | ||
#include "s2plot.h" | #include "s2plot.h" | ||
- | #define NX 10 /* Dimensions of arrays */ | + | #define NX 10 /* Dimensions of arrays */ |
#define NY 10 | #define NY 10 | ||
#define NZ 10 | #define NZ 10 | ||
Line 52: | Line 50: | ||
int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||
{ | { | ||
- | float ***a, ***b, ***c; /* Components of vectors */ | + | float ***a, ***b, ***c; /* Components of vectors */ |
- | int i, j, k; /* Loop variables */ | + | int i, j, k; /* Loop variables */ |
- | float x1 = -XLIMIT, x2 = +XLIMIT, /* Range of plottable values */ | + | float x1 = -XLIMIT, x2 = +XLIMIT, /* Range of plottable values */ |
y1 = -YLIMIT, y2 = +YLIMIT, | y1 = -YLIMIT, y2 = +YLIMIT, | ||
z1 = -ZLIMIT, z2 = +ZLIMIT; | z1 = -ZLIMIT, z2 = +ZLIMIT; | ||
- | float minlength = +9E30; /* Min and max vector lengths */ | + | float minlength = +9E30; /* Min and max vector lengths */ |
float maxlength = -9E30; | float maxlength = -9E30; | ||
- | float tr[12]; /* Transformation matrix */ | + | float tr[12]; /* Transformation matrix */ |
- | float mindraw, scale; /* See below */ | + | float mindraw, scale; /* See below */ |
- | int colbylength, nc; /* See below */ | + | int colbylength, nc; /* See below */ |
- | float length; /* Length of a vector */ | + | float length; /* Length of a vector */ |
+ | |||
+ | srand48((long)time(NULL)); /* Seed random numbers */ | ||
+ | s2opend("/?",argc, argv); /* Open the display */ | ||
+ | s2swin(x1,x2, y1,y2, z1,z2); /* Set the window coordinates */ | ||
+ | s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */ | ||
- | s2opend("/?",argc, argv); /* Open the display */ | ||
- | s2swin(x1,x2, y1,y2, z1,z2); /* Set the window coordinates */ | ||
- | s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */ | ||
- | |||
a = (float ***)calloc(NX, sizeof(float **)); | a = (float ***)calloc(NX, sizeof(float **)); | ||
b = (float ***)calloc(NX, sizeof(float **)); | b = (float ***)calloc(NX, sizeof(float **)); | ||
c = (float ***)calloc(NX, sizeof(float **)); | c = (float ***)calloc(NX, sizeof(float **)); | ||
- | |||
for (i=0;i < NX;i++) { | for (i=0;i < NX;i++) { | ||
a[i] = (float **)calloc(NY, sizeof(float **)); | a[i] = (float **)calloc(NY, sizeof(float **)); | ||
Line 81: | Line 79: | ||
c[i][j] = (float *)calloc(NY, sizeof(float *)); | c[i][j] = (float *)calloc(NY, sizeof(float *)); | ||
for (k=0;k < NZ;k++) { | for (k=0;k < NZ;k++) { | ||
- | a[i][j][k] = drand48()*2.0 - 1.0; /* X component */ | + | a[i][j][k] = drand48()*2.0 - 1.0; /* X component */ |
- | b[i][j][k] = drand48()*2.0 - 1.0; /* Y component */ | + | b[i][j][k] = drand48()*2.0 - 1.0; /* Y component */ |
- | c[i][j][k] = drand48()*2.0 - 1.0; /* Z component */ | + | c[i][j][k] = drand48()*2.0 - 1.0; /* Z component */ |
length = sqrt(a[i][j][k] * a[i][j][k] + | length = sqrt(a[i][j][k] * a[i][j][k] + | ||
- | b[i][j][k] * b[i][j][k] + | + | b[i][j][k] * b[i][j][k] + |
- | c[i][j][k] * c[i][j][k]); | + | c[i][j][k] * c[i][j][k]); |
maxlength = (length > maxlength) ? length : maxlength; | maxlength = (length > maxlength) ? length : maxlength; | ||
minlength = (length < minlength) ? length : minlength; | minlength = (length < minlength) ? length : minlength; | ||
Line 93: | Line 91: | ||
} | } | ||
} | } | ||
- | + | ||
tr[0] = x1; tr[1] = (x2-x1)/(float)(NX-1); tr[2] = 0.0; tr[3] = 0.0; | tr[0] = x1; tr[1] = (x2-x1)/(float)(NX-1); tr[2] = 0.0; tr[3] = 0.0; | ||
tr[4] = y1; tr[5] = 0.0; tr[6] = (y2-y1)/(float)(NY-1); tr[7] = 0.0; | tr[4] = y1; tr[5] = 0.0; tr[6] = (y2-y1)/(float)(NY-1); tr[7] = 0.0; | ||
- | tr[8] = z1; tr[9] = 0.0; tr[10]= 0.0; tr[11] = (z2-z1)/(float)(NZ-1); | + | tr[8] = z1; tr[9] = 0.0; tr[10]= 0.0; tr[11] = (z2-z1)/(float)(NZ-1); |
- | s2icm("rainbow", 1000, 1500); /* Install a colour map */ | + | s2icm("rainbow", 1000, 1500); /* Install a colour map */ |
- | s2scir(1000,1500); /* Set the colour range */ | + | s2scir(1000,1500); /* Set the colour range */ |
s2slw(2); /* Set the line width */ | s2slw(2); /* Set the line width */ | ||
s2sch(2); /* Set the size of arrowhead */ | s2sch(2); /* Set the size of arrowhead */ | ||
s2sah(1, 30.0, 0.8); /* Set the arrowhead type */ | s2sah(1, 30.0, 0.8); /* Set the arrowhead type */ | ||
- | s2sah(1, 30.0, 0.4); /* Set the arrow head type */ | + | scale = 0.2; /* Size of vectors */ |
- | scale = 0.2; /* Size of vectors */ | + | nc = 0; /* Put vector at coord point */ |
- | nc = 0; /* Put vector at coord point */ | + | colbylength = 1; /* Use the colour map */ |
- | colbylength = 1; /* Use the colour map */ | + | mindraw = -1.0; /* Draw them all! */ |
- | mindraw = -1.0; /* Draw them all! */ | + | |
- | s2vect3(a,b,c, NX,NY,NZ, 0,NX-1, 0,NY-1, 0,NZ-1, | + | s2vect3(a,b,c, NX,NY,NZ, 0,NX-1, 0,NY-1, 0,NZ-1, |
- | scale, nc, tr, colbylength, mindraw, minlength, maxlength); | + | scale, nc, tr, colbylength, mindraw, minlength, maxlength); |
- | /* Draw the vectors */ | + | |
- | s2show(1); /* Show the s2plot window */ | + | s2show(1); |
return 1; | return 1; | ||
} | } | ||
+ | |||
</pre></code> | </pre></code> | ||
[[S2PLOT:Function List | Back]] to S2PLOT function list. | [[S2PLOT:Function List | Back]] to S2PLOT function list. | ||
__NOTOC__ | __NOTOC__ | ||
__NOEDITSECTION__ | __NOEDITSECTION__ |
Current revision
s2vect3
Draw a vector map of a 3D data array, with blanking.
Prototype
void s2vect3(float ***a, float ***b, float ***c, int adim, int bdim, int cdim, int a1, int a2, int b1, int b2, int c1, int c2,
float scale, int nc, float *tr, float minlength, int colbylength, float minl, float maxl);
Description
Draw a vector map of a 3D data array, with data blanking.
- a, b and c are 3D arrays indexed by [0..(adim-1)][0..(bdim-1)][0..(cdim-1)] holding the components of the vectors in three orthogonal directions.
- The slice of data actually plotted is indexed by [a1..a2][b1..b2][c1..c2].
- Vector lengths are scaled by the value scale. There is no auto-set as per PGPlot's pgvect function.
- nc controls positioning of the vectors. nc<0 places the head of the vector on the coordinates; nc>0 places the vector base on the coords, and nc == 0 centres the vector on the coords.
- tr is the transformation matrix which maps indexes into the arrays onto the x, y and z axes of the 3D space. NOTE: this transformation IS NOT APPLIED to the vector components!!! The standard (non-rotated, non-skewed) transformation would have tr[2], tr[3], tr[5], tr[7], tr[9]and tr[10] all zero.
- x = tr[0] + tr[1] * ia + tr[2] * ib + tr[3] * ic
- y = tr[4] + tr[5] * ia + tr[6] * ib + tr[7] * ic
- z = tr[8] + tr[9] * ia + tr[10]* ib + tr[11]* ic
- Vectors with length (sqrt(a[...]^2 + b[...]^2 + c[...]^2)) less than minlength are not drawn.
- If colbylength > 0, the the vectors will be coloured by mapping those of length minl or smaller to the start of the current colour index range, and those of length maxl or greater to the end of the current colour index range.
See Also
s2arro | Draw an arrow from the point with world-coordinates (x1,y1,z1) to (x2,y2,z2). |
PGPLOT Equivalent
Code Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "s2plot.h"
#define NX 10 /* Dimensions of arrays */
#define NY 10
#define NZ 10
#define XLIMIT 1.0
#define YLIMIT 1.0
#define ZLIMIT 1.0
int main(int argc, char *argv[])
{
float ***a, ***b, ***c; /* Components of vectors */
int i, j, k; /* Loop variables */
float x1 = -XLIMIT, x2 = +XLIMIT, /* Range of plottable values */
y1 = -YLIMIT, y2 = +YLIMIT,
z1 = -ZLIMIT, z2 = +ZLIMIT;
float minlength = +9E30; /* Min and max vector lengths */
float maxlength = -9E30;
float tr[12]; /* Transformation matrix */
float mindraw, scale; /* See below */
int colbylength, nc; /* See below */
float length; /* Length of a vector */
srand48((long)time(NULL)); /* Seed random numbers */
s2opend("/?",argc, argv); /* Open the display */
s2swin(x1,x2, y1,y2, z1,z2); /* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
a = (float ***)calloc(NX, sizeof(float **));
b = (float ***)calloc(NX, sizeof(float **));
c = (float ***)calloc(NX, sizeof(float **));
for (i=0;i < NX;i++) {
a[i] = (float **)calloc(NY, sizeof(float **));
b[i] = (float **)calloc(NY, sizeof(float **));
c[i] = (float **)calloc(NY, sizeof(float **));
for (j=0;j < NY;j++) {
a[i][j] = (float *)calloc(NY, sizeof(float *));
b[i][j] = (float *)calloc(NY, sizeof(float *));
c[i][j] = (float *)calloc(NY, sizeof(float *));
for (k=0;k < NZ;k++) {
a[i][j][k] = drand48()*2.0 - 1.0; /* X component */
b[i][j][k] = drand48()*2.0 - 1.0; /* Y component */
c[i][j][k] = drand48()*2.0 - 1.0; /* Z component */
length = sqrt(a[i][j][k] * a[i][j][k] +
b[i][j][k] * b[i][j][k] +
c[i][j][k] * c[i][j][k]);
maxlength = (length > maxlength) ? length : maxlength;
minlength = (length < minlength) ? length : minlength;
}
}
}
tr[0] = x1; tr[1] = (x2-x1)/(float)(NX-1); tr[2] = 0.0; tr[3] = 0.0;
tr[4] = y1; tr[5] = 0.0; tr[6] = (y2-y1)/(float)(NY-1); tr[7] = 0.0;
tr[8] = z1; tr[9] = 0.0; tr[10]= 0.0; tr[11] = (z2-z1)/(float)(NZ-1);
s2icm("rainbow", 1000, 1500); /* Install a colour map */
s2scir(1000,1500); /* Set the colour range */
s2slw(2); /* Set the line width */
s2sch(2); /* Set the size of arrowhead */
s2sah(1, 30.0, 0.8); /* Set the arrowhead type */
scale = 0.2; /* Size of vectors */
nc = 0; /* Put vector at coord point */
colbylength = 1; /* Use the colour map */
mindraw = -1.0; /* Draw them all! */
s2vect3(a,b,c, NX,NY,NZ, 0,NX-1, 0,NY-1, 0,NZ-1,
scale, nc, tr, colbylength, mindraw, minlength, maxlength);
s2show(1);
return 1;
}
Back to S2PLOT function list.