想模拟一个物体的自由落体运动  并且模拟该物体下落之后弹跳的高度
物理上都需要什么条件  好久没学 都忘记了

解决方案 »

  1.   

    希望以下模拟重力场的程序,对你有启发。
    使用在重力场(可能在另一个星球,那里的重力加速度为1)中的自由落体位移公式:
    h = 1/2 *g* t*t
    在 400 (长度单位,比如 米)高度,初始速度为0, 下落。
    求出每一秒的位置, 用数组 int a[] 存储一个周期的数据。
    写成代码,模拟上述情况, 然后调整休眠时间,以便直观上看,类似某一个星球上的重力场自由落体的情况。
    ----------------
    import java.awt.*;
    import javax.swing.*;
    public class gravity extends JFrame implements Runnable { private Thread timer=null;
    private int y0; //初始位置
    private int index =0; //数据数组下标
    private int [] data = {0, 1 , 4, 9, 16, 25, 36, 49, 64 ,81, 100, 121, 144, 169, 196, 225,256,289,324,361,400,361,324,289,256,225,196,169,144,121,100,81,64,49,36,25,16,9,4, 1,0};public static void main(String args[]) {
    gravity ff = new gravity();
    ff.setVisible(true);
    ff.setSize(400,500);
    ff.start();
    ff.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
    public gravity(){ 
    super("自由落体");
    y0 = 50;
    Container container = getContentPane();

    public void paint(Graphics g){
    super.paint(g);
    int y = y0 + data[index];
    g.setColor(Color.RED);  
    g.fillOval(100,y,30,30);
    index +=1;
    index %=41;
    g.setColor(Color.GREEN);
    g.drawLine(0,480,300,480);
    g.drawString("地面", 310,480);     
    }

    public void start() {
        if(timer == null) {
             timer = new Thread(this);
             timer.start();      
            }
       }
       public void stop() {
            timer = null;
       }   public void run( ) {
            while (timer != null) {
            try {Thread.sleep( 100);} catch (InterruptedException e) {}
            repaint();
    }
        timer = null;
       }