Programming and Graphics

(Kiana) #1

7.4 Plotting a line 219


if (crossymax<tol)
{
yint = ymax-0.001;
xint= ((yint-ypp)*xp-(yint-yp)*xpp)/(yp-ypp);
if(ypp>=ymax)
{
xpp = xint; ypp = yint;
move2 (xpp,ypp);
}
else
{
xp=xint; yp=yint;
}
}

float crossymin = (yp-ymin)*(ypp-ymin);

if (crossymin<tol)
{
yint = ymin+0.001;
xint= ((yint-ypp)*xp-(yint-yp)*xpp)/(yp-ypp);
if(ypp<=ymin)
{
xpp = xint; ypp = yint;
move2 (xpp,ypp);
}
else
{
xp=xint; yp=yint;
}
}
}

draw2 (xp,yp);

} // sousami

}

An important feature of the code is that, if a plotted line exits the plotting
window, it is chopped off and the marginal values are computed by linear
interpolation.


Code plot2dsimple


The following code contained in the fileplot2dsimple.cc defines and
plots data points based on the two functions we have constructed:

Free download pdf