Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Balistics {
- static double t=0.;
- static double dt=0.002;
- static double m=0.01;
- static double alpha = 0.001;
- static vector r=new vector();
- static vector v= new vector(10.*Math.cos(Math.PI/4.),0.,10.*Math.sin(Math.PI/4.));
- static vector g = new vector(0.,0.,-9.81);
- static vector a = new vector();
- static vector f=new vector();
- public static vector R(vector v){//poloha
- r.x=RComponent(r.x, v.x, dt);
- r.y=RComponent(r.y, v.y, dt);
- r.z=RComponent(r.z, v.z, dt);
- return r;
- }
- public static vector F(vector v){//sila odporu
- f.x=FComponent(v.x, v.abs());
- f.y=FComponent(v.y, v.abs());
- f.z=FComponent(v.z, v.abs());
- return f;
- }
- public static vector A(vector f){//zrychlenie
- a.x=AComponent(f.x, m) + g.x;
- a.y=AComponent(f.y, m) + g.y;
- a.z=AComponent(f.z, m) + g.z;
- return a;
- }
- public static vector V(vector a){//rychlost
- v.x=VComponent(v.x, a.x, dt);
- v.y=VComponent(v.y, a.y, dt);
- v.z=VComponent(v.z, a.z, dt);
- return v;
- }
- private static double FComponent(double vComponent, double absv){
- return (-alpha*absv*vComponent);
- }
- private static double AComponent(double fComponent, double m){
- return (fComponent/m);
- }
- private static double RComponent(double rComponent, double vComponent, double dt){
- return (rComponent + vComponent*dt);
- }
- private static double VComponent(double vComponent, double aComponent, double dt){
- return (vComponent + aComponent*dt);
- }
- public static void makestep(){//krok v case o dt
- r=R(v);
- f=F(v);
- a=A(f);
- v=V(a);
- t=t+dt;
- }
- public static void main(String[] args) {
- for (int i = 0; i<1000;i++){
- makestep();
- System.out.println("time: "+t+" x: "+r.x+" z:"+r.z+" a.x: "+a.x+" a.z: "+a.z+" v.x: "+v.x+" v.z: "+v.z+" f.x: "+f.x+" f.z: "+f.z);
- }
- }
- }
- class vector{
- public double x,y,z;
- vector(){
- x=0;y=0;z=0;
- }
- vector(double x, double y, double z){
- this.x=x; this.y=y; this.z=z;
- }
- public void add(vector r){
- x=x+r.x; y=y+r.y; z=z+r.z;
- }
- public vector Add(vector r){
- vector tmp=new vector(this.x+r.x,this.y+r.y,this.z+r.z);
- return tmp;
- }
- public double abs(){
- return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);
- }
- public vector Mult(double alpha){
- vector tmp = new vector(alpha*this.x, alpha*this.y,alpha*this.z);
- return tmp;
- }
- public double scalarprod(vector r){
- return(x*r.x+y*r.y+z*r.z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement