我试图从矩形中删除贝塞尔曲线。我有两种形状,但从Rectangle中减去Path2D对象时遇到一个小问题。这是它的样子:
正如您所看到的,我不希望曲线底部的线条。我的代码是这样的(无需担心值):
Path2D path1 = new Path2D.Double();
path1.moveTo(start_x, start_y);
path1.curveTo(control1_x, control1_y, control2_x, control2_y, end_x, end_y);
path1.append(new Line2D.Double(start_x, start_y, end_x, start_y), false);
path1.closePath();
g2.setColor(Color.BLUE);
Area shape = calculateOutside(path1);
g2.fill(shape);
此外,calculateOutside
方法:
private Area calculateOutside(Path2D path) {
Area outside = new Area(new Rectangle2D.Double(0, 0, width, height);
outside.subtract(new Area(path2D));
return outside;
}
我还尝试在该曲线下附加一行true
作为构造函数值。或尝试没有追加线。我错过了什么?
感谢您的帮助。
此外,如果有人需要,值:
int start_x = 60, start_y = 76;
int control1_x = 57, control1_y = 49;
int control2_x = 83, control2_y = 47;
int end_x = 80, end_y = 76;