def transform(matrix, vector): # convert 3D vector to 4D homogeneous vector vector4 = visual.array(vector.astuple() + (1,)) # perform the actual matrix transform transformed4 = matrix.dot(vector4) # convert the 4D homogeneous vector back to 3D return visual.vector(transformed4[:-1] / transformed4[-1])
def transform(matrix, vector): # convert 3D vector to 4D homogeneous vector vector4 = visual.array(vector.astuple() + (1, )) # perform the actual matrix transform transformed4 = matrix.dot(vector4) # convert the 4D homogeneous vector back to 3D return visual.vector(transformed4[:-1] / transformed4[-1])
def createTransformMatrix(self, focalDistance): f = focalDistance return visual.array([ [f, 0, 0, 0], [0, f, 0, 0], [0, 0, f, 0], [0, 0, 1, 0] ])
def createTransformMatrix(self, focalDistance): f = focalDistance return visual.array([[f, 0, 0, 0], [0, f, 0, 0], [0, 0, f, 0], [0, 0, 1, 0]])
SRADIUS = R/3. VRANGE = 0.2*L* vp.sqrt(K/M) DT = 0.02*(2.*PI* vp.sqrt(M/K)) ATOM = crystal(index=INDEX, delta=L, radius=R, sradius=SRADIUS) vp.scene.autoscale = False PTOTAL = vp.vector() for a in ATOM: px = M*(-VRANGE/2+VRANGE*random()) py = M*(-VRANGE/2+VRANGE*random()) pz = M*(-VRANGE/2+VRANGE*random()) a.p = vp.vector(px, py, pz) PTOTAL = PTOTAL+a.p for a in ATOM: a.p = vp.array(a.p-PTOTAL/(INDEX**2)) # Convert to tuples for faster indexing access. We aren't growing any more of them. SPRINGS = tuple(SPRINGS) ATOM = tuple(ATOM) # Evaluate a couple of constants outside the loop K_DT = K * DT DT_M = DT / M while True: vp.rate(100) for a in ATOM: r = vp.array(a.nearpos) - a.pos rmag = (vp.sqrt(vp.sum(vp.square(r), -1))).reshape(-1, 1) # reshape rmag from row to column a.p += K_DT * vp.sum((1-L/rmag)*r, 0) # sum the forces k*dt*(rmag-L)*(r/rmag)
(0, -10, 2), (0, -10, 6), (0, 10, 6)]) S_THETA = vp.sphere(pos=(0, -12, -10), radius=0.6, color=(0.6, 1.0, 0.6)) S_THETA_LABEL = vp.label(pos=S_THETA.pos, text="Fix Angle", yoffset=-5, opacity=0, box=0, line=0) S_LENGTH = vp.sphere(pos=(0, -12, 10), radius=0.6, color=(0.6, 0.6, 1.0)) S_LENGTH_LABEL = vp.label(pos=S_LENGTH.pos, text="Fix Length", yoffset=-5, opacity=0, box=0, line=0) S_TEXT = vp.label(pos=(0, 12, 0), text="Yellow = Red x Green", opacity=0, box=0, line=0) FIXLENGTH = 0 FIXTHETA = 0 AVECTOR = vp.array([0, 0, -3.5]) BVECTOR = vp.vector(0, 3, 2) A = vp.arrow(pos=(0, 0, 0), shaftwidth=R, color=vp.color.red) B = vp.arrow(pos=(0, 0, 0), axis=BVECTOR, shaftwidth=R, color=vp.color.green) A.axis = AVECTOR CVECTOR = vp.cross(AVECTOR, BVECTOR) C = vp.arrow(pos=(0, 0, 0), axis=CVECTOR, shaftwidth=R, color=vp.color.yellow) vp.scene.autoscale = 0 vp.scene.forward = (-1, -.5, -1) DRAG = 0 while True: vp.rate(100)