HowToC:DrawPoints
From S2PLOT
Revision as of 22:50, 10 December 2007 S2plot admin (Talk | contribs) ← Previous diff |
Revision as of 22:53, 10 December 2007 S2plot admin (Talk | contribs) Next diff → |
||
Line 22: | Line 22: | ||
s2swin(xmin, xmax, ymin, ymax, zmin, zmax); /* Set the display coordinates */ | s2swin(xmin, xmax, ymin, ymax, zmin, zmax); /* Set the display coordinates */ | ||
- | s2pt1(0, 0, 0, 1); | + | s2pt1(0, 0, 0, 2); /* Draw a cross at the origin: marker = 2 */ |
float x[10], y[10],z[10]; | float x[10], y[10],z[10]; | ||
+ | int m[10]; | ||
int i; | int i; | ||
- | for (i=0;i<10;i++) { | + | for (i=0;i<10;i++) { /* Generate random point positions */ |
x[i] = drand48()*(xmax-xmin) + xmin; | x[i] = drand48()*(xmax-xmin) + xmin; | ||
y[i] = drand48()*(ymax-ymin) + ymin; | y[i] = drand48()*(ymax-ymin) + ymin; | ||
z[i] = drand48()*(zmax-zmin) + zmin; | z[i] = drand48()*(zmax-zmin) + zmin; | ||
+ | m[i] = random()%7; /* Choose a random marker */ | ||
+ | if (m[i] == 3) m[i] = 1; /* There is no marker = 3 */ | ||
+ | else if (m[i] == 5) m[i] = 6; /* There is no marker = 5 */ | ||
} | } | ||
s2pt(10, x, y, z, 1); | s2pt(10, x, y, z, 1); |
Revision as of 22:53, 10 December 2007
Contents |
Drawing Points
Perhaps the most common object you will need to draw as a point. There are two different ways to do this, using either the PGPLOT-style functions or the native S2PLOT point functions.
For PGPLOT programmers, the functional interface to s2pt1 (draw a single point), s2pt (draw multiple points) and s2pnts (draw multiple points with different symbols) will seem very familiar. In each case, x, y and z coordinates are passed to the functions along with an integer value for the "marker" style to use.
Points example
Copy and paste the following code, and save the file as s2points.c
#include <stdio.h>
#include <stdlib.h>
#include "s2plot.h"
int main(int argc, char *argv[])
{
float xmin = -1, xmax = +1; /* X data range */
float ymin = -1, ymax = +1; /* Y data range */
float zmin = -1, zmax = +1; /* Z data range */
s2opend("/?",argc,argv); /* Which S2PLOT device to open? */
s2swin(xmin, xmax, ymin, ymax, zmin, zmax); /* Set the display coordinates */
s2pt1(0, 0, 0, 2); /* Draw a cross at the origin: marker = 2 */
float x[10], y[10],z[10];
int m[10];
int i;
for (i=0;i<10;i++) { /* Generate random point positions */
x[i] = drand48()*(xmax-xmin) + xmin;
y[i] = drand48()*(ymax-ymin) + ymin;
z[i] = drand48()*(zmax-zmin) + zmin;
m[i] = random()%7; /* Choose a random marker */
if (m[i] == 3) m[i] = 1; /* There is no marker = 3 */
else if (m[i] == 5) m[i] = 6; /* There is no marker = 5 */
}
s2pt(10, x, y, z, 1);
s2show(1); /* Hand over to the display */
return 1;
}
Compile using: cbuild.csh s2example<tt> and then run by typing <tt>s2example at the command prompt.
Experiment for yourself
Function Overview
For more information on the functions we have introduced so far, see:
Common Problems
Test code: s2points.c
This is the full test code for the point-drawing example.
Where to Next?
- Back to S2PLOT How To...
- Drawing lines