绘制一个倾斜的矩形

时间:2016-05-22 11:09:31

标签: java swing paint

我用这段代码绘制了一个倾斜的矩形:

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:更像是条形码

你能帮我展示一下如何解决这个问题吗?

0 个答案:

没有答案