A sequence of lines connecting successive vertices is called a polyline.
Although polylines can be drawn by repeated calls to the line-drawing methods,
Cartesian includes them as a special case.
The following methods of the Cartesian class draw a polyline using
two lists of vertex coordinates:
void PolyLineCoord (int VertexCount,
VertexCoordinateList xArray,
VertexCoordinateList yArray);
void PolyLine (int VertexCount,
VertexCoordinateList xArray,
VertexCoordinateList yArray);
|
To plot a series of monthly temperatures on a graph, we could use code
like the following, to set up two VertexCoordinateLists and then use
them in a call to PolyLine:
VertexCoordinateList Months = new VertexCoordinateList (12);
VertexCoordinateList Temp = new VertexCoordinateList (12);
int Month;
|
/* Set up the array of X coordinates */
Month = 0;
while (Month < 12) {
Months.Put (Month, 10 + Month * 15);
Month = Month + 1;
}
/* Set up the array of Y coordinates */
Temp.Put (0, 20);
Temp.Put (1, 35);
Temp.Put (2, 50);
Temp.Put (3, 80);
Temp.Put (4, 40);
Temp.Put (5, 100);
Temp.Put (6, 120);
Temp.Put (7, 125);
Temp.Put (8, 85);
Temp.Put (9, 110);
Temp.Put (10, 80);
Temp.Put (11, 90);
/* Plot two axes */
Canvas.Line (10, 10, 10, 140);
Canvas.Line (10, 70, 190, 70);
/* Draw the polyline */
Canvas.PolyLine (12, Months, Temp);
|
PolyLine Demo 1
|
or, equivalently,
Canvas.PolyLineCoord (12, Months, Temp);
Alternately, PolyLine can be called with a VertexList, a single array
of points.
void PolyLine (int VertexCount, VertexList Vertices);
Here "C_Point" is a defined class, which holds the points x and y values.
See the reference below (Cartesian Points.)
|
To draw a bowtie pattern, the following code could be used:
VertexList Bowtie = new VertexList (7);
/* Set up the VertexList */
Bowtie.Put (0, 10, 140);
Bowtie.Put (1, 75, 85);
Bowtie.Put (2, 140, 140);
Bowtie.Put (3, 140, 10);
Bowtie.Put (4, 75, 65);
Bowtie.Put (5, 10, 10);
Bowtie.Put (6, 10, 140);
/* Draw the polyline */
Canvas.PolyLine (7, Bowtie);
|
PolyLine Demo 2
|
Because Java supports overloading of methods, PolyLine can be called either
with the coordinate arrays or with the point array.
|
|