OatmealDome

Untitled

Mar 27th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.66 KB | None | 0 0
  1. public class EquationThingy
  2. {
  3.  
  4.     /**
  5.      * @param args the command line arguments
  6.      */
  7.     public static void main(String[] args)
  8.     {
  9.         //double y;
  10.         int r = 6371;
  11.         //testing iris equation
  12.  
  13.         //creating an array to store the lad + long data of each location
  14.         //toronto beijing, manilla cood
  15.         //postives  north and east
  16.         double cood[][] =
  17.         {
  18.             {
  19.                 43.6532, -79.3832
  20.             },
  21.             {
  22.                 39.9042, 116.4074
  23.             },
  24.             {
  25.                 14.5995, 120.9842
  26.             }
  27.         };
  28.         //using a loop that will loop until it gives a final answer.
  29.  
  30.         /*while (true)
  31.         {
  32.  
  33.             for (int i = 0; i < 3; i++)
  34.             {
  35.                 //converting the current coorindates into x y z
  36.  
  37.                 //calculate the x y and z
  38.                 x = r * Math.cos(cood[i][0]) * Math.cos(cood[i][1]);
  39.                 y = r * Math.cos(cood[i][0]) * Math.sin(cood[i][1]);
  40.                 z = r * Math.sin(cood[i][0]);
  41.  
  42.                 //this is the equation to get a value for y
  43.                 yans += Math.sqrt(Math.pow((x - fx), 2) + Math.pow((y - fy), 2) + Math.pow((z - fz), 2));
  44.             }
  45.             //increment the x y z
  46.             fx -= 1;
  47.             fy -= 1;
  48.             fz -= 1;
  49.            
  50.             System.out.println(yans);
  51.         }*/
  52.        
  53.         double a1, a2, a3;
  54.         double x = 10000d, y = 10000d, z = 10000d;
  55.         double answer = 0.0d;
  56.        
  57.         // loop until yans is as close to zero as we can get it
  58.         while (true)
  59.         {
  60.             double tempAnswer = 0.0d;
  61.            
  62.             for (int i = 0; i < 3; i++)
  63.             {
  64.                 //converting the current coorindates into x y z
  65.  
  66.                 //calculate the x y and z
  67.                 a1 = r * Math.cos(cood[i][0]) * Math.cos(cood[i][1]);
  68.                 a2 = r * Math.cos(cood[i][0]) * Math.sin(cood[i][1]);
  69.                 a3 = r * Math.sin(cood[i][0]);
  70.  
  71.                 //this is the equation to get a value for y
  72.                 tempAnswer += Math.sqrt(Math.pow((a1 - x), 2) + Math.pow((a2 - y), 2) + Math.pow((a3 - z), 2));
  73.             }
  74.            
  75.             if (tempAnswer <= 0)
  76.             {
  77.                 break;
  78.             }
  79.             else
  80.             {
  81.                 answer = tempAnswer;
  82.                
  83.                 // decrement x / y / z
  84.                 x--;
  85.                 y--;
  86.                 z--;
  87.             }
  88.         }
  89.        
  90.         System.out.printf("answer = %d, x = %d, y = %d, z = %d\n", answer, x, y, z);
  91.        
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment