-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllipse.java
More file actions
47 lines (39 loc) · 911 Bytes
/
Ellipse.java
File metadata and controls
47 lines (39 loc) · 911 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package csg;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;
class Ellipse extends Geometry {
double aRad;
double bRad;
int x, y;
double rotation;
Ellipse(Op op) {
super(op);
aRad = 20;
bRad = 10;
x = 10;
y = 5;
rotation = 0;
}
Ellipse(Op op, int x, int y, double aRad, double bRad) {
super(op);
this.aRad = aRad;
this.bRad = bRad;
this.x = x;
this.y = y;
rotation = 0;
}
boolean isHit(int x, int y) {
return Math.pow(x - this.x, 2) / (aRad * aRad) + Math.pow(y - this.y, 2) / (bRad * bRad) <= 1;
}
public String toString() {
return "Ellipse " + op.name() + " x:" + x + " y:" + y + " a:" + aRad + " b:" + bRad;
}
void draw(Graphics g) {
g.setColor(color);
Graphics2D g2 = (Graphics2D) g;
g2.draw(new Ellipse2D.Double(x - aRad, y - bRad, aRad * 2, bRad * 2));
}
void corner(Graphics g, int c) {
}
}