-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circle2d.java
56 lines (50 loc) · 1.32 KB
/
Circle2d.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.lang.Math;
public class Circle2d {
private double x;
private double y;
private double radius;
public Circle2d(double x, double y, double radius) {
this.x = x;
this.y = y;
this.radius = radius;
}
public Circle2d(double x, double y) {
this.x = x;
this.y = y;
this.radius = 1;
}
// getters
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getRadius() {
return radius;
}
public double getArea() {
return Math.PI * Math.pow(radius,2);
}
public double getCircumference() {
return (2 * radius * Math.PI);
}
// methods
public void translate(double dx, double dy) {
x += dx;
y += dy;
}
public void expand(double amt) {
radius += amt;
}
public double distance(Circle2d c2) {
return Math.pow(Math.pow(Math.abs(x - c2.getX()),2) + Math.pow(Math.abs(y - c2.getY()),2),0.5);
}
public boolean contains(double x, double y) {
return Math.pow(Math.pow(Math.abs(this.x - x), 2) + Math.pow(Math.abs(this.y - y), 2), 0.5) == radius;
}
// toString (yes, it get's its own section)
public String toString() {
return "Circle: (" + x + ", " + y + "); Radius: " + radius;
}
}