KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > physics > ConstantForce2D


1 package JSci.physics;
2
3 /**
4 * The ConstantForce2D class provides an object for encapsulating constant forces in 2D.
5 * @version 1.1
6 * @author Mark Hale
7 * @author Silvere Martin-Michiellot
8 */

9 public class ConstantForce2D extends Force2D {
10         protected final double Fx, Fy;
11         /**
12         * Constructs a force.
13         */

14         public ConstantForce2D(double fx, double fy) {
15                 Fx = fx;
16                 Fy = fy;
17         }
18         /**
19         * Returns the addition of this force and another.
20         */

21         public Force2D add(ConstantForce2D F) {
22                 return new ConstantForce2D(Fx+F.Fx, Fy+F.Fy);
23         }
24         /**
25         * Returns the subtraction of this force by another.
26         */

27         public Force2D subtract(ConstantForce2D F) {
28                 return new ConstantForce2D(Fx-F.Fx, Fy-F.Fy);
29         }
30         public double getXComponent(double t) {
31                 return Fx;
32         }
33         public double getYComponent(double t) {
34                 return Fy;
35         }
36 }
37
38
Popular Tags