title: Rotating a triangle around a fixed point
body: <p>I'm trying to recreate the game Asteroids and I'm currently getting the ship to display and move on the screen. At the moment I've got the function below which draws a triangle on the screen around an origin. What I'm trying to do is rotate the ship around the origin too.</p>
  
  <p>At the moment the triangle gets completely warped by this function and I'm not sure what's going wrong. The angle I'm trying to rotate around is <code>shipHeading</code> and I'm trying to follow this formula:</p>
  
  <p><code>x' = x cos f - y sin f</code>
  <code>y' = y cos f + x sin f</code></p>
  
  <p>where f is equal to the angle of rotation</p>
  
  <pre><code>void drawShip(void){
      int shipX = getShipX();
      int shipY = getShipY();
      int shipHeading = getShipHeading();
  
      int x1, y1, x2, y2, x3, y3;
  
      x1 = shipX;
      y1 = shipY - 20;
      x2 = shipX - 10;
      y2 = shipY + 10;
      x3 = shipX + 10;
      y3 = shipY + 10;
  
      screen-&gt;drawTriangle(x1, y1, x2, y2, x3, y3, RED); //pre rotation
  
      x1 = (x1 * cos(double(shipHeading))) - (y1 * sin(double(shipHeading)));
      y1 = (x1 * sin(double(shipHeading))) + (y1 * cos(double(shipHeading)));
      x2 = (x2 * cos(double(shipHeading))) - (y2 * sin(double(shipHeading)));
      y2 = (x2 * sin(double(shipHeading))) + (y2 * cos(double(shipHeading)));
      x3 = (x3 * cos(double(shipHeading))) - (y3 * sin(double(shipHeading)));
      y3 = (x3 * sin(double(shipHeading))) + (y3 * cos(double(shipHeading)));
  
      x1 *= -1;
      y1 *= -1;
      x2 *= -1;
      y2 *= -1;
      x3 *= -1;
      y3 *= -1;
  
      screen-&gt;drawTriangle(x1, y1, x2, y2, x3, y3, BLUE); //post rotation
  </code></pre>