Ich denke, es ist einfacher, eine Gruppe zu erstellen, die eine Aufwärtslinie und einen Pfeil zusammen enthält, und diese Gruppe dann einfach um die Mitte zu drehen.
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Pane root = createPane();
root.setTranslateX(200);
root.setTranslateY(200);
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
private Pane createPane() {
BorderPane root = new BorderPane();
ArrowFactory arrowfactory = new ArrowFactory();
double lineLength = 100;
double centerX = 0;
double centerY = 0;
root.getChildren().addAll(
arrowfactory.createLineAndArrow(centerX, centerY, lineLength, 0),
arrowfactory.createLineAndArrow(centerX, centerY, lineLength, 30),
arrowfactory.createLineAndArrow(centerX, centerY, lineLength, 45),
arrowfactory.createLineAndArrow(centerX, centerY, lineLength, 60),
arrowfactory.createLineAndArrow(centerX, centerY, lineLength, 90),
arrowfactory.createLineAndArrow(centerX, centerY, lineLength, 135),
arrowfactory.createLineAndArrow(centerX, centerY, lineLength, 180),
arrowfactory.createLineAndArrow(centerX, centerY, lineLength, 225),
arrowfactory.createLineAndArrow(centerX, centerY, lineLength, 270),
arrowfactory.createLineAndArrow(centerX, centerY, lineLength, 315)
);
return root;
}
public static void main(String[] args) {
launch(args);
}
}
ArrayFactory.java
:
public class ArrowFactory {
private final int arrowWidth = 10;
private final int arrowHeight = 10;
public Group createLineAndArrow(double centerX, double centerY, double lineLength, double rotation) {
Group group = new Group();
Line line = new Line(centerX, centerY, centerX, centerY - lineLength);
Polygon upwardArrow = createUpwardArrow(centerX, centerY - lineLength/2);
group.getChildren().addAll(line, upwardArrow);
group.getTransforms().add(new Rotate(rotation, centerX, centerY));
return group;
}
private Polygon createUpwardArrow(double centerX, double centerY) {
Polygon arrow = new Polygon(
createUpwardArrowPoints(centerX, centerY + arrowHeight/2));
arrow.setFill(Color.TRANSPARENT);
arrow.setStroke(Color.BLACK);
return arrow;
}
private double[] createUpwardArrowPoints(double centerX, double centerY) {
return new double[] {
centerX - arrowWidth/2, centerY, // left
centerX + arrowWidth/2, centerY, // right
centerX, centerY - arrowHeight, // top
};
}
}
für Kreismittel als Eingaben verwenden Sie könnten verwenden:
private Group createLineAndArrow(double x1, double y1, double x2, double y2) {
double distance = Math.hypot(x1-x2, y1-y2);
double angle = Math.toDegrees(Math.atan2(x2 - x1, y2 - y1));
return arrowfactory.createLineAndArrow(x1, y1, distance, angle);
}
Ich bin verwirrt, was ist die Übersetzung am Ende? Sind Sie sicher, dass die Pfeile nicht von Ende zu Anfang zeigen? Was die Schicht betrifft, haben Sie sich die LayoutBounds angeschaut? Der Drehpunkt der Drehung ist das Zentrum der LayoutBounds, wenn das also nicht die Mitte des Dreiecks ist, könnte das die Verschiebung erklären. – Lidae
@Lidae Pfeil wird gedreht und dann an die richtige Stelle verschoben - Mitte der Linie. Daher die Übersetzung. – alex
aber sie sind schon vor der Übersetzung an der richtigen Stelle, es sei denn die Pfeile zeigen nach innen, aber dann zeigt der Pfeilkopf in die falsche Richtung ... – Lidae