From 9b79c0073a7108cd05ed49806a4affb45e9f1629 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@gmail.com>
Date: 星期三, 14 一月 2026 16:11:06 +0800
Subject: [PATCH] #
---
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java
index 21c0dfb..423b127 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java
@@ -1,10 +1,13 @@
package com.zy.acs.manager.core.service;
+import com.alibaba.fastjson.JSON;
import com.zy.acs.common.enums.AgvDirectionType;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.manager.core.constant.MapDataConstant;
+import com.zy.acs.manager.core.domain.DirectionDto;
import com.zy.acs.manager.core.domain.SortCodeDto;
import com.zy.acs.manager.core.domain.UnlockPathTask;
+import com.zy.acs.manager.core.domain.type.CodeDirectionType;
import com.zy.acs.manager.core.service.astart.*;
import com.zy.acs.manager.core.service.astart.domain.AStarNavigateNode;
import com.zy.acs.manager.core.service.astart.domain.DynamicNode;
@@ -36,6 +39,7 @@
@Component("mapService")
public class MapService {
+ private static final double EPS = 1e-7;
private final static int[][] DIRECTIONS = {{0,1},{0,-1},{-1,0},{1,0}};
@Value("${floyd.enable}")
@@ -422,6 +426,108 @@
return CodeSpinType.of(code.getSpin());
}
+ public static void main(String[] args) {
+ List<DirectionDto> directionDtoList = DirectionDto.initCodeDirections();
+ System.out.println(JSON.toJSONString(directionDtoList));
+ }
+
+ public CodeSpinType calcSpinDirection(Code code, Double currDir, Double nextDir) {
+ if (Cools.isEmpty(code, currDir, nextDir)) {
+ return CodeSpinType.NA;
+ }
+ List<Double> disableAngleList = new ArrayList<>();
+ List<DirectionDto> directionDtoList = DirectionDto.initCodeDirections();
+ for (DirectionDto dto : directionDtoList) {
+ if (null != dto.getEnabled() && !dto.getEnabled()) {
+ disableAngleList.add(dto.getAngle());
+ }
+ }
+
+ if (Cools.isEmpty(disableAngleList)) {
+ return CodeSpinType.NA;
+ }
+
+ double curr = norm360(currDir);
+ double next = norm360(nextDir);
+
+ // 濡傛灉鍑犱箮鐩哥瓑锛岃涓轰笉闇�瑕佹棆杞�
+ if (almostEqual(curr, next)) {
+ return CodeSpinType.NA;
+ }
+
+ double cwDelta = cwDelta(curr, next); // (0, 360)
+ double ccwDelta = 360.0 - cwDelta; // (0, 360)
+
+ boolean cwBlocked = false;
+ boolean ccwBlocked = false;
+
+ for (Double disableAngle : disableAngleList) {
+ if (disableAngle == null) continue;
+ double disable = norm360(disableAngle);
+
+ if (isOnArcCW(curr, next, disable)) {
+ cwBlocked = true;
+ }
+ if (isOnArcCCW(curr, next, disable)) {
+ ccwBlocked = true;
+ }
+ }
+
+ if (cwBlocked && !ccwBlocked) {
+ return CodeSpinType.CCW;
+ }
+ if (!cwBlocked && ccwBlocked) {
+ return CodeSpinType.CW;
+ }
+
+ return CodeSpinType.NA;
+ }
+
+ private static double norm360(double a) {
+ double x = a % 360.0;
+ if (x < 0) x += 360.0;
+ // 360 褰掍竴鍖栦负 0
+ if (almostEqual(x, 360.0)) return 0.0;
+ return x;
+ }
+
+ private static boolean almostEqual(double a, double b) {
+ return Math.abs(a - b) <= EPS;
+ }
+
+ /**
+ * 椤烘椂閽堣窛绂伙細浠� start 鍒� end锛屾部 CW 鏂瑰悜璧板灏戝害锛岃寖鍥� (0, 360]锛岃繖閲屼笉浼氳繑鍥� 0锛堥櫎闈炰綘 curr==next 宸叉彁鍓嶅鐞嗭級
+ */
+ private static double cwDelta(double start, double end) {
+ double d = end - start;
+ if (d < 0) d += 360.0;
+ if (almostEqual(d, 0.0)) return 0.0;
+ return d;
+ }
+
+ /**
+ * 鍒ゆ柇 angle 鏄惁钀藉湪浠� start -> end 鐨勯『鏃堕拡寮ф涓婏紙涓嶅惈绔偣锛夈��
+ * 鍗筹細娌� CW 浠� start 璧� cwDelta(start,end) 鐨勮矾寰勪笂鏄惁鈥滅粡杩団�漚ngle銆�
+ */
+ private static boolean isOnArcCW(double start, double end, double angle) {
+ double total = cwDelta(start, end);
+ // 寮ч暱涓� 0 琛ㄧず鏃犳棆杞紙宸叉彁鍓嶅鐞嗭級锛岃繖閲岀洿鎺� false
+ if (almostEqual(total, 0.0)) return false;
+
+ double a = cwDelta(start, angle);
+ // 涓嶅寘鍚鐐癸細a 鍦� (0, total) 涔嬮棿鎵嶇畻缁忚繃
+ return a > EPS && a < total - EPS;
+ }
+
+ /**
+ * 鍒ゆ柇 angle 鏄惁钀藉湪浠� start -> end 鐨勯�嗘椂閽堝姬娈典笂锛堜笉鍚鐐癸級銆�
+ * 閫嗘椂閽堢瓑浠蜂簬锛氶『鏃堕拡浠� end -> start 鐨勫姬娈点��
+ */
+ private static boolean isOnArcCCW(double start, double end, double angle) {
+ // 閫嗘椂閽� start->end == 椤烘椂閽� end->start
+ return isOnArcCW(end, start, angle);
+ }
+
/**
* That vehicle is walking if the dynamic node count > 1
*/
--
Gitblit v1.9.1