From af08d1ae10384dc7131ca2aa409d2d117b559cef Mon Sep 17 00:00:00 2001 From: fan Date: Tue, 10 Oct 2023 09:53:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=AD=E5=A4=B4=E8=AE=BE=E5=A4=87=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/arrow/Arrow.ts | 17 ++++++++++------- src/graphics/arrow/ArrowDrawAssistant.ts | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/graphics/arrow/Arrow.ts b/src/graphics/arrow/Arrow.ts index a3fd1cd..c7ef458 100644 --- a/src/graphics/arrow/Arrow.ts +++ b/src/graphics/arrow/Arrow.ts @@ -45,13 +45,16 @@ export class Arrow extends JlGraphic implements ILineGraphic { this.arrowGraphic.clear(); this.arrowGraphic.beginFill(ArrowConsts.lineColor, 1); if (this.arrowGraphic.drawRegularPolygon) { - this.arrowGraphic.drawRegularPolygon( - -10, - 0, - 10, - 3, - Math.atan2(p2.y - p1.y, p2.x - p1.y) - ); + let roation = Math.PI / 2; + const angle = Math.atan2(p1.y - p2.y, p1.x - p2.x); + if (angle > Math.PI / 2) { + roation = angle - Math.PI / 2; + } else if (angle <= Math.PI / 2 && angle >= 0) { + roation = Math.PI / 2 - angle; + } else { + roation = angle - Math.PI / 2; + } + this.arrowGraphic.drawRegularPolygon(p2.x, p2.y, 10, 3, roation); } this.arrowGraphic.endFill(); } diff --git a/src/graphics/arrow/ArrowDrawAssistant.ts b/src/graphics/arrow/ArrowDrawAssistant.ts index 067de7d..5c463b5 100644 --- a/src/graphics/arrow/ArrowDrawAssistant.ts +++ b/src/graphics/arrow/ArrowDrawAssistant.ts @@ -70,13 +70,16 @@ export class ArrowDraw extends GraphicDrawAssistant { this.arrowGraphic.clear(); this.arrowGraphic.beginFill(ArrowConsts.lineColor, 1); if (this.arrowGraphic.drawRegularPolygon) { - this.arrowGraphic.drawRegularPolygon( - -10, - 0, - 10, - 3, - Math.atan2(p.y - p1.y, p.x - p1.y) - ); + let roation = Math.PI / 2; + const angle = Math.atan2(p1.y - p.y, p1.x - p.x); + if (angle > Math.PI / 2) { + roation = angle - Math.PI / 2; + } else if (angle <= Math.PI / 2 && angle >= 0) { + roation = Math.PI / 2 - angle; + } else { + roation = angle - Math.PI / 2; + } + this.arrowGraphic.drawRegularPolygon(p.x, p.y, 10, 3, roation); } this.arrowGraphic.endFill(); }