1 package org.wcb.e6b;
2
3
4
5
6
7
8
9
10
11 public class UnknownWind extends AbstractE6B {
12
13 private double groundSpeed;
14 private double trueAirspeed;
15 private double course;
16 private double heading;
17 private double windDirection;
18 private double windSpeed;
19
20 public double getGroundSpeed() {
21 return groundSpeed;
22 }
23
24 public void setGroundSpeed(double gs) {
25 this.groundSpeed = gs;
26 }
27
28 public double getTrueAirspeed() {
29 return trueAirspeed;
30 }
31
32 public void setTrueAirspeed(double ta) {
33 this.trueAirspeed = ta;
34 }
35
36 public double getCourse() {
37 return course;
38 }
39
40 public void setCourse(double crs) {
41 this.course = crs;
42 }
43
44 public double getHeading() {
45 return heading;
46 }
47
48 public void setHeading(double hdg) {
49 this.heading = hdg;
50 }
51
52 public void calculate() {
53 double crs = Math.toRadians(this.course);
54 double hd = Math.toRadians(this.heading);
55 windSpeed = Math.sqrt(Math.pow(trueAirspeed - groundSpeed, 2) + 4 * trueAirspeed * groundSpeed * Math.pow(Math.sin((hd - crs) / 2), 2));
56 windDirection = crs + Math.atan2(trueAirspeed * Math.sin(hd - crs), trueAirspeed * Math.cos(hd - crs) - groundSpeed);
57 if (windDirection < 0)
58 {
59 windDirection = windDirection + 2 * Math.PI;
60 }
61 if (windDirection > 2 * Math.PI)
62 {
63 windDirection = windDirection - 2 * Math.PI;
64 }
65 windDirection = Math.toDegrees(windDirection);
66 }
67
68 public double getWindDirection() {
69 return Math.rint(windDirection);
70 }
71
72 public double getWindSpeed() {
73 return Math.rint(windSpeed);
74 }
75 }