Graphics JavaFX-创建具有起点和终点角度的半圆
如何在Graphics JavaFX-创建具有起点和终点角度的半圆,graphics,javafx,Graphics,Javafx,如何在JavaFX中创建起点和终点角度可调的半圆。我试着使用Arc或ArcTo,但它从来没有给我需要的东西。有什么简单的解决方案可以创建它吗 它应该是什么样子的: 一个快速解决方案是创建一个外圆、一个内圆、两条线,并用于创建一个新形状: public class Main extends Application { @Override public void start(Stage primaryStage) { try { Pane
JavaFX
中创建起点和终点角度可调的半圆。我试着使用Arc
或ArcTo
,但它从来没有给我需要的东西。有什么简单的解决方案可以创建它吗
它应该是什么样子的:
一个快速解决方案是创建一个外圆、一个内圆、两条线,并用于创建一个新形状:
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Pane root = new Pane();
double dist = 10;
double outerRadius = 100;
double innerRadius = 50;
Circle outerCircle = new Circle();
outerCircle.setRadius(outerRadius);
Circle innerCircle = new Circle();
innerCircle.setRadius(innerRadius);
Line topLeftBottomRightLine = new Line(-outerRadius, -outerRadius, outerRadius, outerRadius);
topLeftBottomRightLine.setStrokeWidth(dist);
Line bottomLeftTopRightLine = new Line(-outerRadius, outerRadius, outerRadius, -outerRadius);
bottomLeftTopRightLine.setStrokeWidth(dist);
Shape shape = Shape.subtract(outerCircle, innerCircle);
shape = Shape.subtract(shape, topLeftBottomRightLine);
shape = Shape.subtract(shape, bottomLeftTopRightLine);
shape.setStroke(Color.BLUE);
shape.setFill(Color.BLUE.deriveColor(1, 1, 1, 0.3));
shape.relocate(300, 100);
root.getChildren().addAll(shape);
Scene scene = new Scene(root, 800, 400);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
类似地,通过使用圆弧并从中减去一个内圈,您只能创建形状的一部分。看看,它看起来非常相似,并且还使用
arcTo
。一旦你有了其中一个,其他的就可以很容易地通过旋转得到。我从这个解开始,但它只创建了半个圆。但是没有选项可以像-45,45那样设置开始和结束角度。正如你说的,我只需要一个,然后对其余的使用旋转。我不知道你的开始和结束角度是什么意思