View Javadoc

1   package org.catacomb.be;
2   
3   import org.catacomb.report.E;
4   
5   
6   
7   
8   public class Direction {
9   
10      double vx;
11      double vy;
12  
13      double cosine;
14      double sine;
15  
16  
17      public Direction(Direction d) {
18          this(d.getXCpt(), d.getYCpt());
19      }
20  
21  
22  
23      public Direction(double a, double b) {
24          vx = a;
25          vy = b;
26          double d = Math.sqrt(vx * vx + vy * vy);
27          if (d == 0.) {
28              d = 1.;
29              vx = 1;
30              E.warning("created direction with zero vector");
31          }
32          cosine = vx / d;
33          sine = vy / d;
34      }
35  
36  
37      public double getCosine() {
38          return cosine;
39      }
40  
41      public double getSine() {
42          return sine;
43      }
44  
45  
46      public double getXCpt() {
47          return vx;
48      }
49  
50  
51      public double getYCpt() {
52          return vy;
53      }
54  
55  
56      public Position destination(double d) {
57          return new Position(d * cosine, d* sine);
58      }
59  
60  
61      public static Direction fromTo(Position pa, Position pb) {
62          return new Direction(pb.getX() - pa.getX(), pb.getY() - pa.getY());
63      }
64  
65  }