我用这段代码绘制了一个倾斜的矩形:
public void paint(Graphics g){
Graphics2D g2 = (Graphics2D)g;
for (int i = 0;i < this.width ;i++) {
Line2D line = new Line2D.Double(this.x + Math.sin(this.theta) * (width / 2 - i) + Math.cos(this.theta) * this.length / 2
, this.y + Math.cos(this.theta) * (width / 2 - i) - Math.sin(this.theta) * this.length / 2
, this.x + Math.sin(this.theta) * (width / 2 - i) - Math.cos(this.theta) * this.length / 2
, this.y + Math.cos(this.theta) * (width / 2 - i) + Math.sin(this.theta) * this.length / 2);
g2.draw(line);
}
}
但输出是theta = Math.PI/4
:更像是条形码
你能帮我展示一下如何解决这个问题吗?