title: Relationship Between AffineTransformation and Polygon's Point
body: <p>As a project, I'm attempting to create an emulation of the game Asteroids. Currently, I'm trying to make it so then the spaceship appears on the opposite side of the GUI if the player ever sends himself out of bounds.</p>
  
  <p>However, I've become quite confused between how AffineTransformation's rotate and createTransformedShape function interacts with the x and y points of the polygon. </p>
  
  <p>Currently, I have the spaceship working; it flies in the angle the user specifies it and all the movement involved works fine. However, when I tried to get the lowest X coordinate of the spaceship to compare if it ever goes bigger than the constant <code>WIDTH</code>, it returns 780. This happens all the time whether or not I am on one side of the map to the other, it always returns 780. This I find really strange because shouldn't it return the smallest X coordinate of where it currently is? 
  <a href="https://i.stack.imgur.com/RA7rt.png" rel="nofollow noreferrer">Here is a screenshot of the console displaying that the "smallest x coordinate" of the polygon is 780, despite not being at 780</a></p>
  
  <p>Can someone explain to me why the X coordinates of the polygon are not changing? I have 2 classes. One, which is the driver classes, and the other which is the ship class which extends Polygon.</p>
  
  <pre><code>public class AsteroidGame implements ActionListener, KeyListener{
  
      public static AsteroidGame game;
      public Renderer renderer;
  
      public boolean keyDown = false;
      public int playerAngle = 0;
  
      public boolean left = false;
      public boolean right = false;
      public boolean go = false;
      public boolean back = false;
      public boolean still = true;
      public double angle = 0;
      public int turnRight = 5;
      public int turnLeft = -5;
  
      public Shape transformed;
      public Shape transformedLine;
  
      public Point p1;
      public Point p2;
      public Point center;
      public Point p4;
  
      public final int WIDTH = 1600;
      public final int HEIGHT = 800;
  
      public Ship ship;
  
  
      public AffineTransform transform = new AffineTransform();
  
      public AsteroidGame(){
          JFrame jframe = new JFrame();
          Timer timer = new Timer(20, this);
          renderer = new Renderer();
  
          jframe.add(renderer);
          jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          jframe.setSize(WIDTH, HEIGHT);
          jframe.setVisible(true);
          jframe.addKeyListener(this);
          jframe.setResizable(false);
  
          int xPoints[] = {800, 780, 800, 820};
          int yPoints[] = {400, 460, 440, 460}; 
  
          p1 = new Point(400,400);
          p2 = new Point(380, 460);
          center = new Point(400,440);//center
          p4 = new Point(420, 460);
  
          ship = new Ship(xPoints, yPoints, 4, 0);
          transformed = transform.createTransformedShape(ship);
  
          timer.start();
  
      }
  
      public void repaint(Graphics g){
  
          g.setColor(Color.BLACK);
          g.fillRect(0, 0, WIDTH, HEIGHT);
  
  
  
          Graphics2D g2d = (Graphics2D)g;
  
          g2d.setColor(Color.WHITE);
          g2d.draw(transformed);
  
  
          /*
          g2d.draw(r2);
          Path2D.Double path = new Path2D.Double();
          path.append(r, false);
          AffineTransform t = new AffineTransform();
          t.rotate(Math.toRadians(45));
          path.transform(t);
          g2d.draw(path);
  
  
          Rectangle test = new Rectangle(WIDTH/2, HEIGHT/2, 200, 100);
          Rectangle test2 = new Rectangle(WIDTH/2, HEIGHT/2, 200, 100);
  
          g2d.draw(test2);
          AffineTransform at = AffineTransform.getTranslateInstance(100, 100);
          g2d.rotate(Math.toRadians(45));
          g2d.draw(test);
          */
  
  
  
  
      }
  
  
  
      public void actionPerformed(ActionEvent arg0) {
          // TODO Auto-generated method stub
          if (right){
              ship.right();
  
              transform.rotate(Math.toRadians(turnRight), ship.getCenterX(), ship.getCenterY());
              System.out.println(ship.getCenterY());
  
          }
  
          else if (left){
              ship.left(); 
  
              transform.rotate(Math.toRadians(turnLeft), ship.getCenterX(), ship.getCenterY());
  
          }
          if (go){
              ship.go();
  
              //ship.x += Math.sin(Math.toRadians(angle)) * 5;
              //ship.y
              /*
              ship.x += (int) Math.sin(Math.toRadians(angle));
              ship.y += (int) Math.cos(Math.toRadians(angle));
              */
              //System.out.println(Math.sin(Math.toRadians(ship.angle)) * 5 + "y" + Math.cos(Math.toRadians(ship.angle)) * 5);
  
          }
          else if (back){
              ship.reverse();
          }
          ship.move();
          //ship.decrement();
  
          transformed = transform.createTransformedShape(ship);
  
          if (ship.smallestX() &gt;= WIDTH){
              System.out.println("out");
          }
          renderer.repaint();
          System.out.println("Smallest x coordinate: " + ship.smallestX());
  
      }
  
      public static void main(String[] args){
          game = new AsteroidGame();
      }
  
      @Override
      public void keyPressed(KeyEvent e) {
          // TODO Auto-generated method stub
          if (e.getKeyCode() == KeyEvent.VK_RIGHT){
              System.out.println("I am down");
              right = true;
              keyDown = true;
          }else if (e.getKeyCode() == KeyEvent.VK_LEFT){
              left = true;
              System.out.println("I am down");
              keyDown = true;
          }
  
          if (e.getKeyCode() == KeyEvent.VK_UP){
              go = true;
          }
          else if (e.getKeyCode() == KeyEvent.VK_DOWN){
              back = true;
          }
  
  
      }
  
      @Override
      public void keyReleased(KeyEvent e) {
          // TODO Auto-generated method stub
          if (e.getKeyCode() == KeyEvent.VK_RIGHT){
              right = false;
          }
          if (e.getKeyCode() == KeyEvent.VK_LEFT){
              left = false;
          }
          if (e.getKeyCode() == KeyEvent.VK_UP){
              go = false;
          }
          if (e.getKeyCode() == KeyEvent.VK_DOWN){
              back = false;
          }
          still = true;
          keyDown = false;
          System.out.println("up");
      }
  
      @Override
      public void keyTyped(KeyEvent e) {
          // TODO Auto-generated method stub
  
      }
  </code></pre>
  
  <p>Ship Class:</p>
  
  <pre><code>public class Ship extends Polygon{
  
      /**
       * 
       */
      private double currSpeed = 0;
  
      private static final long serialVersionUID = 1L;
      public double angle;
  
      public Ship(int[] x, int[] y, int points, double angle){
          super(x, y, points);
          this.angle= angle;
      }
  
      public void right(){
          angle += 5;
      }
      public void left(){
          angle -= 5;
      }
  
      public void move(){
          for (int i = 0; i &lt; super.ypoints.length; i++){
              super.ypoints[i] -= currSpeed;
              //System.out.println(super.ypoints[i]);
              //System.out.println(super.xpoints[i]);
          }
      }
  
  
      public void reverse(){
          if (currSpeed  &gt; -15) currSpeed -= 0.2;
      }
  
      public void go(){
          if (currSpeed &lt; 25) currSpeed += 0.5;
  
      }
      public int smallestX(){
          int min = super.xpoints[0];
          for (int i = 0; i &lt; super.xpoints.length; i++){
              if (min &gt; super.xpoints[i]){
                  min = super.xpoints[i];
              }
          }
          return min;
      }
      public int smallestY(){
          int min = super.ypoints[0];
          for (int i = 0; i &lt; super.ypoints.length; i++){
              if (min &lt; super.ypoints[i]){
                  min = super.ypoints[i];
              }
          }
          return min;
      }
  
      public int getCenterX(){
          return super.xpoints[2];
      }
      public int getCenterY(){
          return super.ypoints[2];
      }
  
      public double getAng(){
          return angle;
      }
  </code></pre>