Programming and Graphics

(Kiana) #1

7.4 Plotting a line 217


/*-------------------------------------------
void drawline2d

Draw a polygonal line defined by a set of points
and put symbols at the points

If a segment crosses the boundaries of the plotting
window, interpolate for the crossing point

SYMBOLS
--------
n: number of points to be plotted
x,y: coordinates of the points
xmin,xmax: x plotting window
ymin,ymax: y plotting window
tol: tolerance for window crossing
Icheck: 1 to perform crossing checks
------------------------------------------ */

#include "VOGLE/voglec++.h"

using namespace std;

void drawline2d (int n, float x[], float y[]
,float xmin, float xmax
,float ymin, float ymax, int Icheck)
{
float xrange = xmax-xmin;
float yrange = ymax-ymin;
float xp, yp, xpp, ypp; // temporary positions
float xint, yint; // interpolation variables
float tol=0.000001; // tolerance

//--- Move to the first point:

xp=x[0]; yp=y[0];
move2 (xp,yp);

/*------------------------------------------
If both the current and the previous point
lie outside the window, do not draw the line
If a segment crosses the borders, draw up to
the interpolated crossing points
------------------------------------------ */

for (int i=1; i<n; i++) // closes at sousami
{
xpp=x[i-1];
ypp=y[i-1];
Free download pdf