The Line class
Example 23.21: The Line class
Example 23.21 is a class that represents a line, or, more precisely, a line segment. The line is stored as two Point objects which represent it endpoints. Notice that the draw method uses the Point class's non-public fields x, y and z. This is permissible because the Line class and the Point class are in the same package, elharo.vrml.
package elharo.vrml;
public class Line extends shape {
// a line is defined by two points
Point p1;
Point p2;
public Line(Point p1, Point p2) {
this.p1 = p1;
this.p2 = p2;
}
public Line(double x1, double y1, double z1,
double x2, double y2, double z2) {
p1 = new Point(x1, y1, z1);
p2 = new Point(x2, y2, z2);
}
public String draw() {
String s1 = "Coordinate3 { point [ ";
String s2 = p1.x + " " + p1.y + " " + p1.z + ",\n";
String s3 = p2.x + " " + p2.y + " " + p2.z + ",\n";
String s4 = "] }\n\n";
String s5 = "IndexedLineSet {\n coordIndex [ " +
"0, 1\n] \n}";
return s1 + s2 + s3 + s4 + s5;
}
}
Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
This Chapter
Examples
Home
Wyszukiwarka
Podobne podstrony:
23 21 Styczeń 1995 Barbarzyńcy i demokraci21 00 23 7woz3e642eqrsuqs4swdh7r4sqpork6hgtkd7xyRKdI TRiL s I sem 5 wykład 23, 30 XI, 7, 14, 21 XII 2011Projekt 3 rys 21, 2321 2321 23 Wrzesień 1999 Okopany krajwięcej podobnych podstron