{"id":5975,"date":"2025-03-03T17:36:31","date_gmt":"2025-03-03T09:36:31","guid":{"rendered":"https:\/\/www.hightopo.com\/blog\/?p=5975"},"modified":"2025-03-03T17:36:31","modified_gmt":"2025-03-03T09:36:31","slug":"%e5%9b%be%e6%89%91%e8%bd%af%e4%bb%b6-%e6%80%bb%e7%ba%bf%e5%bc%8f%e6%8b%93%e6%89%91%e5%9b%be%e7%9a%84%e5%8f%af%e8%a7%86%e5%8c%96%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.hightopo.com\/blog\/5975.html","title":{"rendered":"\u56fe\u6251\u8f6f\u4ef6 | \u603b\u7ebf\u5f0f\u62d3\u6251\u56fe\u7684\u53ef\u89c6\u5316\u5b9e\u73b0"},"content":{"rendered":"\n<p>\u5728\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u8bbe\u8ba1\u4e2d\uff0c\u81ea\u5b9a\u4e49\u8fde\u7ebf\u6280\u672f\u4e0d\u4ec5\u63d0\u5347\u4e86\u7528\u6237\u4f53\u9a8c\uff0c\u8fd8\u4e3a\u590d\u6742\u6570\u636e\u53ef\u89c6\u5316\u5f00\u8f9f\u4e86\u65b0\u7684\u53ef\u80fd\u6027\u3002<strong>\u8be5\u529f\u80fd\u70b9\u5141\u8bb8\u7528\u6237\u7075\u6d3b\u5730\u5728\u754c\u9762\u5143\u7d20\u4e4b\u95f4\u521b\u5efa\u89c6\u89c9\u8fde\u63a5\uff0c\u4f7f\u6d41\u7a0b\u56fe\u3001\u601d\u7ef4\u5bfc\u56fe\u548c\u7f51\u7edc\u62d3\u6251\u56fe\u7b49\u4fe1\u606f\u5448\u73b0\u66f4\u52a0\u76f4\u89c2\u548c\u52a8\u6001\u3002<\/strong><\/p>\n\n\n\n<h1>\u6548\u679c\u5c55\u793a<\/h1>\n\n\n\n<p>\u56fe\u6251\u8f6f\u4ef6\u81ea\u7814 HT for Web \u4ea7\u54c1\u6846\u67b6\u4e2d\uff0cht.Edge \u8282\u70b9\u7528\u4e8e\u8868\u793a\u8282\u70b9\u95f4\u7684\u8fde\u7ebf\u5173\u7cfb\u3002\u719f\u6089 HT \u7684\u7528\u6237\u5e94\u8be5\u4e86\u89e3 ht.Edge \u5185\u7f6e\u4e86\u591a\u79cd\u8fde\u7ebf\u7c7b\u578b\uff0c\u80fd\u6ee1\u8db3\u4e00\u822c\u62d3\u6251\u56fe\u9700\u6c42\uff0c\u4f46\u5728\u7279\u6b8a\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e9b\u9ed8\u8ba4\u7c7b\u578b\u53ef\u80fd\u65e0\u6cd5\u6ee1\u8db3\u9700\u6c42\u3002\u4e3a\u6b64\uff0c<strong>HT <\/strong><strong>\u63d0\u4f9b\u4e86\u81ea\u5b9a\u4e49\u8fde\u7ebf\u529f\u80fd\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u6839\u636e\u5177\u4f53\u9700\u6c42\u521b\u5efa\u7279\u6b8a\u7684\u8fde\u7ebf\u7c7b\u578b\uff0c\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u56fe\u5f62\u8868\u793a\u3002<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640.gif\"><img loading=\"lazy\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640.gif\" alt=\"\" class=\"wp-image-5977\" width=\"640\" height=\"360\"\/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-1-1.gif\"><img loading=\"lazy\" width=\"640\" height=\"360\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-1-1.gif\" alt=\"\" class=\"wp-image-5978\"\/><\/a><\/figure>\n\n\n\n<h1>\u7cfb\u7edf\u5206\u6790<\/h1>\n\n\n\n<h1>\u81ea\u5b9a\u4e49\u8fde\u7ebf<\/h1>\n\n\n\n<p>\u56fe\u6251 HT \u6846\u67b6\u63d0\u4f9b\u7075\u6d3b\u7684\u81ea\u5b9a\u4e49\u8fde\u7ebf\u529f\u80fd\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528 ht.Default.setEdgeType(type, func, mutual) \u65b9\u6cd5\u6765\u521b\u5efa\u72ec\u7279\u7684\u8fde\u7ebf\u7c7b\u578b\u3002\u4ee5\u4e0b\u662f\u8be5\u65b9\u6cd5\u7684\u53c2\u6570\u8be6\u89e3\uff1a<\/p>\n\n\n\n<p><strong>type\uff1a<\/strong>\u81ea\u5b9a\u4e49\u8fde\u7ebf\u7c7b\u578b\u7684\u540d\u79f0\uff0c\u4e0e style \u4e2d\u7684 edge.type \u5c5e\u6027\u76f8\u5bf9\u5e94\u3002<\/p>\n\n\n\n<p><strong>func\uff1a<\/strong>\u8ba1\u7b97\u8fde\u7ebf\u8def\u5f84\u4fe1\u606f\u7684\u51fd\u6570\uff0c\u63a5\u6536\u56db\u4e2a\u53c2\u6570\uff1a<\/p>\n\n\n\n<p>gap\uff1a\u591a\u6761\u8fde\u7ebf\u6210\u6346\u65f6\uff0c\u672c\u8fde\u7ebf\u5bf9\u8c61\u5bf9\u5e94\u4e2d\u5fc3\u8fde\u7ebf\u7684\u95f4\u8ddd\u3002<\/p>\n\n\n\n<p>edge\uff1a\u5f53\u524d\u8fde\u7ebf\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>graphView\uff1a\u5f53\u524d\u5bf9\u5e94\u62d3\u6251\u7ec4\u4ef6\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>sameSourceWithFirstEdge\uff1aboolean \u7c7b\u578b\uff0c\u8be5\u8fde\u7ebf\u662f\u5426\u4e0e\u540c\u7ec4\u7684\u7b2c\u4e00\u6761\u8fde\u7ebf\u540c\u6e90\u3002<\/p>\n\n\n\n<p><strong>mutual\uff1a<\/strong>\u51b3\u5b9a\u8be5\u8fde\u7ebf\u7c7b\u578b\u662f\u5426\u4f1a\u5f71\u54cd\u540c\u4e00\u8d77\u59cb\u6216\u7ed3\u675f\u8282\u70b9\u4e0a\u7684\u5176\u4ed6\u8fde\u7ebf\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u6df1\u5165\u5206\u6790\u4e00\u79cd\u5e38\u89c1\u7684\u62d3\u6251\u5173\u7cfb\u5b9e\u73b0\u6b65\u9aa4\uff0c\u5373&#8221;\u6a2a-\u7ad6-\u6a2a&#8221;\u7684\u8fde\u7ebf\u65b9\u5f0f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-2.gif\"><img loading=\"lazy\" width=\"800\" height=\"394\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-2.gif\" alt=\"\" class=\"wp-image-5979\"\/><\/a><\/figure>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u6bb5\u5b9a\u4e49\u4e0a\u56fe\u8fde\u7ebf\u7c7b\u578b\u7684\u793a\u4f8b\u4ee3\u7801\u3002\u4ee3\u7801\u5f88\u7b80\u5355\uff0c\u9996\u5148\u83b7\u53d6\u8d77\u59cb\u8282\u70b9\u548c\u76ee\u6807\u8282\u70b9\u7684\u4fe1\u606f\uff0c\u7136\u540e\u6839\u636e\u8fd9\u4e24\u4e2a\u8282\u70b9\u7684\u5750\u6807\uff0c\u6309\u7167\u9884\u5b9a\u7684\u89c4\u5219\u8ba1\u7b97\u51fa\u8fde\u7ebf\u7684\u8def\u5f84\u70b9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ht.Default.setEdgeType('horizontal-vertical', function (edge, gap, graphView) {\n    const points = new ht.List();\n    const segments = new ht.List();\n    const source = edge.getSource();\n    const target = edge.getTarget();\n    const sourceP = source.p();\n    const targetP = target.p();\n    points.add(sourceP);\n    if (targetP.x !== sourceP.x) {\n        points.add({ x: sourceP.x + (targetP.x - sourceP.x) \/ 2, y: sourceP.y });\n        points.add({ x: sourceP.x + (targetP.x - sourceP.x) \/ 2, y: targetP.y });\n    }\n    points.add(targetP);\n    return { points, segments };\n})<\/code><\/pre>\n\n\n\n<p>\u5b9a\u4e49\u597d\u8fde\u7ebf\u7c7b\u578b\u540e\uff0c\u53ea\u9700\u901a\u8fc7 edge.s(&#8216;edge.type&#8217;, &#8216;horizontal-vertical&#8217;) \u8fd9\u6bb5\u7b80\u5355\u7684\u4ee3\u7801\u884c\uff0c\u5c31\u80fd\u5c06 edge \u5bf9\u8c61\u7684\u8fde\u7ebf\u8bbe\u7f6e\u4e3a\u6211\u4eec\u521a\u521a\u5b9a\u4e49\u7684\u7c7b\u578b\u3002\u7531\u6b64\u4e00\u6765\uff0c\u5373\u53ef\u770b\u5230\u4ee4\u4eba\u6ee1\u610f\u7684\u6548\u679c\uff0c\u5927\u5e45\u63d0\u5347\u56fe\u5f62\u7684\u53ef\u8bfb\u6027\u548c\u7f8e\u89c2\u5ea6\u3002<\/p>\n\n\n\n<h1>\u603b\u7ebf\u62d3\u6251<\/h1>\n\n\n\n<p>\u603b\u7ebf\u62d3\u6251\u662f\u4e00\u79cd\u7f51\u7edc\u7ed3\u6784\uff0c\u6240\u6709\u8bbe\u5907\uff08\u5982\u8ba1\u7b97\u673a\u3001\u6253\u5370\u673a\u7b49\uff09\u90fd\u8fde\u63a5\u5230\u4e00\u4e2a\u5171\u540c\u7684\u901a\u4fe1\u4ecb\u8d28\u4e0a\uff0c\u901a\u5e38\u662f\u4e00\u6839\u7535\u7f06\uff0c\u8fd9\u4e2a\u4ecb\u8d28\u88ab\u79f0\u4e3a&#8221;\u603b\u7ebf&#8221;\uff08bus\uff09\u3002<strong>\u603b\u7ebf\u62d3\u6251\u5728\u5de5\u4e1a\u63a7\u5236\u548c\u5d4c\u5165\u5f0f\u7cfb\u7edf\u7b49\u7279\u5b9a\u9886\u57df\u4e2d\u88ab\u5e7f\u6cdb\u5e94\u7528\u3002<\/strong>\u5728\u56fe\u6251 HT \u6846\u67b6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528 ht.Shape \u7ec4\u4ef6\u7ed8\u5236\u603b\u7ebf\uff0c\u5e76\u901a\u8fc7 ht.Edge \u7ec4\u4ef6\u5c06\u5404\u4e2a\u8bbe\u5907\u8282\u70b9\u8fde\u63a5\u5230\u603b\u7ebf\u4e0a\u3002\u8fd9\u4e9b\u8fde\u63a5\u7684\u89c6\u89c9\u8868\u73b0\u53ef\u901a\u8fc7<strong>\u81ea\u5b9a\u4e49\u8fde\u7ebf\u7c7b\u578b\u7075\u6d3b\u5b9a\u4e49<\/strong>\uff0c\u4ece\u800c\u5b9e\u73b0\u7cbe\u786e\u7684\u603b\u7ebf\u62d3\u6251\u56fe\u8868\u793a\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-3.gif\"><img loading=\"lazy\" width=\"800\" height=\"394\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-3.gif\" alt=\"\" class=\"wp-image-5980\"\/><\/a><\/figure>\n\n\n\n<p>\u4e0a\u9762\u5c55\u793a\u7684\u662f\u4e00\u4e2a\u603b\u7ebf\u7684\u793a\u4f8b\u6548\u679c\uff0c\u53ef\u4ee5\u76f4\u89c2\u770b\u5230\u6240\u6709\u8bbe\u5907\u90fd\u8fde\u63a5\u5230\u4e86\u603b\u7ebf\u4e0a\u3002\u5728\u5177\u4f53\u5b9e\u73b0\u8fc7\u7a0b\u4e2d\uff0c\u6700\u5177\u6311\u6218\u6027\u7684\u95ee\u9898\u662f\uff1a\u5982\u4f55\u8ba1\u7b97\u51fa\u603b\u7ebf\u4e0a\u8ddd\u79bb\u76ee\u6807\u8282\u70b9\u5750\u6807\u6700\u8fd1\u7684\u70b9?<\/p>\n\n\n\n<p><strong>\u8ba1\u7b97\u8282\u70b9\u5230\u603b\u7ebf\u8ddd\u79bb<\/strong><\/p>\n\n\n\n<p>\u603b\u7ebf\u901a\u5e38\u7531\u591a\u6761\u76f4\u7ebf\u6bb5\u7ec4\u6210\uff0c\u56e0\u6b64\u8ba1\u7b97\u67d0\u4e00\u8282\u70b9\u5230\u603b\u7ebf\u7684\u6700\u77ed\u8ddd\u79bb\u53ef\u6309\u4ee5\u4e0b\u601d\u8def\u8fdb\u884c\uff1a<\/p>\n\n\n\n<p><strong>\u5c06\u603b\u7ebf\u5206\u5272\u4e3a\u591a\u6bb5\u76f4\u7ebf<\/strong><\/p>\n\n\n\n<p>\u603b\u7ebf\u7531\u591a\u4e2a\u76f4\u7ebf\u6bb5\u6784\u6210\uff0c\u53ef\u4ee5\u53d6\u603b\u7ebf\u4e0a\u76f8\u90bb\u4e24\u70b9\u6784\u6210\u4e00\u6761\u76f4\u7ebf\u3002\u5177\u4f53\u5b9e\u73b0\u65f6\uff0c\u904d\u5386 points \u6570\u636e\uff0c\u83b7\u53d6 points[index] \u548c points[index+1] \u4f5c\u4e3a\u7ebf\u6bb5\u7684\u4e24\u4e2a\u7aef\u70b9\u3002\u6ce8\u610f\uff0c\u5982\u679c\u8bbe\u7f6e\u4e86 segments\uff0c\u5176\u4e2d 1 \u4ee3\u8868\u65b0\u8def\u5f84\u7684\u8d77\u70b9\uff0c\u6240\u4ee5\u5f53 segments[index+1] \u4e3a 1 \u65f6\u5e94\u8df3\u8fc7\u3002<\/p>\n\n\n\n<p><strong>\u8ba1\u7b97\u70b9\u5230\u6bcf\u6761\u76f4\u7ebf\u7684\u8ddd\u79bb<\/strong><\/p>\n\n\n\n<p>\u83b7\u53d6\u6bcf\u6761\u76f4\u7ebf\u6bb5\u540e\uff0c\u8ba1\u7b97\u8282\u70b9\u5750\u6807\u5230\u5404\u7ebf\u6bb5\u7684\u8ddd\u79bb\uff0c\u5e76\u5c06<strong>\u8ddd\u79bb\u503c\u5b58\u5165\u4e00\u4e2a\u96c6\u5408\u4e2d<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u83b7\u53d6\u6700\u77ed\u8ddd\u79bb<\/strong><\/p>\n\n\n\n<p>\u4ece\u8ddd\u79bb\u96c6\u5408\u4e2d\u627e\u51fa<strong>\u6700\u5c0f\u503c<\/strong>\uff0c\u5373\u4e3a\u8282\u70b9\u5230\u603b\u7ebf\u7684\u6700\u77ed\u8ddd\u79bb\u3002<\/p>\n\n\n\n<p>\u57fa\u4e8e\u4e0a\u8ff0\u601d\u8def\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2a\u603b\u7ebf\u8fde\u7ebf\u7c7b\u578b\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u7684\u5b9e\u73b0\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u8ba1\u7b97\u70b9\u5230\u76f4\u7ebf\u7684\u8ddd\u79bb\uff0c\u8fd4\u56de\u7ed3\u679c\u662f\u4e2a\u5bf9\u8c61\u7ed3\u6784\nvar pointToInsideLine = function (p1, p2, p) {\n     var x1 = p1.x,\n         y1 = p1.y,\n         x2 = p2.x,\n         y2 = p2.y,\n         x = p.x,\n         y = p.y,\n         result = {},\n         dx = x2 - x1,\n         dy = y2 - y1,\n         d = Math.sqrt(dx * dx + dy * dy),\n         ca = dx \/ d, \/\/ cosine\n         sa = dy \/ d, \/\/ sine\n         mX = (-x1 + x) * ca + (-y1 + y) * sa;\n    result.x = x1 + mX * ca;\n    result.y = y1 + mX * sa;\n    if (!isPointInLine(result, p1, p2)) {\n           result.x = Math.abs(result.x - p1.x) &lt; Math.abs(result.x - p2.x) ? p1.x : p2.x;\n           result.y = Math.abs(result.y - p1.y) &lt; Math.abs(result.y - p2.y) ? p1.y : p2.y;\n    }\n    dx = x - result.x;\n    dy = y - result.y;\n    result.z = Math.sqrt(dx * dx + dy * dy);\n    return result;\n};\n\/\/ \u5224\u65ad\u70b9\u662f\u5426\u5728\u7ebf\u4e0a\nvar isPointInLine = function (p, p1, p2) {\n     return p.x &gt;= Math.min(p1.x, p2.x) &amp;&amp;\n          p.x &lt;= Math.max(p1.x, p2.x) &amp;&amp;\n          p.y &gt;= Math.min(p1.y, p2.y) &amp;&amp;\n          p.y &lt;= Math.max(p1.y, p2.y);\n};\n\/\/ \u6ce8\u518c\u8fde\u7ebf\u7c7b\u578b\nht.Default.setEdgeType('bus', function (edge) {\n    var source = edge.getSourceAgent(),\n        target = edge.getTargetAgent();\n\n\n    var targetP = target.p();\n    var points = source.getPoints().toArray();\n    var segments = source.getSegments();\n    var beginPoint;\n    for (let i = 0; i &lt; points.length - 1; i++) {\n        if (segments) {\n            if (segments&#91;i + 1] === 1) continue;\n        }\n        const point1 = points&#91;i];\n        const point2 = points&#91;i + 1];\n        const minPosition = pointToInsideLine(point1, point2, targetP);\n        if (!beginPoint || minPosition.z &lt; beginPoint.z) {\n            beginPoint = minPosition;\n        }\n    }\n    return {\n        points: new ht.List(&#91; beginPoint, targetP ]),\n        segments: new ht.List(&#91;1, 2])\n    };\n});<\/code><\/pre>\n\n\n\n<p>\u6267\u884c\u4e0a\u8ff0\u4ee3\u7801\u540e\uff0c\u6211\u4eec\u5c06\u5f97\u5230\u5982\u4e0b\u6548\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-4.gif\"><img loading=\"lazy\" width=\"640\" height=\"315\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-4.gif\" alt=\"\" class=\"wp-image-5981\"\/><\/a><\/figure>\n\n\n\n<p>\u4ece\u4e0a\u56fe\u53ef\u4ee5\u6e05\u695a\u770b\u51fa\uff0c\u793a\u4f8b\u6210\u529f\u83b7\u53d6\u4e86\u8282\u70b9\u5230\u603b\u7ebf\u7684\u6700\u8fd1\u70b9\uff0c\u5e76\u7ed8\u5236\u4e86\u76f8\u5e94\u7684\u8fde\u7ebf\u8282\u70b9\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5bf9\u4e8e\u76f4\u7ebf\u6bb5\u800c\u8a00\uff0c\u8282\u70b9\u5728\u76f4\u7ebf\u4e0a\u7684\u6295\u5f71\u70b9\u5373\u4e3a\u5176\u8ddd\u603b\u7ebf\u6700\u8fd1\u7684\u70b9\u3002<\/p>\n\n\n\n<p><strong>\u89c6\u89c9\u7f8e\u611f\u4f18\u5316<\/strong><\/p>\n\n\n\n<p>\u867d\u7136\u793a\u4f8b\u5df2\u5b9e\u73b0\u4e86\u57fa\u7840\u603b\u7ebf\u6548\u679c\uff0c\u4f46\u7531\u4e8e\u62d3\u6251\u56fe\u91c7\u7528 2.5D \u6548\u679c\uff0c\u4ec5\u8ba1\u7b97\u6295\u5f71\u70b9\u53ef\u80fd\u65e0\u6cd5\u5448\u73b0\u7406\u60f3\u7684\u89c6\u89c9\u6548\u679c\u3002<strong>\u4e3a\u4e86\u589e\u5f3a\u89c6\u89c9\u8868\u73b0\uff0c\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u8ba9\u8fde\u7ebf\u65cb\u8f6c\u4e00\u5b9a\u89d2\u5ea6\u3002<\/strong>\u4e3a\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u73b0\u6709\u529f\u80fd\u7684<strong>\u57fa\u7840\u4e0a\u6dfb\u52a0\u65cb\u8f6c\u4ee3\u7801\uff0c\u4f7f\u8fde\u7ebf\u4e0e\u6574\u4f53\u56fe\u5f62\u66f4\u52a0\u534f\u8c03\uff0c<\/strong>\u63d0\u5347\u89c6\u89c9\u7f8e\u611f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ht.Default.setEdgeType('bus', function (edge) {    \n  var source = edge.getSourceAgent(),\n    target = edge.getTargetAgent();\n\n\n    var targetP = target.p();\n    var points = source.getPoints().toArray();\n    var segments = source.getSegments();\n    var beginPoint, linePoints;\n    for (let i = 0; i &lt; points.length - 1; i++) {\n        if (segments) {\n            if (segments&#91;i + 1] === 1) continue;\n        }\n        const point1 = points&#91;i];\n        const point2 = points&#91;i + 1];\n        const minPosition = pointToInsideLine(point1, point2, targetP);\n        if (!beginPoint || minPosition.z &lt; beginPoint.z) {\n            beginPoint = minPosition;\n            linePoints = &#91;point1, point2]\n        }\n    }\n    var rotation = angleBetweenLineAndHorizontal(linePoints&#91;0], linePoints&#91;1]);\n    var rotatePoint = findIntersection(&#91;rotatePointAroundAnotherPoint(beginPoint, targetP, rotation), targetP], linePoints);\n    if(isPointInLine(rotatePoint, linePoints&#91;0], linePoints&#91;1])){\n        beginPoint = rotatePoint;\n    }\n    return {\n        points: new ht.List(&#91;\n            beginPoint, targetP\n        ]),\n        segments: new ht.List(&#91;1, 2])\n    };\n});\n\n\n\/**\n * \u8ba1\u7b97\u4e24\u70b9\u4e4b\u95f4\u76f4\u7ebf\u4e0e\u6c34\u5e73\u7ebf\u7684\u5939\u89d2\n *\/\nfunction angleBetweenLineAndHorizontal(p1, p2) {\n  if (new ht.Math.Vector2(p1.x, p1.y).length() &gt; new ht.Math.Vector2(p2.x, p2.y).length()) {\n      var p = p2;\n      p2 = p1;\n      p1 = p;\n    }\n    var x1 = p1.x,\n      y1 = p1.y,\n      x2 = p2.x,\n      y2 = p2.y;\n    var dx = x2 - x1;\n    var dy = y2 - y1;\n    var angleRadians = Math.atan2(dy, dx); \/\/ \u8ba1\u7b97\u5939\u89d2\uff08\u5f27\u5ea6\uff09\n    var angleDegrees = angleRadians * (180 \/ Math.PI); \/\/ \u5f27\u5ea6\u8f6c\u89d2\n    \/\/ \u786e\u4fdd\u89d2\u5ea6\u5728 0 \u5230 360 \u4e4b\u95f4\n    if (angleDegrees &lt; 0) {\n       angleDegrees += 360;\n    }\n    return angleDegrees;\n}\nfunction rotatePointAroundAnotherPoint(point, center, angleDegrees) {\n    var angleRadians = angleDegrees * (Math.PI \/ 180);\n    var cosTheta = Math.cos(angleRadians);\n    var sinTheta = Math.sin(angleRadians);\n    var translatedX = point.x - center.x;\n    var translatedY = point.y - center.y;\n    var rotatedX = translatedX * cosTheta - translatedY * sinTheta;\n    var rotatedY = translatedX * sinTheta + translatedY * cosTheta;\n    var finalX = rotatedX + center.x;\n    var finalY = rotatedY + center.y;\n    return { x: finalX, y: finalY };\n}\n\n\n\/**\n * \u7ed9\u5b9a\u4e24\u4e2a\u70b9\uff0c\u8ba1\u7b97\u76f4\u7ebf\u7684\u7cfb\u6570 A, B, C\n * \u76f4\u7ebf\u65b9\u7a0b\uff1aAx + By = C\n *\/\nfunction getLineEquation(x1, y1, x2, y2) {\n  var A = y2 - y1;\n  var B = x1 - x2;\n  var C = A * x1 + B * y1;\n  return { A, B, C };\n}\n\n\n\/**\n * \u8ba1\u7b97\u4e24\u6761\u76f4\u7ebf\u7684\u4ea4\u70b9\n *\/\nfunction calculateIntersection(line1, line2) {\n    var { A: A1, B: B1, C: C1 } = line1;\n    var { A: A2, B: B2, C: C2 } = line2;\n    var determinant = A1 * B2 - A2 * B1;\n    if (determinant === 0) {\n        \/\/ \u5e73\u884c\u6216\u91cd\u5408\n        return null;\n    } else {\n        var x = (C1 * B2 - C2 * B1) \/ determinant;\n        var y = (A1 * C2 - A2 * C1) \/ determinant;\n        return { x, y };\n    }\n}\n\n\n\/**\n * \u627e\u5230\u4e24\u6761\u7ebf\u7684\u4ea4\u70b9\uff0c\u6216\u8005\u5ef6\u957f\u7ebf\u7684\u4ea4\u70b9\n *\/\nfunction findIntersection(line1Points, line2Points) {\n    var &#91;p1, p2] = line1Points;\n    var &#91;p3, p4] = line2Points;\n    var line1 = getLineEquation(p1.x, p1.y, p2.x, p2.y);\n    var line2 = getLineEquation(p3.x, p3.y, p4.x, p4.y);\n    var intersection = calculateIntersection(line1, line2);\n    return intersection;\n}<\/code><\/pre>\n\n\n\n<p>\u5b9e\u73b0\u7684\u6700\u7ec8\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-5.gif\"><img loading=\"lazy\" width=\"800\" height=\"450\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-5.gif\" alt=\"\" class=\"wp-image-5982\"\/><\/a><\/figure>\n\n\n\n<h1>\u603b\u7ed3<\/h1>\n\n\n\n<p>\u56fe\u6251\u8f6f\u4ef6 HT \u81ea\u5b9a\u4e49\u8fde\u7ebf\u529f\u80fd\u4e3a\u56fe\u5f62\u4ea4\u4e92\u8bbe\u8ba1\u5f00\u8f9f\u4e86\u5e7f\u9614\u7684\u65b0\u5929\u5730\u3002\u4ece\u57fa\u672c\u7684&#8221;\u6a2a-\u7ad6-\u6a2a&#8221;\u8fde\u7ebf\u5230\u590d\u6742\u7684\u603b\u7ebf\u62d3\u6251\u56fe\uff0c<strong>\u4e0d\u4ec5\u63d0\u5347\u4e86\u6570\u636e\u53ef\u89c6\u5316\u7684\u7075\u6d3b\u6027\uff0c\u8fd8\u5927\u5e45\u589e\u5f3a\u4e86\u7528\u6237\u4f53\u9a8c\u3002<\/strong>\u901a\u8fc7\u7cbe\u7ec6\u8c03\u6574\u8fde\u7ebf\u7684\u65cb\u8f6c\u89d2\u5ea6\u548c\u6295\u5f71\u70b9\uff0c\u5728 2.5D \u6548\u679c\u4e2d\u5448\u73b0\u66f4\u52a0\u7f8e\u89c2\u548c\u76f4\u89c2\u7684\u62d3\u6251\u5173\u7cfb\u3002<\/p>\n\n\n\n<p><strong>\u4e0d\u4ec5\u9002\u7528\u4e8e\u7f51\u7edc\u7ed3\u6784\u7684\u5c55\u793a\uff0c\u8fd8\u53ef\u6269\u5c55\u5230\u5404\u79cd\u590d\u6742\u7cfb\u7edf\u7684\u53ef\u89c6\u5316\u4e2d\u3002<\/strong>\u4e3a\u8bbe\u8ba1\u5e08\u548c\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5e2e\u52a9\u4ed6\u4eec\u521b\u9020\u51fa\u66f4\u52a0\u4e30\u5bcc\u3001\u5bcc\u6709\u8868\u73b0\u529b\u7684\u56fe\u5f62\u754c\u9762\u3002<\/p>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u81f3\u56fe\u6251\u8f6f\u4ef6\u5b98\u7f51\u67e5\u770b\u66f4\u591a\u6848\u4f8b\u53ca\u6548\u679c\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/www.hightopo.com\/demos\/index.html\">https:\/\/www.hightopo.com\/demos\/index.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><!-- wp:paragraph --><\/p>\n<p>\u5728\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u8bbe\u8ba1\u4e2d\uff0c\u81ea\u5b9a\u4e49\u8fde\u7ebf\u6280\u672f\u4e0d\u4ec5\u63d0\u5347\u4e86\u7528\u6237\u4f53\u9a8c\uff0c\u8fd8\u4e3a\u590d\u6742\u6570\u636e\u53ef\u89c6\u5316\u5f00\u8f9f\u4e86\u65b0\u7684\u53ef\u80fd\u6027\u3002<strong>\u8be5\u529f\u80fd\u70b9\u5141\u8bb8\u7528\u6237\u7075\u6d3b\u5730\u5728\u754c\u9762\u5143\u7d20\u4e4b\u95f4\u521b\u5efa\u89c6\u89c9\u8fde\u63a5\uff0c\u4f7f\u6d41\u7a0b\u56fe\u3001\u601d\u7ef4\u5bfc\u56fe\u548c\u7f51\u7edc\u62d3\u6251\u56fe\u7b49\u4fe1\u606f\u5448\u73b0\u66f4\u52a0\u76f4\u89c2\u548c\u52a8\u6001\u3002<\/strong><\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:heading {\"level\":1} --><\/p>\n<h1>\u6548\u679c\u5c55\u793a<\/h1>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u56fe\u6251\u8f6f\u4ef6\u81ea\u7814 HT for Web \u4ea7\u54c1\u6846\u67b6\u4e2d\uff0cht.Edge \u8282\u70b9\u7528\u4e8e\u8868\u793a\u8282\u70b9\u95f4\u7684\u8fde\u7ebf\u5173\u7cfb\u3002\u719f\u6089 HT \u7684\u7528\u6237\u5e94\u8be5\u4e86\u89e3 ht.Edge \u5185\u7f6e\u4e86\u591a\u79cd\u8fde\u7ebf\u7c7b\u578b\uff0c\u80fd\u6ee1\u8db3\u4e00\u822c\u62d3\u6251\u56fe\u9700\u6c42\uff0c\u4f46\u5728\u7279\u6b8a\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e9b\u9ed8\u8ba4\u7c7b\u578b\u53ef\u80fd\u65e0\u6cd5\u6ee1\u8db3\u9700\u6c42\u3002\u4e3a\u6b64\uff0c<strong>HT <\/strong><strong>\u63d0\u4f9b\u4e86\u81ea\u5b9a\u4e49\u8fde\u7ebf\u529f\u80fd\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u6839\u636e\u5177\u4f53\u9700\u6c42\u521b\u5efa\u7279\u6b8a\u7684\u8fde\u7ebf\u7c7b\u578b\uff0c\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u56fe\u5f62\u8868\u793a\u3002<\/strong><\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:image {\"id\":5977,\"width\":640,\"height\":360,\"sizeSlug\":\"full\",\"linkDestination\":\"media\"} --><\/p>\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640.gif\"><img loading=\"lazy\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640.gif\" alt=\"\" class=\"wp-image-5977\" width=\"640\" height=\"360\"\/><\/a><\/figure>\n<p><!-- \/wp:image --><\/p>\n<p><!-- wp:image {\"id\":5978,\"sizeSlug\":\"full\",\"linkDestination\":\"media\"} --><\/p>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-1-1.gif\"><img loading=\"lazy\" width=\"640\" height=\"360\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-1-1.gif\" alt=\"\" class=\"wp-image-5978\"\/><\/a><\/figure>\n<p><!-- \/wp:image --><\/p>\n<p><!-- wp:heading {\"level\":1} --><\/p>\n<h1>\u7cfb\u7edf\u5206\u6790<\/h1>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:heading {\"level\":1} --><\/p>\n<h1>\u81ea\u5b9a\u4e49\u8fde\u7ebf<\/h1>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u56fe\u6251 HT \u6846\u67b6\u63d0\u4f9b\u7075\u6d3b\u7684\u81ea\u5b9a\u4e49\u8fde\u7ebf\u529f\u80fd\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528 ht.Default.setEdgeType(type, func, mutual) \u65b9\u6cd5\u6765\u521b\u5efa\u72ec\u7279\u7684\u8fde\u7ebf\u7c7b\u578b\u3002\u4ee5\u4e0b\u662f\u8be5\u65b9\u6cd5\u7684\u53c2\u6570\u8be6\u89e3\uff1a<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>type\uff1a<\/strong>\u81ea\u5b9a\u4e49\u8fde\u7ebf\u7c7b\u578b\u7684\u540d\u79f0\uff0c\u4e0e style \u4e2d\u7684 edge.type \u5c5e\u6027\u76f8\u5bf9\u5e94\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>func\uff1a<\/strong>\u8ba1\u7b97\u8fde\u7ebf\u8def\u5f84\u4fe1\u606f\u7684\u51fd\u6570\uff0c\u63a5\u6536\u56db\u4e2a\u53c2\u6570\uff1a<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>gap\uff1a\u591a\u6761\u8fde\u7ebf\u6210\u6346\u65f6\uff0c\u672c\u8fde\u7ebf\u5bf9\u8c61\u5bf9\u5e94\u4e2d\u5fc3\u8fde\u7ebf\u7684\u95f4\u8ddd\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>edge\uff1a\u5f53\u524d\u8fde\u7ebf\u5bf9\u8c61\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>graphView\uff1a\u5f53\u524d\u5bf9\u5e94\u62d3\u6251\u7ec4\u4ef6\u5bf9\u8c61\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>sameSourceWithFirstEdge\uff1aboolean \u7c7b\u578b\uff0c\u8be5\u8fde\u7ebf\u662f\u5426\u4e0e\u540c\u7ec4\u7684\u7b2c\u4e00\u6761\u8fde\u7ebf\u540c\u6e90\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>mutual\uff1a<\/strong>\u51b3\u5b9a\u8be5\u8fde\u7ebf\u7c7b\u578b\u662f\u5426\u4f1a\u5f71\u54cd\u540c\u4e00\u8d77\u59cb\u6216\u7ed3\u675f\u8282\u70b9\u4e0a\u7684\u5176\u4ed6\u8fde\u7ebf\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u6df1\u5165\u5206\u6790\u4e00\u79cd\u5e38\u89c1\u7684\u62d3\u6251\u5173\u7cfb\u5b9e\u73b0\u6b65\u9aa4\uff0c\u5373&#8221;\u6a2a-\u7ad6-\u6a2a&#8221;\u7684\u8fde\u7ebf\u65b9\u5f0f\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:image {\"id\":5979,\"sizeSlug\":\"full\",\"linkDestination\":\"media\"} --><\/p>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-2.gif\"><img loading=\"lazy\" width=\"800\" height=\"394\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-2.gif\" alt=\"\" class=\"wp-image-5979\"\/><\/a><\/figure>\n<p><!-- \/wp:image --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u6bb5\u5b9a\u4e49\u4e0a\u56fe\u8fde\u7ebf\u7c7b\u578b\u7684\u793a\u4f8b\u4ee3\u7801\u3002\u4ee3\u7801\u5f88\u7b80\u5355\uff0c\u9996\u5148\u83b7\u53d6\u8d77\u59cb\u8282\u70b9\u548c\u76ee\u6807\u8282\u70b9\u7684\u4fe1\u606f\uff0c\u7136\u540e\u6839\u636e\u8fd9\u4e24\u4e2a\u8282\u70b9\u7684\u5750\u6807\uff0c\u6309\u7167\u9884\u5b9a\u7684\u89c4\u5219\u8ba1\u7b97\u51fa\u8fde\u7ebf\u7684\u8def\u5f84\u70b9\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:code --><\/p>\n<pre class=\"wp-block-code\"><code>ht.Default.setEdgeType('horizontal-vertical', function (edge, gap, graphView) {\n    const points = new ht.List();\n    const segments = new ht.List();\n    const source = edge.getSource();\n    const target = edge.getTarget();\n    const sourceP = source.p();\n    const targetP = target.p();\n    points.add(sourceP);\n    if (targetP.x !== sourceP.x) {\n        points.add({ x: sourceP.x + (targetP.x - sourceP.x) \/ 2, y: sourceP.y });\n        points.add({ x: sourceP.x + (targetP.x - sourceP.x) \/ 2, y: targetP.y });\n    }\n    points.add(targetP);\n    return { points, segments };\n})<\/code><\/pre>\n<p><!-- \/wp:code --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u5b9a\u4e49\u597d\u8fde\u7ebf\u7c7b\u578b\u540e\uff0c\u53ea\u9700\u901a\u8fc7 edge.s(&#8216;edge.type&#8217;, &#8216;horizontal-vertical&#8217;) \u8fd9\u6bb5\u7b80\u5355\u7684\u4ee3\u7801\u884c\uff0c\u5c31\u80fd\u5c06 edge \u5bf9\u8c61\u7684\u8fde\u7ebf\u8bbe\u7f6e\u4e3a\u6211\u4eec\u521a\u521a\u5b9a\u4e49\u7684\u7c7b\u578b\u3002\u7531\u6b64\u4e00\u6765\uff0c\u5373\u53ef\u770b\u5230\u4ee4\u4eba\u6ee1\u610f\u7684\u6548\u679c\uff0c\u5927\u5e45\u63d0\u5347\u56fe\u5f62\u7684\u53ef\u8bfb\u6027\u548c\u7f8e\u89c2\u5ea6\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:heading {\"level\":1} --><\/p>\n<h1>\u603b\u7ebf\u62d3\u6251<\/h1>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u603b\u7ebf\u62d3\u6251\u662f\u4e00\u79cd\u7f51\u7edc\u7ed3\u6784\uff0c\u6240\u6709\u8bbe\u5907\uff08\u5982\u8ba1\u7b97\u673a\u3001\u6253\u5370\u673a\u7b49\uff09\u90fd\u8fde\u63a5\u5230\u4e00\u4e2a\u5171\u540c\u7684\u901a\u4fe1\u4ecb\u8d28\u4e0a\uff0c\u901a\u5e38\u662f\u4e00\u6839\u7535\u7f06\uff0c\u8fd9\u4e2a\u4ecb\u8d28\u88ab\u79f0\u4e3a&#8221;\u603b\u7ebf&#8221;\uff08bus\uff09\u3002<strong>\u603b\u7ebf\u62d3\u6251\u5728\u5de5\u4e1a\u63a7\u5236\u548c\u5d4c\u5165\u5f0f\u7cfb\u7edf\u7b49\u7279\u5b9a\u9886\u57df\u4e2d\u88ab\u5e7f\u6cdb\u5e94\u7528\u3002<\/strong>\u5728\u56fe\u6251 HT \u6846\u67b6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528 ht.Shape \u7ec4\u4ef6\u7ed8\u5236\u603b\u7ebf\uff0c\u5e76\u901a\u8fc7 ht.Edge \u7ec4\u4ef6\u5c06\u5404\u4e2a\u8bbe\u5907\u8282\u70b9\u8fde\u63a5\u5230\u603b\u7ebf\u4e0a\u3002\u8fd9\u4e9b\u8fde\u63a5\u7684\u89c6\u89c9\u8868\u73b0\u53ef\u901a\u8fc7<strong>\u81ea\u5b9a\u4e49\u8fde\u7ebf\u7c7b\u578b\u7075\u6d3b\u5b9a\u4e49<\/strong>\uff0c\u4ece\u800c\u5b9e\u73b0\u7cbe\u786e\u7684\u603b\u7ebf\u62d3\u6251\u56fe\u8868\u793a\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:image {\"id\":5980,\"sizeSlug\":\"full\",\"linkDestination\":\"media\"} --><\/p>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-3.gif\"><img loading=\"lazy\" width=\"800\" height=\"394\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-3.gif\" alt=\"\" class=\"wp-image-5980\"\/><\/a><\/figure>\n<p><!-- \/wp:image --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u4e0a\u9762\u5c55\u793a\u7684\u662f\u4e00\u4e2a\u603b\u7ebf\u7684\u793a\u4f8b\u6548\u679c\uff0c\u53ef\u4ee5\u76f4\u89c2\u770b\u5230\u6240\u6709\u8bbe\u5907\u90fd\u8fde\u63a5\u5230\u4e86\u603b\u7ebf\u4e0a\u3002\u5728\u5177\u4f53\u5b9e\u73b0\u8fc7\u7a0b\u4e2d\uff0c\u6700\u5177\u6311\u6218\u6027\u7684\u95ee\u9898\u662f\uff1a\u5982\u4f55\u8ba1\u7b97\u51fa\u603b\u7ebf\u4e0a\u8ddd\u79bb\u76ee\u6807\u8282\u70b9\u5750\u6807\u6700\u8fd1\u7684\u70b9?<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>\u8ba1\u7b97\u8282\u70b9\u5230\u603b\u7ebf\u8ddd\u79bb<\/strong><\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u603b\u7ebf\u901a\u5e38\u7531\u591a\u6761\u76f4\u7ebf\u6bb5\u7ec4\u6210\uff0c\u56e0\u6b64\u8ba1\u7b97\u67d0\u4e00\u8282\u70b9\u5230\u603b\u7ebf\u7684\u6700\u77ed\u8ddd\u79bb\u53ef\u6309\u4ee5\u4e0b\u601d\u8def\u8fdb\u884c\uff1a<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>\u5c06\u603b\u7ebf\u5206\u5272\u4e3a\u591a\u6bb5\u76f4\u7ebf<\/strong><\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u603b\u7ebf\u7531\u591a\u4e2a\u76f4\u7ebf\u6bb5\u6784\u6210\uff0c\u53ef\u4ee5\u53d6\u603b\u7ebf\u4e0a\u76f8\u90bb\u4e24\u70b9\u6784\u6210\u4e00\u6761\u76f4\u7ebf\u3002\u5177\u4f53\u5b9e\u73b0\u65f6\uff0c\u904d\u5386 points \u6570\u636e\uff0c\u83b7\u53d6 points[index] \u548c points[index+1] \u4f5c\u4e3a\u7ebf\u6bb5\u7684\u4e24\u4e2a\u7aef\u70b9\u3002\u6ce8\u610f\uff0c\u5982\u679c\u8bbe\u7f6e\u4e86 segments\uff0c\u5176\u4e2d 1 \u4ee3\u8868\u65b0\u8def\u5f84\u7684\u8d77\u70b9\uff0c\u6240\u4ee5\u5f53 segments[index+1] \u4e3a 1 \u65f6\u5e94\u8df3\u8fc7\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>\u8ba1\u7b97\u70b9\u5230\u6bcf\u6761\u76f4\u7ebf\u7684\u8ddd\u79bb<\/strong><\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u83b7\u53d6\u6bcf\u6761\u76f4\u7ebf\u6bb5\u540e\uff0c\u8ba1\u7b97\u8282\u70b9\u5750\u6807\u5230\u5404\u7ebf\u6bb5\u7684\u8ddd\u79bb\uff0c\u5e76\u5c06<strong>\u8ddd\u79bb\u503c\u5b58\u5165\u4e00\u4e2a\u96c6\u5408\u4e2d<\/strong>\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>\u83b7\u53d6\u6700\u77ed\u8ddd\u79bb<\/strong><\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u4ece\u8ddd\u79bb\u96c6\u5408\u4e2d\u627e\u51fa<strong>\u6700\u5c0f\u503c<\/strong>\uff0c\u5373\u4e3a\u8282\u70b9\u5230\u603b\u7ebf\u7684\u6700\u77ed\u8ddd\u79bb\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u57fa\u4e8e\u4e0a\u8ff0\u601d\u8def\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2a\u603b\u7ebf\u8fde\u7ebf\u7c7b\u578b\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u7684\u5b9e\u73b0\u4ee3\u7801\uff1a<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:code --><\/p>\n<pre class=\"wp-block-code\"><code>\/\/ \u8ba1\u7b97\u70b9\u5230\u76f4\u7ebf\u7684\u8ddd\u79bb\uff0c\u8fd4\u56de\u7ed3\u679c\u662f\u4e2a\u5bf9\u8c61\u7ed3\u6784\nvar pointToInsideLine = function (p1, p2, p) {\n     var x1 = p1.x,\n         y1 = p1.y,\n         x2 = p2.x,\n         y2 = p2.y,\n         x = p.x,\n         y = p.y,\n         result = {},\n         dx = x2 - x1,\n         dy = y2 - y1,\n         d = Math.sqrt(dx * dx + dy * dy),\n         ca = dx \/ d, \/\/ cosine\n         sa = dy \/ d, \/\/ sine\n         mX = (-x1 + x) * ca + (-y1 + y) * sa;\n    result.x = x1 + mX * ca;\n    result.y = y1 + mX * sa;\n    if (!isPointInLine(result, p1, p2)) {\n           result.x = Math.abs(result.x - p1.x) &lt; Math.abs(result.x - p2.x) ? p1.x : p2.x;\n           result.y = Math.abs(result.y - p1.y) &lt; Math.abs(result.y - p2.y) ? p1.y : p2.y;\n    }\n    dx = x - result.x;\n    dy = y - result.y;\n    result.z = Math.sqrt(dx * dx + dy * dy);\n    return result;\n};\n\/\/ \u5224\u65ad\u70b9\u662f\u5426\u5728\u7ebf\u4e0a\nvar isPointInLine = function (p, p1, p2) {\n     return p.x &gt;= Math.min(p1.x, p2.x) &amp;&amp;\n          p.x &lt;= Math.max(p1.x, p2.x) &amp;&amp;\n          p.y &gt;= Math.min(p1.y, p2.y) &amp;&amp;\n          p.y &lt;= Math.max(p1.y, p2.y);\n};\n\/\/ \u6ce8\u518c\u8fde\u7ebf\u7c7b\u578b\nht.Default.setEdgeType('bus', function (edge) {\n    var source = edge.getSourceAgent(),\n        target = edge.getTargetAgent();\n\n\n    var targetP = target.p();\n    var points = source.getPoints().toArray();\n    var segments = source.getSegments();\n    var beginPoint;\n    for (let i = 0; i &lt; points.length - 1; i++) {\n        if (segments) {\n            if (segments&#91;i + 1] === 1) continue;\n        }\n        const point1 = points&#91;i];\n        const point2 = points&#91;i + 1];\n        const minPosition = pointToInsideLine(point1, point2, targetP);\n        if (!beginPoint || minPosition.z &lt; beginPoint.z) {\n            beginPoint = minPosition;\n        }\n    }\n    return {\n        points: new ht.List(&#91; beginPoint, targetP ]),\n        segments: new ht.List(&#91;1, 2])\n    };\n});<\/code><\/pre>\n<p><!-- \/wp:code --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u6267\u884c\u4e0a\u8ff0\u4ee3\u7801\u540e\uff0c\u6211\u4eec\u5c06\u5f97\u5230\u5982\u4e0b\u6548\u679c\uff1a<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:image {\"id\":5981,\"sizeSlug\":\"full\",\"linkDestination\":\"media\"} --><\/p>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-4.gif\"><img loading=\"lazy\" width=\"640\" height=\"315\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-4.gif\" alt=\"\" class=\"wp-image-5981\"\/><\/a><\/figure>\n<p><!-- \/wp:image --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u4ece\u4e0a\u56fe\u53ef\u4ee5\u6e05\u695a\u770b\u51fa\uff0c\u793a\u4f8b\u6210\u529f\u83b7\u53d6\u4e86\u8282\u70b9\u5230\u603b\u7ebf\u7684\u6700\u8fd1\u70b9\uff0c\u5e76\u7ed8\u5236\u4e86\u76f8\u5e94\u7684\u8fde\u7ebf\u8282\u70b9\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5bf9\u4e8e\u76f4\u7ebf\u6bb5\u800c\u8a00\uff0c\u8282\u70b9\u5728\u76f4\u7ebf\u4e0a\u7684\u6295\u5f71\u70b9\u5373\u4e3a\u5176\u8ddd\u603b\u7ebf\u6700\u8fd1\u7684\u70b9\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>\u89c6\u89c9\u7f8e\u611f\u4f18\u5316<\/strong><\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u867d\u7136\u793a\u4f8b\u5df2\u5b9e\u73b0\u4e86\u57fa\u7840\u603b\u7ebf\u6548\u679c\uff0c\u4f46\u7531\u4e8e\u62d3\u6251\u56fe\u91c7\u7528 2.5D \u6548\u679c\uff0c\u4ec5\u8ba1\u7b97\u6295\u5f71\u70b9\u53ef\u80fd\u65e0\u6cd5\u5448\u73b0\u7406\u60f3\u7684\u89c6\u89c9\u6548\u679c\u3002<strong>\u4e3a\u4e86\u589e\u5f3a\u89c6\u89c9\u8868\u73b0\uff0c\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u8ba9\u8fde\u7ebf\u65cb\u8f6c\u4e00\u5b9a\u89d2\u5ea6\u3002<\/strong>\u4e3a\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u73b0\u6709\u529f\u80fd\u7684<strong>\u57fa\u7840\u4e0a\u6dfb\u52a0\u65cb\u8f6c\u4ee3\u7801\uff0c\u4f7f\u8fde\u7ebf\u4e0e\u6574\u4f53\u56fe\u5f62\u66f4\u52a0\u534f\u8c03\uff0c<\/strong>\u63d0\u5347\u89c6\u89c9\u7f8e\u611f\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:code --><\/p>\n<pre class=\"wp-block-code\"><code>ht.Default.setEdgeType('bus', function (edge) {    \n  var source = edge.getSourceAgent(),\n    target = edge.getTargetAgent();\n\n\n    var targetP = target.p();\n    var points = source.getPoints().toArray();\n    var segments = source.getSegments();\n    var beginPoint, linePoints;\n    for (let i = 0; i &lt; points.length - 1; i++) {\n        if (segments) {\n            if (segments&#91;i + 1] === 1) continue;\n        }\n        const point1 = points&#91;i];\n        const point2 = points&#91;i + 1];\n        const minPosition = pointToInsideLine(point1, point2, targetP);\n        if (!beginPoint || minPosition.z &lt; beginPoint.z) {\n            beginPoint = minPosition;\n            linePoints = &#91;point1, point2]\n        }\n    }\n    var rotation = angleBetweenLineAndHorizontal(linePoints&#91;0], linePoints&#91;1]);\n    var rotatePoint = findIntersection(&#91;rotatePointAroundAnotherPoint(beginPoint, targetP, rotation), targetP], linePoints);\n    if(isPointInLine(rotatePoint, linePoints&#91;0], linePoints&#91;1])){\n        beginPoint = rotatePoint;\n    }\n    return {\n        points: new ht.List(&#91;\n            beginPoint, targetP\n        ]),\n        segments: new ht.List(&#91;1, 2])\n    };\n});\n\n\n\/**\n * \u8ba1\u7b97\u4e24\u70b9\u4e4b\u95f4\u76f4\u7ebf\u4e0e\u6c34\u5e73\u7ebf\u7684\u5939\u89d2\n *\/\nfunction angleBetweenLineAndHorizontal(p1, p2) {\n  if (new ht.Math.Vector2(p1.x, p1.y).length() &gt; new ht.Math.Vector2(p2.x, p2.y).length()) {\n      var p = p2;\n      p2 = p1;\n      p1 = p;\n    }\n    var x1 = p1.x,\n      y1 = p1.y,\n      x2 = p2.x,\n      y2 = p2.y;\n    var dx = x2 - x1;\n    var dy = y2 - y1;\n    var angleRadians = Math.atan2(dy, dx); \/\/ \u8ba1\u7b97\u5939\u89d2\uff08\u5f27\u5ea6\uff09\n    var angleDegrees = angleRadians * (180 \/ Math.PI); \/\/ \u5f27\u5ea6\u8f6c\u89d2\n    \/\/ \u786e\u4fdd\u89d2\u5ea6\u5728 0 \u5230 360 \u4e4b\u95f4\n    if (angleDegrees &lt; 0) {\n       angleDegrees += 360;\n    }\n    return angleDegrees;\n}\nfunction rotatePointAroundAnotherPoint(point, center, angleDegrees) {\n    var angleRadians = angleDegrees * (Math.PI \/ 180);\n    var cosTheta = Math.cos(angleRadians);\n    var sinTheta = Math.sin(angleRadians);\n    var translatedX = point.x - center.x;\n    var translatedY = point.y - center.y;\n    var rotatedX = translatedX * cosTheta - translatedY * sinTheta;\n    var rotatedY = translatedX * sinTheta + translatedY * cosTheta;\n    var finalX = rotatedX + center.x;\n    var finalY = rotatedY + center.y;\n    return { x: finalX, y: finalY };\n}\n\n\n\/**\n * \u7ed9\u5b9a\u4e24\u4e2a\u70b9\uff0c\u8ba1\u7b97\u76f4\u7ebf\u7684\u7cfb\u6570 A, B, C\n * \u76f4\u7ebf\u65b9\u7a0b\uff1aAx + By = C\n *\/\nfunction getLineEquation(x1, y1, x2, y2) {\n  var A = y2 - y1;\n  var B = x1 - x2;\n  var C = A * x1 + B * y1;\n  return { A, B, C };\n}\n\n\n\/**\n * \u8ba1\u7b97\u4e24\u6761\u76f4\u7ebf\u7684\u4ea4\u70b9\n *\/\nfunction calculateIntersection(line1, line2) {\n    var { A: A1, B: B1, C: C1 } = line1;\n    var { A: A2, B: B2, C: C2 } = line2;\n    var determinant = A1 * B2 - A2 * B1;\n    if (determinant === 0) {\n        \/\/ \u5e73\u884c\u6216\u91cd\u5408\n        return null;\n    } else {\n        var x = (C1 * B2 - C2 * B1) \/ determinant;\n        var y = (A1 * C2 - A2 * C1) \/ determinant;\n        return { x, y };\n    }\n}\n\n\n\/**\n * \u627e\u5230\u4e24\u6761\u7ebf\u7684\u4ea4\u70b9\uff0c\u6216\u8005\u5ef6\u957f\u7ebf\u7684\u4ea4\u70b9\n *\/\nfunction findIntersection(line1Points, line2Points) {\n    var &#91;p1, p2] = line1Points;\n    var &#91;p3, p4] = line2Points;\n    var line1 = getLineEquation(p1.x, p1.y, p2.x, p2.y);\n    var line2 = getLineEquation(p3.x, p3.y, p4.x, p4.y);\n    var intersection = calculateIntersection(line1, line2);\n    return intersection;\n}<\/code><\/pre>\n<p><!-- \/wp:code --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u5b9e\u73b0\u7684\u6700\u7ec8\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:image {\"id\":5982,\"sizeSlug\":\"full\",\"linkDestination\":\"media\"} --><\/p>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-5.gif\"><img loading=\"lazy\" width=\"800\" height=\"450\" src=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2025\/03\/640-5.gif\" alt=\"\" class=\"wp-image-5982\"\/><\/a><\/figure>\n<p><!-- \/wp:image --><\/p>\n<p><!-- wp:heading {\"level\":1} --><\/p>\n<h1>\u603b\u7ed3<\/h1>\n<p><!-- \/wp:heading --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u56fe\u6251\u8f6f\u4ef6 HT \u81ea\u5b9a\u4e49\u8fde\u7ebf\u529f\u80fd\u4e3a\u56fe\u5f62\u4ea4\u4e92\u8bbe\u8ba1\u5f00\u8f9f\u4e86\u5e7f\u9614\u7684\u65b0\u5929\u5730\u3002\u4ece\u57fa\u672c\u7684&#8221;\u6a2a-\u7ad6-\u6a2a&#8221;\u8fde\u7ebf\u5230\u590d\u6742\u7684\u603b\u7ebf\u62d3\u6251\u56fe\uff0c<strong>\u4e0d\u4ec5\u63d0\u5347\u4e86\u6570\u636e\u53ef\u89c6\u5316\u7684\u7075\u6d3b\u6027\uff0c\u8fd8\u5927\u5e45\u589e\u5f3a\u4e86\u7528\u6237\u4f53\u9a8c\u3002<\/strong>\u901a\u8fc7\u7cbe\u7ec6\u8c03\u6574\u8fde\u7ebf\u7684\u65cb\u8f6c\u89d2\u5ea6\u548c\u6295\u5f71\u70b9\uff0c\u5728 2.5D \u6548\u679c\u4e2d\u5448\u73b0\u66f4\u52a0\u7f8e\u89c2\u548c\u76f4\u89c2\u7684\u62d3\u6251\u5173\u7cfb\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><strong>\u4e0d\u4ec5\u9002\u7528\u4e8e\u7f51\u7edc\u7ed3\u6784\u7684\u5c55\u793a\uff0c\u8fd8\u53ef\u6269\u5c55\u5230\u5404\u79cd\u590d\u6742\u7cfb\u7edf\u7684\u53ef\u89c6\u5316\u4e2d\u3002<\/strong>\u4e3a\u8bbe\u8ba1\u5e08\u548c\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5e2e\u52a9\u4ed6\u4eec\u521b\u9020\u51fa\u66f4\u52a0\u4e30\u5bcc\u3001\u5bcc\u6709\u8868\u73b0\u529b\u7684\u56fe\u5f62\u754c\u9762\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u60a8\u53ef\u4ee5\u81f3\u56fe\u6251\u8f6f\u4ef6\u5b98\u7f51\u67e5\u770b\u66f4\u591a\u6848\u4f8b\u53ca\u6548\u679c\uff1a<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p><a href=\"https:\/\/www.hightopo.com\/demos\/index.html\">https:\/\/www.hightopo.com\/demos\/index.html<\/a><\/p>\n<p><!-- \/wp:paragraph --><\/p>\n","protected":false},"author":2,"featured_media":5983,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[3,7,9,20,17,726,728,13,59,25,27,725,727,724],"_links":{"self":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/5975"}],"collection":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/comments?post=5975"}],"version-history":[{"count":1,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/5975\/revisions"}],"predecessor-version":[{"id":5984,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/5975\/revisions\/5984"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/media\/5983"}],"wp:attachment":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/media?parent=5975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/categories?post=5975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/tags?post=5975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}