-
Notifications
You must be signed in to change notification settings - Fork 132
/
Vector.ts
44 lines (39 loc) · 893 Bytes
/
Vector.ts
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
export default class Vector {
public u: number;
public v: number;
public m: number;
constructor(u: number, v: number) {
this.u = u;
this.v = v;
this.m = this.magnitude();
}
/**
* 向量值(这里指风速)
* @returns {Number}
*/
public magnitude() {
return Math.sqrt(this.u ** 2 + this.v ** 2);
}
/**
* 流体方向 (这里指风向,范围为0-360º)
* N is 0º and E is 90º
* @returns {Number}
*/
public directionTo() {
const verticalAngle = Math.atan2(this.u, this.v);
let inDegrees = verticalAngle * (180.0 / Math.PI);
if (inDegrees < 0) {
inDegrees += 360.0;
}
return inDegrees;
}
/**
* Angle in degrees (0 to 360º) From x-->
* N is 0º and E is 90º
* @returns {Number}
*/
public directionFrom() {
const a = this.directionTo();
return (a + 180.0) % 360.0;
}
}