Java Reference
In-Depth Information
17.
public int
getX(){
18.
return
(x);
19.
}
20.
21.
public int
getY(){
22.
return
(y);
23.
}
24.
25.
public
String toString(){
26.
return
("["+x+";"+y+"]");
27.
}
28.
}//
class
File:
its/GenericDraw/RealPoint.java
1.
package
its.GenericDraw;
2.
3.
public class
RealPoint{
4.
private double
x, y;
5.
6.
public
RealPoint(
double
xx,
double
yy){
7.
x=xx;
8.
y=yy;
9.
}
10.
11.
public double
getX(){
12.
return
(x);
13.
}
14.
15.
public double
getY(){
16.
return
(y);
17.
}
18.
19.
public double
distanceTo(RealPoint p){
20.
return
(Math.sqrt(Math.pow((
this
.x-p.x),2)+Math.pow((
this
.y-p.y),2)));
21.
}
22.
23.
public
String toString(){
24.
return
("("+x+";"+y+")");
25.
}
26.
}//
class
We shall use real points for the abstract specification of geometric objects. When-
ever such an object has to be rendered, the real points are converted into pixel
coordinates. The pixel coordinates are computed in such a way that the whole
Search WWH ::
Custom Search