Environment.java
4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package me.drton.jmavsim;
import javax.vecmath.Matrix3d;
import javax.vecmath.Vector3d;
/**
* User: ton Date: 28.11.13 Time: 20:35
*/
public abstract class Environment extends WorldObject implements ReportingObject {
protected Vector3d g = new Vector3d(); // gravity
protected Vector3d magField = new Vector3d();
protected Vector3d wind = new Vector3d(); // base wind speed
protected Vector3d windDeviation = new Vector3d(); // deviation magnitude
protected Vector3d windCurrent = new Vector3d(); // current wind conditions (base plus deviation)
protected double windT = 2.0;
protected double groundLevel = 0.0;
protected Float magIncl = 0.0f;
protected Float magDecl = 0.0f;
protected double magHIntensity;
protected double magTIntensity;
public Environment(World world) {
super(world);
}
public void report(StringBuilder builder) {
builder.append("ENVIRONMENT");
builder.append(newLine);
builder.append("===========");
builder.append(newLine);
builder.append("Grav: ");
builder.append(ReportUtil.vector2str(g));
builder.append(newLine);
builder.append("Mag: ");
builder.append(ReportUtil.vector2str(magField));
builder.append(newLine);
builder.append(String.format(" Incl: %.5f; Decl: %.5f", magIncl, magDecl));
builder.append(newLine);
builder.append(String.format(" H-Magn: %.5f; T-Magn: %.5f", magHIntensity, magTIntensity));
builder.append(newLine);
builder.append("Wind Set: ");
builder.append(ReportUtil.vector2str(wind));
builder.append(newLine);
builder.append("Wind Dev: ");
builder.append(ReportUtil.vector2str(windDeviation));
builder.append(newLine);
builder.append("Wind Cur: ");
builder.append(ReportUtil.vector2str(windCurrent));
builder.append(newLine);
builder.append(newLine);
}
public Vector3d getWind() {
return wind;
}
public void setWind(Vector3d wind) {
this.wind = wind;
}
public Vector3d getWindDeviation() {
return this.windDeviation;
}
public void setWindDeviation(Vector3d deviation) {
this.windDeviation = deviation;
}
/**
* Get wind (air velocity) vector in specified point.
*
* @param point point in NED frame
* @return wind vector
*/
public Vector3d getCurrentWind(Vector3d point) {
return windCurrent;
}
public void setCurrentWind(Vector3d wind) {
this.windCurrent = wind;
}
/**
* The base ground level member.
*/
public void setGroundLevel(double groundLevel) {
this.groundLevel = groundLevel;
}
public double getGroundLevel() {
return groundLevel;
}
/**
* Get ground level for specified point.
* Multilevel environment may be simulated, in this case method should return level under specified point.
*
* @param point point in NED frame
* @return ground level in NED frame
*/
public double getGroundLevelAt(Vector3d point) {
return getGroundLevel();
}
/**
* Get gravity vector.
* Should be pointed to ground.
*
* @return gravity vector
*/
public Vector3d getG() {
return g;
}
public void setG(Vector3d grav) {
if (grav == null) {
g = new Vector3d();
} else {
g = grav;
}
}
/**
* Get magnetic field vector in specified point.
*
* @param point point in NED frame
* @return magnetic field vector
*/
public Vector3d getMagField(Vector3d point) {
return magField;
}
/**
* Set magnetic field using specific vector.
*
* @param magField vector in NED frame
*/
public void setMagField(Vector3d magField) {
this.magField = magField;
magHIntensity = Math.sqrt(magField.x * magField.x + magField.y * magField.y);
magTIntensity = Math.sqrt(magHIntensity * magHIntensity + magField.z * magField.z);
magIncl = (float)Math.toDegrees(Math.atan2(magField.z, magField.x));
magDecl = (float)Math.toDegrees(Math.atan2(magField.y, magField.x));
}
/**
* Set magnetic field using specified inclination and declination
*
* @param incl Magnetic inclination in degrees
* @param decl Magnetic declination in degrees
*/
public void setMagFieldByInclDecl(double incl, double decl) {
decl = Math.toRadians(decl);
incl = Math.toRadians(incl);
Vector3d magField = new Vector3d(Math.cos(incl), 0.0f, Math.sin(incl));
Matrix3d declMtx = new Matrix3d();
declMtx.rotZ(decl);
declMtx.transform(magField);
setMagField(magField);
}
}