From: Stefan P. <ste...@ur...> - 2007-02-01 16:28:37
|
When rotating a frame inside a class, it starts to move and rotates around some mysterious center. I could not find out how to calculate origin for a propper offset. Please find attached my example. I would be glad for any hint. Thanks in advance, Mit freundlichen Grüßen / With kindest regards Stefan Paulick http://www.urbeli.com mailto://ste...@ur... /*----------------------*/ import time import visual b = visual.box(height = .1) c = visual.cylinder(pos=(2,2,2),axis=(2,0,0),radius=.1) f = visual.frame() d = visual.cylinder(frame=f,pos=(1,2,1),axis=(2,0,0),radius=.1) e = visual.cylinder(pos=(0,0,0),axis=(2,0,0),radius=.1) e.pos = (3,2,3) class cC(): def __init__(self, pos=(0,0,0), axis=(2,0,0)): self.pos = visual.vector(pos) self.axis = visual.vector(axis) self.f = visual.frame() self.g = visual.cylinder(frame=f,pos=self.pos,axis=self.axis,radius=.1) self.g.pos = visual.vector(0,2,0) def wpos(self,local): x_axis = visual.norm(f.axis) z_axis = visual.norm(visual.cross(f.axis, f.up)) y_axis = visual.norm(visual.cross(z_axis, x_axis)) #return x_axis,y_axis,z_axis return self.f.pos+local[0]*x_axis+local[1]*y_axis+local[2]*z_axis u = cC() ax = 0 cnt = 0. while 1: print u.wpos((1,2,0)) if ax == 0: c.rotate(angle=.15, axis=(0,1,0), origin=(3,2,2)) f.rotate(angle=.15, axis=(0,1,0), origin=(2,2,1)) e.rotate(angle=.15, axis=(0,1,0), origin=(4,2,3)) u.f.rotate(angle=.15, axis=(0,1,0), origin=(1,2,0)) c.color = (1,1,0) elif ax == 1: c.rotate(angle=.15, axis=(0,0,1), origin=(3,2,2)) f.rotate(angle=.15, axis=(0,0,1), origin=(2,2,1)) e.rotate(angle=.15, axis=(0,0,1), origin=(4,2,3)) u.f.rotate(angle=.15, axis=(0,0,1), origin=(1,2,0)) c.color = (1,0,0) elif ax == 2: c.rotate(angle=.15, axis=(1,0,0), origin=(3,2,2)) f.rotate(angle=.15, axis=(1,0,0), origin=(2,2,1)) e.rotate(angle=.15, axis=(1,0,0), origin=(4,2,3)) u.f.rotate(angle=.15, axis=(1,0,0), origin=(1,2,0)) c.color = (0,0,1) cnt +=1 ## print cnt,ax if cnt > 10: cnt = 0 ax += 1 if ax > 2: ax = 0 time.sleep(.1) |