lyb-js 1.6.5 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Math/LibJsCoordsAngle.d.ts +1 -1
- package/Math/LibJsCoordsAngle.js +12 -9
- package/libJs.d.ts +1 -1
- package/lyb.js +9 -6
- package/package.json +1 -1
package/Math/LibJsCoordsAngle.js
CHANGED
|
@@ -3,19 +3,22 @@
|
|
|
3
3
|
* @param coord2 终点坐标
|
|
4
4
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCoordsAngle-两点角度
|
|
5
5
|
*/
|
|
6
|
-
export const libJsCoordsAngle = (coord1, coord2) => {
|
|
6
|
+
export const libJsCoordsAngle = (coord1, coord2, mode = "deg") => {
|
|
7
7
|
//计算相对于第一个坐标的水平和垂直距离
|
|
8
8
|
const deltaX = coord2.x - coord1.x;
|
|
9
9
|
const deltaY = coord2.y - coord1.y;
|
|
10
10
|
//使用反三角函数计算角度(以弧度为单位)
|
|
11
11
|
const angleRad = Math.atan2(deltaY, deltaX);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
angleDeg
|
|
12
|
+
if (mode === "deg") {
|
|
13
|
+
//将弧度转换为角度
|
|
14
|
+
let angleDeg = angleRad * (180 / Math.PI);
|
|
15
|
+
//将角度转换为顺时针方向为正方向的角度
|
|
16
|
+
angleDeg = -angleDeg + 90;
|
|
17
|
+
//调整角度使得右边成为 360 度的位置变为 0 度
|
|
18
|
+
if (angleDeg < 0) {
|
|
19
|
+
angleDeg += 360;
|
|
20
|
+
}
|
|
21
|
+
return angleDeg;
|
|
19
22
|
}
|
|
20
|
-
return
|
|
23
|
+
return angleRad;
|
|
21
24
|
};
|
package/libJs.d.ts
CHANGED
package/lyb.js
CHANGED
|
@@ -284,16 +284,19 @@ ${log3.label}:`, log3.value];
|
|
|
284
284
|
throw new Error("请使用正确类型");
|
|
285
285
|
}
|
|
286
286
|
};
|
|
287
|
-
const libJsCoordsAngle = (coord1, coord2) => {
|
|
287
|
+
const libJsCoordsAngle = (coord1, coord2, mode = "deg") => {
|
|
288
288
|
const deltaX = coord2.x - coord1.x;
|
|
289
289
|
const deltaY = coord2.y - coord1.y;
|
|
290
290
|
const angleRad = Math.atan2(deltaY, deltaX);
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
angleDeg
|
|
291
|
+
if (mode === "deg") {
|
|
292
|
+
let angleDeg = angleRad * (180 / Math.PI);
|
|
293
|
+
angleDeg = -angleDeg + 90;
|
|
294
|
+
if (angleDeg < 0) {
|
|
295
|
+
angleDeg += 360;
|
|
296
|
+
}
|
|
297
|
+
return angleDeg;
|
|
295
298
|
}
|
|
296
|
-
return
|
|
299
|
+
return angleRad;
|
|
297
300
|
};
|
|
298
301
|
const libJsCoordsDistance = (coord1, coord2) => {
|
|
299
302
|
const deltaX = coord2.x - coord1.x;
|