-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircle.java
44 lines (40 loc) · 1.07 KB
/
Circle.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
import java.awt.geom.Arc2D;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.Line2D;
/**
* Circle class. Extends the Arc2D.Double class. Has the new method of checking
* if a line is intersecting a circle.
*
* @author haolidu
* @version 1.00
*/
public class Circle extends Double {
private static final long serialVersionUID = 5075382594155069106L;
/**
* Circle constructor.
*
* @param x
* double position in x-axis
* @param y
* double position in y-axis
* @param d
* double diameter
*/
public Circle(double x, double y, double d) {
super(x, y, d, d, 0, 360, Arc2D.CHORD);
}
/**
* Checks if the given line is intersecting this circle.
*
* @param line
* Line2D object
* @return ture if the circle is intersecting the line, false otherwise.
*/
public boolean intersects(Line2D line) {
double r = width / 2;
if (line.ptSegDist(x + r, y + r) <= r) {
return true;
}
return false;
}
}