-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint2D.java
35 lines (33 loc) · 977 Bytes
/
Point2D.java
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
30
31
32
33
public class Point2D {
private double x,y;
// Notkun: p = new Point2D(x,y)
// Fyrir: ekkert
// Eftir: p er punkturinn med hnitin (x,y)
public Point2D(double x, double y) {
this.x = x;
this.y = y;
}
// Notkun: a = p.getX()
// Fyrir: punkturinn p er til
// Eftir: a er x-hnit p
public double getX() { return x;}
// Notkun: a = p.getY()
// Fyrir: punkturinn p er til
// Eftir: a er y-hnit p
public double getY() { return y;}
// Notkun: x = a.distanceTo(b)
// Fyrir: ekkert
// Eftir: x er fjarlaegdin milli a og b
public double distanceTo(Point2D b) {
return Math.sqrt(Math.pow(this.getX()-b.getX(),2) + Math.pow(this.getY()-b.getY(),2));
}
public void setX(double x) {this.x = x;}
public void setY(double y) {this.y = y;}
public void reset(Point2D b) {
this.setX(b.x);
this.setY(b.y);
}
public String toString(){
return "(" + this.x + ", " + this.y + ")";
}
}