Rotation an object around his center using vpython
Question: I'm making a moonlander game using VPython. The moonlander itself must be able
to rotate around his own center, but he rotates around the wrong axis and/or
around his original position instead. The axis and position where it has to
rotate around don't change when the position of the moonlander changes. I
don't know how to do this.

The moonlander is made of curves, but I have a frame that contains the
moonlander. Here is the code (sorry about the code being in dutch, I hope you
understand enough):

    
    
    from visual import *
    from math import *
    from random import randint
    maanoppervlak = curve(pos=[(-20,-2),(-18,-5)],color=color.red)
    maanoppervlak.append(pos=(-18,-5))
    maanoppervlak.append(pos=(-15,-4),color=color.red)
    maanoppervlak.append(pos=(-15,-4))
    maanoppervlak.append(pos=(-14,-4),color=color.red)
    maanoppervlak.append(pos=(-14,-4))
    maanoppervlak.append(pos=(-13,-15),color=color.red)
    maanoppervlak.append(pos=(-13,-15), color=color.green)
    maanoppervlak.append(pos=(-7,-15),color=color.green)
    maanoppervlak.append(pos=(-7,-15),color=color.red)
    maanoppervlak.append(pos=(-3,4),color=color.red)
    maanoppervlak.append(pos=(-3,4))
    maanoppervlak.append(pos=(-1,0),color=color.red)
    maanoppervlak.append(pos=(-1,0))
    maanoppervlak.append(pos=(3,-2),color=color.red)
    maanoppervlak.append(pos=(3,-2),color=color.green)
    maanoppervlak.append(pos=(8,-2),color=color.green)
    maanoppervlak.append(pos=(8,-2),color=color.red)
    maanoppervlak.append(pos=(13,-8),color=color.red)
    maanoppervlak.append(pos=(13,-8))
    maanoppervlak.append(pos=(16,-5),color=color.red)
    maanoppervlak.append(pos=(16,-5))
    maanoppervlak.append(pos=(19,-12),color=color.red)
    maanoppervlak.append(pos=(19,-12))
    maanoppervlak.append(pos=(20,-7), color=color.red)
    
    print scene.width
    
    f = frame() #maken van een frame waar de maanlander in zit
    f.axis = (1,0,0)
    f.pos = vector(-4,-10,0)
    maanlander = curve(frame=f, pos=[(1,1),(2,1),(1.5,1),(1.5,2),(2,2.5),(2,3.5),(2.75,3.5),
    (2.25,4),(2.25,4.5),(2.75,5),(3.75,5),(4.25,4.5),
    (4.25,4),(3.75,3.5),(4.5,3.5),(4.5,2.5),(3.5,2.5),(3.75,2),
    (2.75,2),(3,2.5),(2,2.5),(4.5,2.5),(5,2),(5,1),(4.5,1),
    (5.5,1)],color=color.blue)
    maanlander.accel = vector(0,0) #acceleratie van de maanlander
    f.accel = vector(0,0) #acceleratie van de frame (deze of die hierboven is waarschijnlijk overbodig)
    f.velocity = vector(0,0) #snelheid van de frame
    deltat = 0.005
    state = true
    while state == true: #start van de loop
        rate(100)
        f.velocity = f.velocity + maanlander.accel*deltat #bepaalt de snelheid adhv de accel.
        maanlander.pos = maanlander.pos + f.velocity*deltat #bepaalt de positie adhv de snelheid
        if scene.kb.keys: # is there an event waiting to be processed?
                s = scene.kb.getkey() # obtain keyboard information
                if s == 'left': #er wordt op linkertoets gedrukt
                    f.rotate(angle=pi/15., axis=(0,0,1), origin=(f.pos + vector(2.75,2.5,0))) #object moet rond zijn middden draaien (werkt nog niet)
                elif s == 'right':
                    f.rotate(angle=-pi/15., axis=(0,0,1), origin=vector(2.75,2.5,0)) #zelfde als bij left, maar in omgekeerde richting
                elif s == 'up': #'boost'
                    maanlander.accel = maanlander.accel + vector(0,10)
    

So, how can you rotate the moonlander, and also when it has a different
position than its original one?

Thanks in advance


Answer: Ignacio is saying translate your moonlander to the origin (the `center`) then
rotate everything about the center, then translate it back to where it was.

