如何从 JavaFX 中的路径中正确减去形状

How to properly subtract a shape from a Path in JavaFX

我的 JavaFX 应用程序绘制多达 10 种不同类型的形状。其中一些比较复杂,必须用 Path 绘制成一系列直线和圆弧。一些形状是负区域,它们将从它们重叠的任何形状中减去。

我发现从基本的 Javafx 形状(例如圆形和矩形)中减去可以按预期工作,但从 Path 制作的形状却不行。

显示的重叠形状:

相减结果:

如您所见,该形状已从圆中正确减去,但尝试从 "fillet" 形状中减去椭圆只会留下一个间隙,并且线条为 darker/thicker 因为它试图闭合通过回溯到间隙的另一端而不是绘制重叠区域来缩小间隙。

下面是绘制图中所示复杂形状的代码

//Here the v shape is drawn from right to left
Path path = new Path();
path.getElements().add(new MoveTo(firstLineXposition, firstLineYposition));
path.getElements().add(new LineTo(originX, originY));
path.getElements().add(new LineTo(secondLineXPos, secondLineYPos));

//here the arc is drawn from top left point to the top right point      
ArcTo arc = new ArcTo();
arc.setX(firstLineXposition);
arc.setY(firstLineYposition);
arc.setRadiusX(radiusPositionX);
arc.setRadiusY(radiusPositionY);
path.getElements().add(arc);
path.getElements().add(new ClosePath());

我猜想在使用 Path 绘制这些形状时遗漏了一个步骤,它应该被视为一个整体形状,而不是被视为一系列线条。

我假设您的路径未填充(未设置填充颜色)。所以我猜你只是与轮廓笔画定义的区域相交。