Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EquationThingy
- {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- //double y;
- int r = 6371;
- //testing iris equation
- //creating an array to store the lad + long data of each location
- //toronto beijing, manilla cood
- //postives north and east
- double cood[][] =
- {
- {
- 43.6532, -79.3832
- },
- {
- 39.9042, 116.4074
- },
- {
- 14.5995, 120.9842
- }
- };
- //using a loop that will loop until it gives a final answer.
- /*while (true)
- {
- for (int i = 0; i < 3; i++)
- {
- //converting the current coorindates into x y z
- //calculate the x y and z
- x = r * Math.cos(cood[i][0]) * Math.cos(cood[i][1]);
- y = r * Math.cos(cood[i][0]) * Math.sin(cood[i][1]);
- z = r * Math.sin(cood[i][0]);
- //this is the equation to get a value for y
- yans += Math.sqrt(Math.pow((x - fx), 2) + Math.pow((y - fy), 2) + Math.pow((z - fz), 2));
- }
- //increment the x y z
- fx -= 1;
- fy -= 1;
- fz -= 1;
- System.out.println(yans);
- }*/
- double a1, a2, a3;
- double x = 10000d, y = 10000d, z = 10000d;
- double answer = 0.0d;
- // loop until yans is as close to zero as we can get it
- while (true)
- {
- double tempAnswer = 0.0d;
- for (int i = 0; i < 3; i++)
- {
- //converting the current coorindates into x y z
- //calculate the x y and z
- a1 = r * Math.cos(cood[i][0]) * Math.cos(cood[i][1]);
- a2 = r * Math.cos(cood[i][0]) * Math.sin(cood[i][1]);
- a3 = r * Math.sin(cood[i][0]);
- //this is the equation to get a value for y
- tempAnswer += Math.sqrt(Math.pow((a1 - x), 2) + Math.pow((a2 - y), 2) + Math.pow((a3 - z), 2));
- }
- if (tempAnswer <= 0)
- {
- break;
- }
- else
- {
- answer = tempAnswer;
- // decrement x / y / z
- x--;
- y--;
- z--;
- }
- }
- System.out.printf("answer = %d, x = %d, y = %d, z = %d\n", answer, x, y, z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment