1   package org.wcb.e6b;
2   
3   /**
4    * Created by IntelliJ IDEA.
5    * User: wbogaardt
6    * Date: Aug 24, 2005
7    * Time: 1:01:00 PM
8    * To change this template use File | Settings | File Templates.
9    */
10  
11  public class HeadingGroundspeed extends AbstractE6B {
12  
13      private double trueCourse;
14      private double trueAirspeed;
15      private double windSpeed;
16      private double windDirection;
17  
18      private double trueHeading;
19      private double groundspeed;
20      private double wca;
21  
22      public double getTrueCourse() {
23          return trueCourse;
24      }
25  
26      public void setTrueCourse(int course) {
27          this.trueCourse = course;
28      }
29  
30      public double getTrueAirspeed() {
31          return trueAirspeed;
32      }
33  
34      public void setTrueAirspeed(int airspeed) {
35          this.trueAirspeed = airspeed;
36      }
37  
38      public double getWindSpeed() {
39          return windSpeed;
40      }
41  
42      public void setWindSpeed(int wspeed) {
43          this.windSpeed = wspeed;
44      }
45  
46      public double getWindDirection() {
47          return windDirection;
48      }
49  
50      public void setWindDirection(int wdirection) {
51          this.windDirection = wdirection;
52      }
53  
54      /**
55       * Calculations from http://www.pilotfriend.com/flightplanning/flight planning/calculators/whizzwheel.thm
56       *  http://www.pilotfriend.com/calcs/calculators/whizz.htm
57       */
58      public void calculate() {
59          double crs = Math.toRadians(trueCourse);
60          double wd = Math.toRadians(windDirection);
61          double swc = (windSpeed / trueAirspeed) * Math.sin(wd - crs);
62          if (Math.abs(swc) > 1)
63          {
64              System.out.println("Danger! ...course should not be flown..wind is too strong");
65          }
66          trueHeading = crs + Math.asin(swc);
67          if (trueHeading < 0)
68          {
69              trueHeading = trueHeading + 2 * Math.PI;
70          }
71          if (trueHeading > (2 * Math.PI))
72          {
73              trueHeading = trueHeading - 2 * Math.PI;
74          }
75          groundspeed = Math.round(trueAirspeed * Math.sqrt(1 - Math.pow(swc, 2)) - (windSpeed * Math.cos(wd - crs)));
76          wca = Math.atan2(windSpeed * Math.sin(trueHeading - wd), trueAirspeed - windSpeed * Math.cos(trueHeading - wd));
77          wca = Math.round((180 / Math.PI) * (wca * -1));  // 6/2/02 CED sign correction
78      }
79  
80      public long getHeading() {
81          return Math.round(Math.toDegrees(trueHeading));
82      }
83  
84      public double getGroundSpeed() {
85          return groundspeed;
86      }
87  
88      public double getWindCorrectionAngle() {
89          return wca;
90      }
91  }