7.4 Plotting a line 215
7.4 Plotting a line.............................
Next, we build a code that draws the graph of a line in thexyplane defined
by a group of data points. The code will offer an option for drawing markers
at the data points, including circles, squares, and diamonds. The application
will employ two ancillary functions that use basicVoglecommands to move
the cursor and draw straight segments:
- Functiondrawmarker2ddraws a marker at a specified location.
- Functiondrawline2ddraws the graph of a line defined by a group of
points inside a specified window.
We will discuss these functions individually and then illustrate their usage in a
plotting code.
Function drawmarker2d
The implementation of the marker drawing functiondrawmarker2dis:
/*------------------------------------------------
void drawmarker2d
Draw a symbol at the location (x, y) according
to the value of the integer variable marker:
marker:
0 : no symbol
1 : circle
2 : triangle
3 : square
4 : diamond
5 : dot
------------------------------------------------ */
#include "VOGLE/voglec++.h"
using namespace std;
void drawmarker2d (float x, float y, int marker
,float xmin, float xmax
,float ymin, float ymax)
{
float xrange = xmax-xmin; // plotting range
float yrange = ymax-ymin;
float xsize = 0.02*xrange; // marker size