[英]How can I get a Point on a rotated image?
对于使用Graphics2D绘制的图像,我需要访问左下角的坐标(或图像上的其他3个点)。 问题是图像旋转了。 这是paintComponent()
方法:
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
//Makes a white background
g2d.setColor(Color.WHITE);
g2d.fill(new Rectangle2D.Float(0, 0, (float)Toolkit.getDefaultToolkit().getScreenSize().getWidth(), (float)Toolkit.getDefaultToolkit().getScreenSize().getHeight()));
//Draws Images & rotates
g2d.rotate(Math.toRadians(rocketAngle), r.getxPos() + (r.getImage().getWidth()/2), r.getyPos());
g2d.drawImage(r.getImage(), r.getxPos(), r.getyPos(), this);
}
(其中“ r”是包含照片的对象)
通常,我会将图像的高度添加到图像的绘制点上,但这不起作用,因为图像已旋转。 有谁知道如何做到这一点?
因此,您在原始坐标系(CS1)中具有以下几点:
CS1:
Left bottom: lb(0, h)
Right bottom: rb(w, h)
Right top: rt(w, 0)
Left top: lt(0, 0)
您想围绕点v(w / 2,0)旋转图片。 为此,让我们介绍一个新的坐标系,其中心为点v(CS2):
CS2:
x' = x-w/2
y' = y
现在让我们介绍CS3,它是CS2旋转角度phi:
CS3:
x'' = x'*cos phi - y'*sin phi = (x-w/2)*cos phi - y*sin phi
y'' = x'*sin phi + y'*cos phi = (x-w/2)*sin phi + y*cos phi
现在,您要获取CS3中CS1的点lb,rb,rt,lt的坐标:
lb'' = (-(w/2)*cos phi - h*sin phi, -(w/2)*sin phi + h*cos phi)
我希望你有主意
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.