Advertisement
hocikto19

Balistic curve

Mar 11th, 2015
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1. public class Balistics {
  2.     static double t=0.;
  3.     static double dt=0.002;
  4.     static double m=0.01;
  5.     static double alpha = 0.001;
  6.     static vector r=new vector();
  7.     static vector v= new vector(10.*Math.cos(Math.PI/4.),0.,10.*Math.sin(Math.PI/4.));
  8.     static vector g = new vector(0.,0.,-9.81);
  9.     static vector a = new vector();
  10.     static vector f=new vector();
  11.    
  12.     public static vector R(vector v){//poloha
  13.         r.x=RComponent(r.x, v.x, dt);
  14.         r.y=RComponent(r.y, v.y, dt);
  15.         r.z=RComponent(r.z, v.z, dt);
  16.         return r;
  17.     }
  18.  
  19.     public static vector F(vector v){//sila odporu
  20.         f.x=FComponent(v.x, v.abs());
  21.         f.y=FComponent(v.y, v.abs());
  22.         f.z=FComponent(v.z, v.abs());
  23.         return f;
  24.     }
  25.    
  26.     public static vector A(vector f){//zrychlenie
  27.         a.x=AComponent(f.x, m) + g.x;
  28.         a.y=AComponent(f.y, m) + g.y;
  29.         a.z=AComponent(f.z, m) + g.z;
  30.         return a;
  31.     }
  32.    
  33.     public static vector V(vector a){//rychlost
  34.         v.x=VComponent(v.x, a.x, dt);
  35.         v.y=VComponent(v.y, a.y, dt);
  36.         v.z=VComponent(v.z, a.z, dt);
  37.         return v;
  38.     }
  39.    
  40.     private static double FComponent(double vComponent, double absv){
  41.         return (-alpha*absv*vComponent);
  42.     }
  43.    
  44.     private static double AComponent(double fComponent, double m){
  45.         return (fComponent/m);
  46.     }
  47.    
  48.     private static double RComponent(double rComponent, double vComponent, double dt){
  49.         return (rComponent + vComponent*dt);
  50.     }
  51.    
  52.     private static double VComponent(double vComponent, double aComponent, double dt){
  53.         return (vComponent + aComponent*dt);
  54.     }
  55.    
  56.     public static void makestep(){//krok v case o dt
  57.         r=R(v);
  58.         f=F(v);
  59.         a=A(f);
  60.         v=V(a);
  61.         t=t+dt;
  62.     }
  63.    
  64.     public static void main(String[] args) {
  65.         for (int i = 0; i<1000;i++){
  66.             makestep();
  67.             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);
  68.         }
  69.     }
  70.    
  71. }
  72. class vector{
  73.     public double x,y,z;
  74.     vector(){
  75.         x=0;y=0;z=0;
  76.     }
  77.     vector(double x, double y, double z){
  78.         this.x=x; this.y=y; this.z=z;
  79.     }
  80.     public void add(vector r){
  81.         x=x+r.x; y=y+r.y; z=z+r.z;
  82.     }
  83.     public vector Add(vector r){
  84.         vector tmp=new vector(this.x+r.x,this.y+r.y,this.z+r.z);
  85.         return tmp;
  86.     }
  87.    
  88.     public double abs(){
  89.         return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);
  90.     }
  91.     public vector Mult(double alpha){
  92.         vector tmp = new vector(alpha*this.x, alpha*this.y,alpha*this.z);
  93.         return tmp;
  94.     }
  95.    
  96.     public double scalarprod(vector r){
  97.         return(x*r.x+y*r.y+z*r.z);
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement