CPP
cpp
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
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
class wind {
public:
wind(float x, float y, int z)
: vs(x), aws(y), awd(z) { }
/* Calculating true wind speed
vs - vessel's speed, aws - apparent wind speed, awd - apparent wind direction, tws - true wind speed,
rwd - true relative wind direction */
float windSpeed (float vs, float aws, int awd) {
float tws; //tws - true wind speed
tws=sqrt(pow(vs,2)+pow(aws,2)-(2*vs*aws*cos(awd*0.0175)));
return tws;
}
/* Calculating true relative wind direction
vs - vessel's speed, aws - apparent wind speed, awd - apparent wind direction, tws - true wind speed,
rwd - true relative wind direction */
float windDir (float vs, float aws, float tws) {
float rwd; //rwd - apparent (relative) wind direction
rwd=acos((pow(aws,2)-pow(tws,2)-pow(vs,2))/(2*tws*vs))/0.0175;
return rwd;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run