|
@@ -119,7 +119,7 @@ export function convert_point_r2c(src_point, pRadar, angle) {
|
|
* @param {number} angle - 顺时针旋转角度 0, 90, 180, 270
|
|
* @param {number} angle - 顺时针旋转角度 0, 90, 180, 270
|
|
* @returns {Object} 旋转后的矩形 { left, top, width, height }
|
|
* @returns {Object} 旋转后的矩形 { left, top, width, height }
|
|
*/
|
|
*/
|
|
-export function rotateRect(src_rect, pRadar, angle) {
|
|
|
|
|
|
+export function rotateRect_cw(src_rect, pRadar, angle) {
|
|
if (![0, 90, 180, 270].includes(angle)) angle = 0
|
|
if (![0, 90, 180, 270].includes(angle)) angle = 0
|
|
|
|
|
|
const { left, top, width, height } = src_rect
|
|
const { left, top, width, height } = src_rect
|
|
@@ -169,80 +169,31 @@ export function rotateRect(src_rect, pRadar, angle) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- * 坐标系:x正轴朝右→, y正轴朝上↑
|
|
|
|
- * 将 src_point 绕 point 旋转 angle 度
|
|
|
|
- * @param {{x: number, y: number}} src_point - 原始点
|
|
|
|
- * @param {{x: number, y: number}} point - 旋转中心点
|
|
|
|
- * @param {number} angle - 旋转角度(度数)
|
|
|
|
- * @returns {{x: number, y: number}} - 旋转后的点
|
|
|
|
|
|
+ * 逆时针旋转矩形(家具/检测区域)
|
|
|
|
+ * @param {Object} src_rect - 输入矩形 { left, top, width, height }
|
|
|
|
+ * @param {Object} pRadar - 雷达中心坐标 { x, y }
|
|
|
|
+ * @param {number} angle - 逆时针旋转角度 0, 90, 180, 270
|
|
|
|
+ * @returns {Object} 旋转后的矩形 { left, top, width, height }
|
|
*/
|
|
*/
|
|
-export function rotatePoint(src_point, point, angle) {
|
|
|
|
- // console.log('rotatePoint 输入:', { src_point, point, angle });
|
|
|
|
- const rad = (-angle * Math.PI) / 180; // 顺时针旋转
|
|
|
|
- const cosA = Math.cos(rad);
|
|
|
|
- const sinA = Math.sin(rad);
|
|
|
|
-
|
|
|
|
- const x = src_point.x - point.x;
|
|
|
|
- const y = src_point.y - point.y;
|
|
|
|
-
|
|
|
|
- const xRot = x * cosA - y * sinA;
|
|
|
|
- const yRot = x * sinA + y * cosA;
|
|
|
|
-
|
|
|
|
- const result = {
|
|
|
|
- x: parseFloat((xRot + point.x).toFixed(6)),
|
|
|
|
- y: parseFloat((yRot + point.y).toFixed(6)),
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- // console.log('rotatePoint 返回:', result);
|
|
|
|
- return result;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 正向保存家具的方法
|
|
|
|
-
|
|
|
|
-// 从画布坐标系(c)转换为雷达坐标系(r)
|
|
|
|
-export function convert_furniture_save(furniture, p_radar) {
|
|
|
|
- const x = furniture.left - p_radar.x;
|
|
|
|
- const y = p_radar.y - furniture.top;
|
|
|
|
- const width = furniture.width;
|
|
|
|
- const length = furniture.length;
|
|
|
|
-
|
|
|
|
- return {
|
|
|
|
- x,
|
|
|
|
- y,
|
|
|
|
- width,
|
|
|
|
- length
|
|
|
|
- };
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 反向旋转:将画布坐标系的矩形,按指定角度反旋转回雷达坐标
|
|
|
|
-// 把画布坐标的家具位置旋转回雷达坐标系(用于保存)
|
|
|
|
-
|
|
|
|
-export function rotateRectReverse(src_rect, pRadar, angle) {
|
|
|
|
- console.log('rotateRectReverse 输入:', { src_rect, pRadar, angle });
|
|
|
|
|
|
+export function rotateRect_ccw(src_rect, pRadar, angle) {
|
|
if (![0, 90, 180, 270].includes(angle)) angle = 0;
|
|
if (![0, 90, 180, 270].includes(angle)) angle = 0;
|
|
|
|
|
|
- // ✅ 注意这里要用 length
|
|
|
|
- let { x, y, width, length } = src_rect;
|
|
|
|
|
|
+ const { left, top, width, height } = src_rect;
|
|
|
|
+ const cx = left + width / 2;
|
|
|
|
+ const cy = top + height / 2;
|
|
|
|
|
|
- // 计算中心点
|
|
|
|
- const cx = pRadar.x + x + width / 2;
|
|
|
|
- const cy = pRadar.y - y - length / 2;
|
|
|
|
|
|
+ const dx = cx - pRadar.x;
|
|
|
|
+ const dy = cy - pRadar.y;
|
|
|
|
|
|
- // 相对雷达点偏移
|
|
|
|
- let dx = cx - pRadar.x;
|
|
|
|
- let dy = cy - pRadar.y;
|
|
|
|
let new_dx, new_dy;
|
|
let new_dx, new_dy;
|
|
|
|
|
|
- // 与 rotateRect 方向相反(逆旋转)
|
|
|
|
switch (angle) {
|
|
switch (angle) {
|
|
case 0:
|
|
case 0:
|
|
new_dx = dx;
|
|
new_dx = dx;
|
|
new_dy = dy;
|
|
new_dy = dy;
|
|
break;
|
|
break;
|
|
- case 90: // 原来顺时针90°,现在逆时针90°
|
|
|
|
|
|
+ case 90: // 逆时针 90°
|
|
new_dx = dy;
|
|
new_dx = dy;
|
|
new_dy = -dx;
|
|
new_dy = -dx;
|
|
break;
|
|
break;
|
|
@@ -250,7 +201,7 @@ export function rotateRectReverse(src_rect, pRadar, angle) {
|
|
new_dx = -dx;
|
|
new_dx = -dx;
|
|
new_dy = -dy;
|
|
new_dy = -dy;
|
|
break;
|
|
break;
|
|
- case 270: // 原来顺时针270°(=逆时针90°)
|
|
|
|
|
|
+ case 270: // 逆时针 270° = 顺时针 90°
|
|
new_dx = -dy;
|
|
new_dx = -dy;
|
|
new_dy = dx;
|
|
new_dy = dx;
|
|
break;
|
|
break;
|
|
@@ -259,23 +210,49 @@ export function rotateRectReverse(src_rect, pRadar, angle) {
|
|
const new_cx = pRadar.x + new_dx;
|
|
const new_cx = pRadar.x + new_dx;
|
|
const new_cy = pRadar.y + new_dy;
|
|
const new_cy = pRadar.y + new_dy;
|
|
|
|
|
|
- // 对于 90/270,宽高要交换回来
|
|
|
|
let new_width = width;
|
|
let new_width = width;
|
|
- let new_length = length;
|
|
|
|
|
|
+ let new_height = height;
|
|
if (angle === 90 || angle === 270) {
|
|
if (angle === 90 || angle === 270) {
|
|
- new_width = length;
|
|
|
|
- new_length = width;
|
|
|
|
|
|
+ new_width = height;
|
|
|
|
+ new_height = width;
|
|
}
|
|
}
|
|
|
|
|
|
- // ⚠️ 注意:这里是雷达坐标系
|
|
|
|
- const new_x = new_cx - pRadar.x;
|
|
|
|
- const new_y = pRadar.y - new_cy;
|
|
|
|
-
|
|
|
|
return {
|
|
return {
|
|
- x: new_x,
|
|
|
|
- y: new_y,
|
|
|
|
|
|
+ left: new_cx - new_width / 2,
|
|
|
|
+ top: new_cy - new_height / 2,
|
|
width: new_width,
|
|
width: new_width,
|
|
- length: new_length
|
|
|
|
|
|
+ height: new_height
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 坐标系:x正轴朝右→, y正轴朝上↑
|
|
|
|
+ * 将 src_point 绕 point 旋转 angle 度
|
|
|
|
+ * @param {{x: number, y: number}} src_point - 原始点
|
|
|
|
+ * @param {{x: number, y: number}} point - 旋转中心点
|
|
|
|
+ * @param {number} angle - 旋转角度(度数)
|
|
|
|
+ * @returns {{x: number, y: number}} - 旋转后的点
|
|
|
|
+ */
|
|
|
|
+export function rotatePoint(src_point, point, angle) {
|
|
|
|
+ // console.log('rotatePoint 输入:', { src_point, point, angle });
|
|
|
|
+ const rad = (-angle * Math.PI) / 180; // 顺时针旋转
|
|
|
|
+ const cosA = Math.cos(rad);
|
|
|
|
+ const sinA = Math.sin(rad);
|
|
|
|
+
|
|
|
|
+ const x = src_point.x - point.x;
|
|
|
|
+ const y = src_point.y - point.y;
|
|
|
|
+
|
|
|
|
+ const xRot = x * cosA - y * sinA;
|
|
|
|
+ const yRot = x * sinA + y * cosA;
|
|
|
|
+
|
|
|
|
+ const result = {
|
|
|
|
+ x: parseFloat((xRot + point.x).toFixed(6)),
|
|
|
|
+ y: parseFloat((yRot + point.y).toFixed(6)),
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // console.log('rotatePoint 返回:', result);
|
|
|
|
+ return result;
|
|
|
|
+}
|
|
|
|
+
|