我想围绕这个椭圆形轨道旋转图像:
这是我的代码:
if(xloc >= 637 && yloc >= 275) //bottom-right quadrant image rotation statement
{
angle = Math.atan((double)(yloc-275)/(900-xloc));
//radians = Math.toRadians(angle);
//radians += Math.PI;
radians = Math.round(radians*10000000.0)/10000000.0;
}
else if(xloc >= 637 && yloc <= 275) //top-right quadrant image rotation statement
{
angle = Math.PI - Math.atan(yloc/(900-xloc));
//radians = Math.toRadians(angle);
radians = Math.round(radians*10000000.0)/10000000.0;
}
else if(xloc <= 263 && yloc <= 275) //top-left quadrant image rotation statement
{
angle = Math.PI + Math.atan(yloc/xloc);
//radians = Math.toRadians(angle);
radians = Math.round(radians*10000000.0)/10000000.0;
}
else if(xloc <= 264 && yloc >= 275) //bottom-left quadrant image rotation statement
{
angle = (2*Math.PI) - Math.atan((yloc-275)/xloc);
//radians = Math.toRadians(angle);
radians = Math.round(radians*10000000.0)/10000000.0;
}
//casting the graphics object to Graphics2D
Graphics2D g2d = (Graphics2D)g;
//AffineTransform object image rotation
AffineTransform a = AffineTransform.getRotateInstance(radians,xloc,yloc);
//moving the image at x and y locations
a.translate(xloc,yloc);
//drawing the user's horse chariot image and applying all transformations to the image when it is drawn
g2d.drawImage(horse,a,null);
为什么图像不会被旋转?我应该改变什么呢?