The following methods of the Cartesian class draw a line from (x1, y1) to
(x2, y2):
void LineCoord (int x1, int y1, int x2, int y2);
void Line (int x1, int y1, int x2, int y2);
|
To plot a line from (10, 10) to (90, 90) on Cartesian Canvas,
we simply call
Canvas.LineCoord (10, 10, 90, 90);
or, equivalently,
Canvas.Line (10, 10, 90, 90);
|
Line Demo 1
|
Because it is often more natural to think in terms of endpoints
rather than of individual x and y coordinates, Cartesian provides
an alternative line-drawing functions:
void Line (C_Point pt1, C_Point pt2);
Because Java supports overloading of methods, Line can be called either
with the coordinates or with the end points.
Here "C_Point" is a defined class, which holds the points x and y values.
See the reference below (Cartesian Points.)
|
To plot a line from A = (10, 90) to B = (70, 20) on Cartesian Canvas,
call
C_Point A = new C_Point (10, 90);
C_Point B = new C_Point (70, 20);
Canvas.Line (A, B);
|
Line Demo 2
|
|
|