用一些东西来回答这个问题(非问题)很难......
......你的数学搞砸了几个方面:
应该sin
而cos
不是asin
和acos
它应该是sin(x)*length
,而不是sin(x/length)
在sin
与cos
被交换
线的角度应该更好地计算atan2
(atan
你使用的函数有一些问题,显然特别是starty==endy
)
应将"偏移"添加到线角度 - 特别是应该lineAngle - arrowAngle
代替arrowAngle - lineAngle
整个代码,更新:
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Line; import javafx.stage.Stage; public class ArrowTest extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { double startx = 200; double starty = 100; double endx = 100; double endy = 300; double arrowAngle = Math.toRadians(45.0); double arrowLength = 10.0; double lineAngle = Math.atan2(starty - endy, startx - endx); double x1 = Math.cos(lineAngle + arrowAngle) * arrowLength + endx; double y1 = Math.sin(lineAngle + arrowAngle) * arrowLength + endy; double x2 = Math.cos(lineAngle - arrowAngle) * arrowLength + endx; double y2 = Math.sin(lineAngle - arrowAngle) * arrowLength + endy; Group root = new Group(); Line line = new Line(startx, starty, endx, endy); Line arrowHead1 = new Line(endx, endy, x1, y1); Line arrowHead2 = new Line(endx, endy, x2, y2); root.getChildren().addAll(line, arrowHead1, arrowHead2); primaryStage.setScene(new Scene(root, 800, 600)); primaryStage.show(); } }