0

I want to rotate a image around this oval track:

enter image description here

This is my code:

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);

Why isn't the image being rotated? What should I change so that it will?

Bentaye
  • 9,403
  • 5
  • 32
  • 45
Anushka
  • 35
  • 4
  • Check out this similar question: https://stackoverflow.com/questions/8639567/java-rotating-images – bcr Apr 29 '18 at 00:28
  • 2
    Possible duplicate of [Java: Rotating Images](https://stackoverflow.com/questions/8639567/java-rotating-images) – bcr Apr 29 '18 at 00:29
  • I'm thinking you probably want something more [like this](https://stackoverflow.com/questions/32392095/how-to-rotate-a-rectangle-after-reaching-specified-position/32397121#32397121) – MadProgrammer May 01 '18 at 04:15

0 Answers0