Java_小球自由落体_小球下落问题

小球下落问题描述:

一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?

问题的关键有:

1.要求得第十次落地时,球走的总路程,即包括前九次的下落和弹起和第十次的下落

 2.一次落地包括:下落和弹起,先下落,再弹起。

示意图如图所示:

其中,H为下落高度,H/2为弹起高度,一次的总路程S=H+H/2。

编码:

package test;
/**
 * 
 * @author laoshifu
 * 2021年12月8日
 */
public class Action {
	public static void main(String[] args) {
		double h=100;//最初高度
		double s=0;//sum记录
		for (int i = 0; i < 10; i++) {
			s+=2*h;//每次累加往返距离
			h=h/2;//每次距离减半
		}
		System.out.println(h);
		System.out.println(s-100);//问经过多少M,所以减除初始高度
	}
}

希望能对大家有所帮助,点赞评论哦。

实现小球自由落体反弹的关键在于模拟小球在不同高度上的速度和位置变化以及碰撞的效果。可以使用以下代码实现: ```java public class Ball { private double x; // 小球x坐标 private double y; // 小球y坐标 private double v; // 小球下落速度 private double g; // 重力加速度 private double e; // 碰撞能量损失系数 private double t; // 间间隔 private double h; // 弹跳高度 private double maxHeight; // 最大高度 private double radius; // 小球半径 public Ball(double x, double y, double v, double g, double e, double t, double h, double radius) { this.x = x; this.y = y; this.v = v; this.g = g; this.e = e; this.t = t; this.h = h; this.maxHeight = 0; this.radius = radius; } // 更新小球位置和速度 public void update() { if (y <= radius) { // 碰到地面 v = -v * e; // 反弹 if (Math.abs(v) < 0.1) { // 小球停止运动 v = 0; } h = 0; // 重置弹跳高度 } else { // 自由落体 v += g * t; } y += v * t; // 更新y坐标 if (y > maxHeight) { // 更新最大高度 maxHeight = y; } h = maxHeight - y; // 更新弹跳高度 } // 获取小球x坐标 public double getX() { return x; } // 获取小球y坐标 public double getY() { return y; } // 获取小球半径 public double getRadius() { return radius; } // 获取小球弹跳高度 public double getBounceHeight() { return h; } } ``` 在主程序中,可以使用以下代码模拟小球自由落体反弹的过程: ```java public static void main(String[] args) { double x = 0; // 小球x坐标 double y = 100; // 小球y坐标 double v = 0; // 小球下落速度 double g = 9.8; // 重力加速度 double e = 0.8; // 碰撞能量损失系数 double t = 0.01; // 间间隔 double h = 0; // 弹跳高度 double radius = 10; // 小球半径 Ball ball = new Ball(x, y, v, g, e, t, h, radius); JFrame frame = new JFrame(); frame.setSize(400, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.RED); g.fillOval((int) (ball.getX() - ball.getRadius()), (int) (ball.getY() - ball.getRadius()), (int) (2 * ball.getRadius()), (int) (2 * ball.getRadius())); } }; frame.add(panel); frame.setVisible(true); while (true) { ball.update(); panel.repaint(); try { Thread.sleep(10); } catch (InterruptedException ex) { ex.printStackTrace(); } } } ``` 运行程序后,可以看到小球在窗口中自由落体反弹的过程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

红目香薰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值