forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKinematics.java
More file actions
69 lines (61 loc) · 1.97 KB
/
Kinematics.java
File metadata and controls
69 lines (61 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.thealgorithms.physics;
/**
* Implements the fundamental "SUVAT" equations for motion
* under constant acceleration.
*
* @author [Priyanshu Kumar Singh](https://github.com/Priyanshu1303d)
* @see <a href="https://en.wikipedia.org/wiki/Equations_of_motion#Uniform_acceleration">Wikipedia</a>
*/
public final class Kinematics {
private Kinematics() {
}
/**
* Calculates the final velocity (v) of an object.
* Formula: v = u + at
*
* @param u Initial velocity (m/s).
* @param a Constant acceleration (m/s^2).
* @param t Time elapsed (s).
* @return The final velocity (m/s).
*/
public static double calculateFinalVelocity(double u, double a, double t) {
return u + a * t;
}
/**
* Calculates the displacement (s) of an object.
* Formula: s = ut + 0.5 * a * t^2
*
* @param u Initial velocity (m/s).
* @param a Constant acceleration (m/s^2).
* @param t Time elapsed (s).
* @return The displacement (m).
*/
public static double calculateDisplacement(double u, double a, double t) {
return u * t + 0.5 * a * t * t;
}
/**
* Calculates the displacement (s) of an object.
* Formula: v^2 = u^2 + 2 * a * s
*
* @param u Initial velocity (m/s).
* @param a Constant acceleration (m/s^2).
* @param s Displacement (m).
* @return The final velocity squared (m/s)^2.
*/
public static double calculateFinalVelocitySquared(double u, double a, double s) {
return u * u + 2 * a * s;
}
/**
* Calculates the displacement (s) using the average velocity.
* Formula: s = (u + v) / 2 * t
*
* @param u Initial velocity (m/s).
* @param v Final velocity (m/s).
* @param t Time elapsed (s).
* @return The displacement (m).
*/
public static double calculateDisplacementFromVelocities(double u, double v, double t) {
double velocitySum = u + v;
return velocitySum / 2 * t;
}
}