title: Transforming an Image to move diagnally
body: <pre><code>public void draw(Graphics g, Graphics g2d, double theta, int NEWY){
  
          g.setColor(Color.orange);
  
  
          int drawLocationX = character.x;
          int drawLocationY = character.y-47;
  
  
          double rotationRequired = Math.toRadians (theta);
          double locationX = this.getWidth()/2;
          double locationY = this.getHeight()/2;
          AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);
          AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
  
  
          g2d.drawImage(op.filter(image, null), drawLocationX, NEWY, null);
  }
  
          public int getHeightWorld(int x){
          //meant to find height of land at specified location
          int highest = 0;
          int checked = 0;
  
          for(int c = panel.HEIGHT-1; c &gt;= 0; c--){
  
              if(this.inColRange(x)&amp;&amp; this.inRowRange(c))
              if(LandList[c][x] == 2){
                  highest = c;
                  checked++;
              }
  
          }
  
          return (1000 - highest);
      }
  
  
      public double getAngleWorldT1(){
          //meant to find angle tank needs to be rotated at
          int g = this.getHeightWorld(tank1.getNEWX());
          int h = this.getHeightWorld((tank1.getWidth()+ tank1.getNEWX()));
          double trythis = this.NewEquation();
          int newg = tank1.getWidth()+ tank1.getNEWX();
          int newh = tank2.getWidth()+ tank2.getNEWX();
          double newery =  (trythis*newg);
          double newery2 =  (trythis*tank1.getNEWX());
          double newval = newery - newery2;
  
           double u = 5;
           double width = tank1.getWidth();
           if(Math.abs(h-g) &gt; tank1.getWidth()){
  
                u = width/(g-h);
  
           }
           else{
           u = (g-h)/width;
  
           }
  
          double p =  57.6846779*Math.asin(Math.toRadians(u));
  
          return p;
      }
  public double NewEquation(){
          int dividethis = 0;
          int subtractthis = 0;
          int numnegative = 0;
          for(int what = 0; what &lt; tank1.getWidth(); what++){
  
              if(Math.abs(this.getHeightWorld(what)-this.getHeightWorld(what-1)) &lt; 2){
              dividethis += this.getHeightWorld(what);
                  if(this.getHeightWorld(what)-this.getHeightWorld(what-1) &lt; 0){
                  numnegative++;
              }
              }
              else{
                  subtractthis++;
              }
          }
          dividethis = dividethis/(tank1.getWidth()-subtractthis);
          if((numnegative - tank1.getWidth()) &gt; tank1.getWidth()/2){
              dividethis = dividethis*-1;
          }
          return dividethis;
  
      }
      public void draw(Graphics g) {
          //MOVE TO DIFF METHOD
          int newy = this.getHeightWorld(tank1.getNEWX()) - tank1.getHeight();
          int newy2 = this.getHeightWorld(tank2.getNEWX()) - tank2.getHeight();
          if( LandList[newy][tank1.getNEWX()] == 2){
              while (LandList[newy][tank1.getNEWX()] == 2){
              newy--;
  //          System.out.println("FIRST HERE");
  //          System.out.println(newy);
              }
  //          System.out.println("FIRST");
          }
          if( LandList[newy+1][tank1.getNEWX()] != 2){
              while (LandList[newy+1][tank1.getNEWX()] != 2){
              newy++;
  //          System.out.println("SECOND HERE");
              }
  //          System.out.println("SECOND");
          }
  
  //System.out.println("YESSSSS" +Math.toDegrees(this.getAngleWorldT1()) );
          tank1.draw(g, g, Math.toDegrees(this.getAngleWorldT1()), newy - tank1.getHeight()-50);
          tank2.draw(g, g, Math.toDegrees(this.getAngleWorldT2()), newy2 - tank2.getHeight());
  
  
          //      System.out.println("2");
          for(int x = 0; x &lt; platforms.size(); x++){
              platforms.get(x).draw(g);
          }
  
      }
  
  }
  </code></pre>
  
  <p>(Sorry for the messy code.)</p>
  
  <p>These are two classes I am using to design a tank shooter game. In this portion, I am attempting to make the image rotate according to the land it is over(to appear traveling uphill or downhill) and I don't want any piece inside of the land. "LandList" is a 2D array that has a value of 2 if there is land and 1 if there is no land. Two issues is A) rotating at incorrect heights and not rotating at all points
  B)Image cuts off at a certain height</p>
  
  <p>Thank you for your help.</p>
  
  <p>BOTH CLASSES IN FULL</p>
  
  <pre><code>public class World {
  
      Land[][] land;
      List&lt;Land&gt; platforms = new ArrayList&lt;Land&gt;();
  
  
      private GraphicsPanel panel;
      int[][] LandList = new int[800][1500];
      private int delay = 30;
      private Timer timer;
      private Random r;
      Tank tank1;
      Tank tank2;
  
      public World(GraphicsPanel marioPanel) {
  
          panel = marioPanel;
          land = new Land[panel.WIDTH][panel.HEIGHT-500-3];
  
          setUpWorld();
          setUpTimer();
  
      }
  
      private void setUpWorld() {
  
          for(int r = 0; r &lt; panel.WIDTH; r++){
              for(int c = 0; c &lt; panel.HEIGHT; c++){
                  LandList[c][r] = 1;
              }
          }
          //tank not displaying
          //a lot of stuff copied over
          tank1 = new Tank(25,442,100,60,1);
          tank2 = new Tank(700,442,100,60,2);
          r = new Random();
  
          int w = 0;
          int n = 0;
          for(int x = 0; x &lt; panel.WIDTH; x+=5){
              if(x &gt; 0 &amp;&amp; x &lt; panel.WIDTH/6 +1){
  
                  //for(int y = (int) (500+(-(100*Math.random())*((x%2)+1))); y &lt; panel.HEIGHT; y+=5){
                  for(int y = 500; y &lt; panel.HEIGHT; y+=5){
                      Land creating = new Land(x, y, 5, 5);
                      platforms.add(creating);
                      for(int r = 0; r &lt; 5; r++){
                          for(int c = 0; c &lt; 5; c++){
                              if(inRowRange(x+r) &amp;&amp; inColRange(y+c))
                                  LandList[y+r][x+c] = 2;
                          }
                      }
                  }
  
              }
              if(x &gt; panel.WIDTH/6 &amp;&amp; x &lt; 2*panel.WIDTH/6 +1){
  
                  //for(int y = (int) (500+(-(100*Math.random())*((x%2)+1))); y &lt; panel.HEIGHT; y+=5){
                  for(int y = 500+ 4*w; y &lt; panel.HEIGHT; y+=5){
                      Land creating = new Land(x, y, 5, 5);
                      platforms.add(creating);
                      for(int r = 0; r &lt; 5; r++){
                          for(int c = 0; c &lt; 5; c++){
                              if(inRowRange(y+r) &amp;&amp; inColRange(x+c))
                                  LandList[y+r][x+c] = 2;
                          }
                      }
  
                  }
                  w--;
              }
              if(x &gt; 2*panel.WIDTH/6 &amp;&amp; x &lt; 3*panel.WIDTH/6 +1){
  
                  //for(int y = (int) (500+(-(100*Math.random())*((x%2)+1))); y &lt; panel.HEIGHT; y+=5){
                  for(int y = 500+ 4*w; y &lt; panel.HEIGHT; y+=5){
                      Land creating = new Land(x, y, 5, 5);
                      platforms.add(creating);
                      for(int r = 0; r &lt; 5; r++){
                          for(int c = 0; c &lt; 5; c++){
                              if(inRowRange(y+r) &amp;&amp; inColRange(x+c))
                                  LandList[y+r][x+c] = 2;
                          }
                      }
  
                  }
                  w++;
              }
              if(x &gt; 3*panel.WIDTH/6 &amp;&amp; x &lt; 4*panel.WIDTH/6 +1){
  
                  //for(int y = (int) (500+(-(100*Math.random())*((x%2)+1))); y &lt; panel.HEIGHT; y+=5){
                  for(int y = 500+ 4*n; y &lt; panel.HEIGHT; y+=5){
                      Land creating = new Land(x, y, 5, 5);
                      platforms.add(creating);
                      for(int r = 0; r &lt; 5; r++){
                          for(int c = 0; c &lt; 5; c++){
                              if(inRowRange(y+r) &amp;&amp; inColRange(x+c))
                                  LandList[y+r][x+c] = 2;
                          }
                      }
  
                  }
                  n--;
              }
              if(x &gt; 4*panel.WIDTH/6 &amp;&amp; x &lt; 5*panel.WIDTH/6 +1){
  
                  //for(int y = (int) (500+(-(100*Math.random())*((x%2)+1))); y &lt; panel.HEIGHT; y+=5){
                  for(int y = 500+ 4*n; y &lt; panel.HEIGHT; y+=5){
                      Land creating = new Land(x, y, 5, 5);
                      platforms.add(creating);
                      for(int r = 0; r &lt; 5; r++){
                          for(int c = 0; c &lt; 5; c++){
                              if(inRowRange(y+r) &amp;&amp; inColRange(x+c))
                                  LandList[y+r][x+c] = 2;
  
                          }
                      }
  
                  }
                  n++;
              }
              if(x &gt; 5*panel.WIDTH/6){
  
                  //for(int y = (int) (500+(-(100*Math.random())*((x%2)+1))); y &lt; panel.HEIGHT; y+=5){
                  for(int y = 500; y &lt; panel.HEIGHT; y+=5){
                      Land creating = new Land(x, y, 5, 5);
                      platforms.add(creating);
                      for(int r = 0; r &lt; 5; r++){
                          for(int c = 0; c &lt; 5; c++){
                              if(inRowRange(y+r) &amp;&amp; inColRange(x+c))
                              LandList[y+r][x+c] = 2;
                          //  System.out.println(LandList[x+r][y+c]);
                          }
                      }
  
                  }
  
              }
              //              else{
              //                  for(int y = 500; y &lt; panel.HEIGHT; y+=5){
              //                      Land creating = new Land(x, y, 5, 5);
              //                      platforms.add(creating);
              //                  }
              //              
              //              }
          }
          for(int r = 0; r &lt; panel.WIDTH; r++){
              for(int c = 0; c &lt; panel.HEIGHT; c++){
                  //System.out.println(LandList[r][c]);
              }
          }
          for(int checked = 0; checked &lt; panel.WIDTH; checked++){
              System.out.println(this.getHeightWorld(checked));
          }
  //      System.out.println(LandList);
      }
  
  
  
      private boolean inColRange(int i) {
          // TODO Auto-generated method stub
          return i&gt;=0 &amp;&amp; i&lt;LandList[0].length;
      }
  
      private boolean inRowRange(int i) {
          // TODO Auto-generated method stub
          return i&gt;=0 &amp;&amp; i&lt;LandList.length;
      }
  
      private void setUpTimer() {
          timer = new Timer(delay, new ActionListener() {
  
              @Override
              public void actionPerformed(ActionEvent arg0) {
                  // what should happen each time the timer goes off?
  
                  panel.repaint();
                  moveStuff();
                  checkHitBoxes();
                  //System.out.println(mario.getY());
  
              }
  
          });
          timer.start();
      }
  
  
  
      protected void checkHitBoxes() {
  
      }
  
  
      protected void moveStuff() {
          tank1.move();
          panel.repaint();
  
      }
  
      public int getHeightWorld(int x){
          //meant to find height of land at specified location
          int highest = 0;
          int checked = 0;
  
          for(int c = panel.HEIGHT-1; c &gt;= 0; c--){
  
              if(this.inColRange(x)&amp;&amp; this.inRowRange(c))
              if(LandList[c][x] == 2){
                  highest = c;
                  checked++;
              }
  
          }
  
          return (1000 - highest);
      }
  
  
      public double getAngleWorldT1(){
          //meant to find angle tank needs to be rotated at
          int g = this.getHeightWorld(tank1.getNEWX());
          int h = this.getHeightWorld((tank1.getWidth()+ tank1.getNEWX()));
          double trythis = this.NewEquation();
          int newg = tank1.getWidth()+ tank1.getNEWX();
          int newh = tank2.getWidth()+ tank2.getNEWX();
          double newery =  (trythis*newg);
          double newery2 =  (trythis*tank1.getNEWX());
          double newval = newery - newery2;
  
           double u = 5;
           double width = tank1.getWidth();
           if(Math.abs(h-g) &gt; tank1.getWidth()){
  
                u = width/(g-h);
  
           }
           else{
           u = (g-h)/width;
  
           }
  
          double p =  57.6846779*Math.asin(Math.toRadians(u));
  
          return p;
      }
      public double getAngleWorldT2(){
          int a = this.getHeightWorld(tank2.getNEWX());
          int s = this.getHeightWorld((tank2.getWidth() + tank2.getNEWX() + 100) );
  //       a = 100;
  //       s = 700;
          int o = (a-s)/tank2.getWidth();
          //System.out.println(o);
          double p =  -57.6846779*(Math.asin(Math.toRadians(o)));
          //System.out.println(p);
          return p;
  
  
      }
  
      public double NewEquation(){
          int dividethis = 0;
          int subtractthis = 0;
          int numnegative = 0;
          for(int what = 0; what &lt; tank1.getWidth(); what++){
  
              if(Math.abs(this.getHeightWorld(what)-this.getHeightWorld(what-1)) &lt; 2){
              dividethis += this.getHeightWorld(what);
                  if(this.getHeightWorld(what)-this.getHeightWorld(what-1) &lt; 0){
                  numnegative++;
              }
              }
              else{
                  subtractthis++;
              }
          }
          dividethis = dividethis/(tank1.getWidth()-subtractthis);
          if((numnegative - tank1.getWidth()) &gt; tank1.getWidth()/2){
              dividethis = dividethis*-1;
          }
          return dividethis;
  
      }
      public void draw(Graphics g) {
          //MOVE TO DIFF METHOD
          int newy = this.getHeightWorld(tank1.getNEWX()) - tank1.getHeight();
          int newy2 = this.getHeightWorld(tank2.getNEWX()) - tank2.getHeight();
          if( LandList[newy][tank1.getNEWX()] == 2){
              while (LandList[newy][tank1.getNEWX()] == 2){
              newy--;
  //          System.out.println("FIRST HERE");
  //          System.out.println(newy);
              }
  //          System.out.println("FIRST");
          }
          if( LandList[newy+1][tank1.getNEWX()] != 2){
              while (LandList[newy+1][tank1.getNEWX()] != 2){
              newy++;
  //          System.out.println("SECOND HERE");
              }
  //          System.out.println("SECOND");
          }
  
  //System.out.println("YESSSSS" +Math.toDegrees(this.getAngleWorldT1()) );
          tank1.draw(g, g, Math.toDegrees(this.getAngleWorldT1()), newy - tank1.getHeight()-50);
          tank2.draw(g, g, Math.toDegrees(this.getAngleWorldT2()), newy2 - tank2.getHeight());
  
  
          //      System.out.println("2");
          for(int x = 0; x &lt; platforms.size(); x++){
              platforms.get(x).draw(g);
          }
  
      }
  
  }
  
  public class Tank extends Moveable{
  
  
      private boolean moveRight,moveLeft;
      private String direction = "NONE";
      private int dx =5;
  
      //graphics
      BufferedImage image = null;
      private URL file;
      private Rectangle character;
      private Rectangle hitBox;
      JLabel label = new JLabel();
       private int NEWX;
  
      public Tank(int x, int y, int w, int h, int color){
  
  
          character = new Rectangle(x,y,w,h);
  
          this.create(null,x,y,w,h);
          NEWX = character.x;
          BufferedImage img =null;
          if(color == 1){
  //          file= getClass().getResource("pictures\\green_tank1"); 
              try {
                  img = ImageIO.read(new File("green_tank1.png"));
                  image = img;
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
          else{
  //          file = getClass().getResource("pictures\\blue_tank1");
              try {
                  img = ImageIO.read(new File("blue_tank1.png"));
                  image = img;
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
  
      }
  
      public void draw(Graphics g, Graphics g2d, double theta, int NEWY){
  
          g.setColor(Color.orange);
  
  
          int drawLocationX = character.x;
          int drawLocationY = character.y-47;
  
  
          double rotationRequired = Math.toRadians (theta);
          double locationX = this.getWidth()/2;
          double locationY = this.getHeight()/2;
          AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);
          AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
  
  
          g2d.drawImage(op.filter(image, null), drawLocationX, NEWY, null);
          //System.out.println("This is new X " + NEWX);
  //      label.setVisible(true);
  //      label.isOpaque();
  //      label.setBounds(character.x, character.y, character.width, character.height);
  //      label.repaint();
          //g.drawImage(image, 0, 0, null);
  //      int centerx = character.x + character.width/2;
  //      int centery = character.y + character.height/2;
  //  
  //      int point1 = (int) (centerx + (character.width/2)*Math.cos(Math.toRadians(theta)) - (character.height/2)* Math.sin(Math.toRadians(theta)));
  //      int point2 = (int) (centery + (character.height/2)*Math.cos(Math.toRadians(theta))+(character.width/2)*Math.sin(Math.toRadians(theta)));
  //      int point3 =(int) (centerx - (character.width/2)*Math.cos(Math.toRadians(theta)) + (character.height/2)* Math.sin(Math.toRadians(theta)));
  //      int point4 = (int) (centery - (character.height/2)*Math.cos(Math.toRadians(theta))-(character.width/2)*Math.sin(Math.toRadians(theta)));
  //      //System.out.println(theta);
  //      g.drawImage(image, point1,point2,point3,point4, null);
  ////        System.out.println("3");
  
  
  
          // Rotation information
  
  
  
  //      AffineTransform tx = AffineTransform.getRotateInstance(Math.toRadians (theta), character.x, character.y);
  //      AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
  //  
  //      // Drawing the rotated image at the required drawing locations
  //      g.drawImage(op.filter((BufferedImage) image, null), character.x, character.y, null);
  
  
  
  
  
  //      System.out.println(this.getX());
  //      System.out.println(this.getY());
  //      System.out.println(this.getWidth());
  //      System.out.println(this.getHeight());
  //      g.fillRect(this.getX(), this.getY(), this.getWidth(), this.getHeight());
  //      this.setBounds(this.getX(), this.getY(), this.getWidth(), this.getHeight());
  //      
      }
  
  
  
      public Rectangle getRect(){
          return this.character;
      }
      public void move(){
  
          if(moveLeft == true){
  
              character.setBounds(character.x -2, character.y, character.width, character.height);
              character.x = character.x -2;
              NEWX += -2;
          }
          if(moveRight == true){
              character.setBounds(character.x +2, character.y, character.width, character.height);
              character.x = character.x +2;
              NEWX += 2;
          }
  
      }
      public void setDirection(String s){
          this.direction =  s;
          String x = s.toUpperCase().substring(0, 1);
  
          if(x.equals("L")){
              //System.out.println(x);
              moveLeft = true;
  
              moveRight = false;
  
  
          }
          if(x.equals("R")){
              moveRight = true;
  
              moveLeft = false;
  //          System.out.println("im here");
  
          }
          else if(x.equals("N")){
              moveRight = false;
              moveLeft =false;
  //          System.out.println("I Got Here #2");
          }
      }
  
      public String getDirection(){
          return this.direction;
      }
  
      public int getNEWX(){
          return this.NEWX;
      }
  
  
  }
  </code></pre>