From 05d16b513b84fcb82f954ebc2b1b8efb0664fbf1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Ko=C5=BEusznik?= <jan@kozusznik.cz>
Date: Fri, 14 Oct 2022 14:42:26 +0200
Subject: [PATCH] fix movement equation
---
src/main/java/lab/BulletAnimated.java | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/main/java/lab/BulletAnimated.java b/src/main/java/lab/BulletAnimated.java
index 342be6f..c310369 100644
--- a/src/main/java/lab/BulletAnimated.java
+++ b/src/main/java/lab/BulletAnimated.java
@@ -12,7 +12,7 @@ public class BulletAnimated {
private Point2D initialSpeed;
private double size;
private double mass = 2;
- private double strenghtOfCannon = 50;
+ private double strenghtOfCannon = 100;
private double cannonLength = 100;
private boolean accelerate = true;
private boolean hitToGround = false;
@@ -52,27 +52,25 @@ public class BulletAnimated {
double cannonAngle = cannon.getAngle();
speed = speed
.add(new Point2D(Math.cos(cannonAngle) * strenghtOfCannon, Math.sin(cannonAngle) * strenghtOfCannon)
- .multiply(1 / mass * deltaT));
+ .multiply(deltaT / mass));
} else if (!hitToGround) {
accelerate = false;
Point2D airResistanceforce = new Point2D(
-1. / 2 * crossSectionalArea * Constants.AIR_DENSITY * dragCoefficient * Math.pow(speed.getX(), 2),
-1. / 2 * crossSectionalArea * Constants.AIR_DENSITY * 0.47 * Math.pow(speed.getY(), 2));
Point2D acceleration = new Point2D(-airResistanceforce.getX() * mass,
- -Constants.GRAVITATIONAL_ACCELERATION + airResistanceforce.getY() * mass);
+ (-Constants.GRAVITATIONAL_ACCELERATION + airResistanceforce.getY()) * mass);
speed = speed.add(acceleration.multiply(deltaT));
}
if (!hitToGround) {
- position = position.add(speed);
+ position = position.add(speed.multiply(deltaT*100));
if (!accelerate && position.getY() <= size / 2) {
hitToGround = true;
position = new Point2D(position.getX(), size / 2);
}
} else {
reload();
- }
-
-
+ }
}
public void reload() {
--
GitLab