Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/arranger/jarl/test/AngleTest.java


1   package com.arranger.jarl.test;
2   
3   import junit.framework.TestCase;
4   
5   /**
6    * AngleTest created on Mar 1, 2003
7    */
8   public class AngleTest extends TestCase {
9   
10      public void testAngle() throws Exception {
11          double rad = findRadians(0, 0, -5, 0);
12          double degrees = Math.toDegrees(rad);
13  
14          System.out.println(degrees);
15      }
16  
17      protected double findRadians(double x1, double y1, double x2, double y2) {
18          if (x1 < x2 && y1 <= y2) {
19              double tmp = (y1 - y2) / (x1 - x2);
20              return Math.atan(tmp);
21          } else if (x1 >= x2 && y1 < y2) {
22              double tmp = (x1 - x2) / (y1 - y2);
23              return Math.atan(tmp) + (Math.PI / 2);
24          } else if (x1 > x2 && y1 >= y2) {
25              double tmp = (y1 - y2) / (x1 - x2);
26              return Math.atan(tmp) + Math.PI;
27          } else if (x1 <= x2 && y1 > y2) {
28              double tmp = (x1 - x2) / (y1 - y2);
29              return Math.atan(tmp) + (Math.PI  * 3 / 2);
30          }  else {
31              throw new IllegalStateException("idiot");
32          }
33      }
34  
35  }