我正在尝试绘制某种类型的多边形,但我无法让它工作。我的公式错了吗?如果是这样,你能帮帮我吗?
我想使用 Java.awt.polygon 绘制一个多边形
TMP = new Polygon();
// this.getX() and this.getY() return an int
// consider getX() and getY() as x0 and y0
int x1,x2,x3,x4;
int y1,y2,y3,y4;
x1 = (int) Math.round(this.getX() - this.getLength() * Math.cos(this.getAngle()));
y1 = (int) Math.round(this.getY() - this.getLength() * Math.sin(this.getAngle()));
x3 = (int) Math.round(x1 - this.getWidth() * Math.cos((Math.PI / 2) - this.getAngle()));
y3 = (int) Math.round(y1 + this.getWidth() * Math.sin((Math.PI/2) - this.getAngle()));
x4 = (int) Math.round(this.getX() - this.getWidth() * Math.cos((Math.PI/2) - this.getAngle()));
y4 = (int) Math.round(this.getX() + this.getWidth() * Math.sin((Math.PI/2) - this.getAngle()));
x2 = (int) Math.round((x1 + x3) / 2 + Math.cos(this.getAngle()) * this.getLength() / 2);
y2 = (int) Math.round((y1 + y3) / 2 + Math.sin(this.getAngle()) * this.getLength() / 2);
TMP.addPoint(this.getX(), this.getY());
TMP.addPoint(x1, y1);
TMP.addPoint(x2, y2);
TMP.addPoint(x3, y3);
TMP.addPoint(x4, y4);
this.setPolygon(TMP);
这就是我所期望的 https://i.gyazo.com/bdd8510d0128bab6347bb6c110f03c92.png
我得到了这个 https://i.gyazo.com/55a00ae07d4f31732db12805fa592aec.png