ソースです。
import java.awt.Color;
import java.awt.Graphics2D;
import myMath.MyCurve;
import myMath.Tpl10;
public class TestMyEllipse01 extends Tpl10 {
int t = 0;
double a = 5.0;
double b = 4.0;
double c = 3.0;
public void init() {
tr.move(getWidth() / 2, getHeight() / 2);
tr.set(1, 0, 0, -1);
tr.scale(20);
setTimer(10);
}
public void draw(Graphics2D g2) {
double x;
MyParaEllipse mp = new MyParaEllipse();
x = Math.toRadians(t);
// 軸
g2.setColor(Color.black);
g2.draw(tr.LineX());
g2.draw(tr.LineY());
// 焦点
g2.setColor(Color.blue);
g2.fill(tr.Point(c, 0));
g2.fill(tr.Point(-c, 0));
// 線
g2.setColor(Color.green);
mp.p(x);
g2.draw(tr.Line(c, 0, mp.x, mp.y));
g2.draw(tr.Line(-c, 0, mp.x, mp.y));
// 点
g2.setColor(Color.red);
g2.fill(tr.Point(mp.x, mp.y));
// 楕円
draw(mp, 0, x);
t++;
if (t > 360) {
t = 0;
}
}
class MyParaEllipse extends MyCurve {
public void p(double t) {
x = a * Math.cos(t);
y = b * Math.sin(t);
}
}
}