title: Rotation around point in python (matrices)
body: <p>My teacher is not very good at relating math to code, so I was unable to figure this out from the lectures. </p>
  
  <p>In pygame(teacher wants us to use pygame+numpy for this assignment) I am supposed to rotate an object(image of planet) around a point(sun) by using matrices. I have found multiple ways to do this without matrices, but since we were specifically asked to do it with matrices, those are useless.</p>
  
  <p>I can't quite figure out how to change the center of my planet based on a matrix.
  Any pointers/hints. I want to do the programming myself to learn, so all I need is some pointers on how its done. Under is my current attempt.</p>
  
  <p>EDIT:
  For the record, I know that to rotate around a point you have to move as if you were moving the point to origin, rotate then move back same distance. I just need to know how to do this in code.</p>
  
  <pre><code>import sys,pygame, numpy, time
  from math import *
  
  pygame.init()
  
  size = width, height = 1280, 720
  black = 0,0,0
  
  screen = pygame.display.set_mode(size)
  
  sun = pygame.image.load("sun.png")
  sun.convert_alpha()
  sunRect = sun.get_rect()
  #Placing the sun to the left in the window
  sunRect = sunRect.move(20,200)
  
  #creating another object and placing it more to the right of the sun
  osuni = sun
  osuni = pygame.transform.scale(osuni,(40,40))
  osun = sun.get_rect()
  osun = osun.move(400,300)
  osua = numpy.array([400,300])
  
  #move object to center of sun
  move = numpy.array([[1,0,-20],[0,1,-200],[0,0,1]])
  #move object back
  back = numpy.array([[1,0,20],[0,1,200],[0,0,1]])
  #rotate object by 1 degree(for smooth movement)
  rotate = numpy.array([[numpy.cos(1),numpy.sin(1),0],[-numpy.sin(1),numpy.cos(1),0],[0,0,1]])
  #combinex matrix for simplicity
  movement = numpy.dot(back,numpy.dot(rotate,move))
  
  #standard pygame loop
  while 1:
      for event in pygame.event.get():
          if event.type == pygame.QUIT: sys.exit()
      time.sleep(0.1)
      #should move the object here
      screen.fill(black)
      screen.blit(sun,sunRect)
      screen.blit(osuni,osun)
      pygame.display.flip();
  </code></pre>