乍一看,这个问题似乎有点怪异,但我已经为此苦苦挣扎了一段时间。我试图用椭圆画出一条紧身的轨迹。我使用了指数方程来绘制起始轨迹,并且效果很好。对于其余的轨迹,我决定使方程为二次方。我在屏幕上看到一个抛物线,但是当我尝试通过乘以小于零的数字来使抛物线变宽时,它会改变一切。有人能帮我吗?代码如下。
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
// import java.awt.geom.Ellipse2D.Double;
public class Slinkey extends Applet {
private static final long serialVersionUID = 4803949557086825455L;
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
int x = 10;
int y = 10;
int w = 100;
int h = 100;
int k = 0;
int otherX = 0;
double xpos = 0, ypos = 10;
System.out.println(xpos + " " + ypos);
Ellipse2D.Double c1 = new Ellipse2D.Double(ypos, ypos, w, h);
for (k = 0; k < 155; k += 5) {
xpos = x + k;
ypos = getYStart(xpos);
System.out.println(xpos + " " + ypos);
c1.setFrame(xpos, ypos, w, h); // (10, 10) (Top left corner) (1325, 650) (Bottom right corner).
g2.draw(c1);
}
for (double i = 160; i < 1325; i++) {
xpos = x + i;
ypos = getYMain(otherX);
otherX++;
System.out.println("Y Coordinate: " + xpos + " " + ypos);
if (ypos < 652) {
c1.setFrame(xpos, ypos, w, h);
g2.draw(c1);
}
}
}
public static double getYStart(double x) { // Starting trajectory.
return (0.029) * (Math.pow(x - 10, 2) + 10);
}
public static double getYMain(double x) { // Main equation that is causing problems.
return (Math.pow(x - 100, 2) + 10);
}
}