1 |
|
2 | /**
|
3 | * @description 返回当前两点连成的线与Y轴的夹角
|
4 | * @author SoldierAb
|
5 | * @param {Number} 起始坐标x1,y1 当前坐标x2,y2
|
6 | * @returns {Object}
|
7 | * @example
|
8 | * ·
|
9 | * · ^ y
|
10 | * (x1,y1) * |
|
11 | * · |
|
12 | * · |
|
13 | * · |
|
14 | * · |
|
15 | * (x2,y2) * |
|
16 | * · |
|
17 | * -----------------------·-------------------------->
|
18 | * ·| O x
|
19 | * |
|
20 | * |·
|
21 | * |
|
22 | * |
|
23 | * |
|
24 | * |
|
25 | * |
|
26 | * |
|
27 | *
|
28 | *
|
29 | *
|
30 | *
|
31 | */
|
32 |
|
33 | export default (x1, y1, x2, y2) => {
|
34 | // 直角的边长
|
35 | let x = Math.abs(x1 - x2);
|
36 | let y = Math.abs(y1 - y2);
|
37 | // 斜边长
|
38 | let z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
|
39 | // 余弦
|
40 | let cos = y / z;
|
41 | // 弧度
|
42 | let radina = Math.acos(cos);
|
43 | // 角度
|
44 | let angle = 180 / (Math.PI / radina);
|
45 | return {
|
46 | angle: angle,
|
47 | xdis: x2 - x1,
|
48 | ydis: y2 - y1
|
49 | };
|
50 | } |
\ | No newline at end of file |