-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
29 lines (23 loc) · 843 Bytes
/
Copy pathPoint.java
File metadata and controls
29 lines (23 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*************************************************************************
* Compilation: javac Point.java
*
* Point in the plane.
*
*************************************************************************/
public class Point {
private final static double SCALEX = 0.0001 * 1000.0;
private final static double SCALEY = 0.0001 * 1000.0 * 1.3;
private int x; // x component
private int y; // y component
public Point(int x, int y) { this.x = x; this.y = y; }
// convert to string
public String toString() {
return "(" + x + ", " + y + ")";
}
// return Euclidean distance between this and p
public double distanceTo(Point p) {
double dx = this.x - p.x;
double dy = this.y - p.y;
return Math.sqrt(dx*dx + dy*dy);
}
}