Advertisement
Guest User

Untitled

a guest
May 27th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.11 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package slingshot3.pkg0;
  7. import java.util.*;
  8. import java.text.*;
  9. /**
  10.  *
  11.  * @author GFNVIDIA
  12.  */
  13. public class Slingshot30 {
  14.    
  15.  
  16.     /**
  17.      * @param args the command line arguments
  18.      */
  19.     public static void main(String[] args) {
  20.         // TODO code application logic here
  21.     double y1 = 1.0;
  22.     double x1 = 0.0;
  23.     double gravity = 9.8;
  24.     double dragCo = 0.40;
  25.     double airDensity = 1.23;
  26.     double CSArea = 0.00426;
  27.     double baseballMass = 0.145;
  28.     double velocity = 23.02;
  29.     double angleNew = Math.toRadians(45.0);
  30.     double totalDisplacement;
  31.     double AR;
  32.     double fricFX;
  33.     double fricFY;
  34.     double gravForce;
  35.     double iniVeloYrads;
  36.     double iniVeloXrads;
  37.     double iniVeloYdeg;
  38.     double iniVeloXdeg;
  39.     double netForceX;
  40.     double netForceY;
  41.     double accelX;
  42.     double accelY;
  43.     double time;
  44.     double finalVeloX;
  45.     double finalVeloY;
  46.    
  47.  
  48.  
  49.     while (y1 > 0){
  50.         //Double massInput = Double.parseDouble(txtMassInput.getText());
  51.         //Double angleInput = Math.toRadians(Double.parseDouble(txtLaunchAngle.getText())); //this is to put degrees to radians... will later be converted back to degrees.
  52.         //angleNew = Math.toRadians(45.0);
  53.         totalDisplacement = 0.0;
  54.        
  55.        
  56.         // program begins
  57.         AR = 0.5*(gravity*dragCo*airDensity*CSArea*velocity*velocity);
  58.        
  59.         fricFX = AR*(Math.cos(angleNew));
  60.         //fricFY = 0.0;
  61.                
  62.         if (angleNew > 0){
  63.             fricFY = (-1)*AR*(Math.sin(angleNew));
  64.         }
  65.         else if (angleNew < 0){
  66.             fricFY = AR*(Math.sin(angleNew));
  67.         }
  68.         else {
  69.             fricFY = 0;
  70.         }
  71.        
  72.        
  73.         ///nonsense starts here
  74.        
  75.         iniVeloYrads = Math.toDegrees(Math.sin(angleNew)) * velocity;
  76.         iniVeloXrads = Math.toDegrees(Math.cos(angleNew)) * velocity;
  77.  
  78.         // code is continued down here to convert the velocity with respect to degrees
  79.         //iniVeloYdeg = Math.toDegrees(iniVeloYrads);
  80.         //iniVeloXdeg = Math.toDegrees(iniVeloXrads);
  81.        
  82.         gravForce = (gravity*baseballMass)*(-1);
  83.         netForceX = fricFX;
  84.         netForceY = fricFY + gravForce;
  85.  
  86.         //continued
  87.         accelX = netForceX/baseballMass;
  88.         accelY = netForceY/baseballMass;
  89.  
  90.  
  91.         time = 1/100;
  92.  
  93.        //continued
  94.         finalVeloX = iniVeloXrads+(accelX*time);
  95.         finalVeloY = iniVeloYrads+(accelY*time);
  96.        
  97.        
  98.         velocity = Math.sqrt((finalVeloX*finalVeloX)+(finalVeloY*finalVeloY));
  99.        
  100.         x1 =  x1 + (finalVeloX*time + 0.5*accelX*Math.pow(time,2));
  101.         y1 =  y1 + (finalVeloY*time + 0.5*accelY*Math.pow(time,2));
  102.        
  103.         //totalDisplacement = totalDisplacement+x1;
  104.         angleNew = Math.toDegrees(Math.atan(finalVeloY/finalVeloX));
  105.        System.out.println(y1);
  106.        
  107.        
  108.        
  109.        
  110.     }
  111.     }
  112.    
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement