def cos(v): from math import cos as mcos if isinstance(v, int) or isinstance(v, float): return mcos(v) elif isinstance(v, Vector): return Vector(array=[mcos(x) for x in v.list]) else: raise Exception("Must provide either an int, a float, or a vector.")
def rungeKutta(x_cur, u_next, u_cur): h = 0.25 xj = [0, 0, 0, 0] up = (u_next + u_cur) * 0.5 k11 = x_cur[1] k12 = u_cur - x_cur[1] k12 = 10 * k12 k13 = x_cur[3] k14 = 0.0004 * (-4905 * msin(x_cur[2]) - 500 * x_cur[3] + 5000 * (u_cur - x_cur[1]) * mcos(x_cur[2])) x2p = x_cur[1] + k12 * h * 0.5 x3p = x_cur[2] + k13 * h * 0.5 x4p = x_cur[3] + k14 * h * 0.5 k21 = x2p k22 = up - x2p k22 = 10 * k22 k23 = x4p k24 = 0.0004 * (-4905 * msin(x3p) - 500 * x4p + 5000 * (up - x2p) * mcos(x3p)) x2q = x_cur[1] + k22 * h * 0.5 x3q = x_cur[2] + k23 * h * 0.5 x4q = x_cur[3] + k24 * h * 0.5 k31 = x2q k32 = up - x2q k32 = 10 * k32 k33 = x4q k34 = 0.0004 * (-4905 * msin(x3q) - 500 * x4q + 5000 * (up - x2q) * mcos(x3q)) x2e = x_cur[1] + k32 * h x3e = x_cur[2] + k33 * h x4e = x_cur[3] + k34 * h k41 = x2e k42 = u_next - x2e k42 = 10 * k42 k43 = x4e k44 = 0.0004 * (-4905 * msin(x3e) - 500 * x4e + 5000 * (u_next - x2e) * mcos(x3e)) xj[0] = x_cur[0] + h * (k11 + 2.0 * k21 + 2.0 * k31 + k41) / 6.0 xj[1] = x_cur[1] + h * (k12 + 2.0 * k22 + 2.0 * k32 + k42) / 6.0 xj[2] = x_cur[2] + h * (k13 + 2.0 * k23 + 2.0 * k33 + k43) / 6.0 xj[3] = x_cur[3] + h * (k14 + 2.0 * k24 + 2.0 * k34 + k44) / 6.0 return xj
def nebula(output, iterations=100, # (1, 500, 1) exposure=1.0, # (0, 5, 0.01) damping=0.8, # (0, 1.2, 0.01) noisy=1.0, # (0, 10, 0.01) fuzz=1.0, # (0, 10, 0.01) intensity=1.0, # (0, 5, 0.01) initial_vx=10, # (0, 100, 0.01) initial_vy=10, # (0, 100, 0.01) spawn=10, # (1, 100, 1) step_sample_rate=10 # Sample rate for each particle render. ): for radius, colour in [(50, (1.0, 0.1, 0.1)), (100, (1.0, 0.5, 0.1)), (150, (0.3, 1, 0.3)), (200, (0.25, 1, 0.75)), (250, (0.2, 0.2, 1)), (300, (0.75, 0.25, 1)) ]: LOG.info('# Generating: %s radius:%i colour:%s', 'circle', radius, colour) output.write('SIMULATE {} {} {} {} {}\n'.format(iterations, step_sample_rate, damping, noisy, fuzz)) output.write('COLOUR {} {} {}\n'.format(*tuple(c * intensity for c in colour))) for angle in frange(0, tau, 0.5 / radius): for _ in range(spawn): x, y = 500 + radius * mcos(angle), 500 + radius * msin(angle) output.write('PARTICLE {} {} {} {}\n'.format(x, y, fuzzy(initial_vx), fuzzy(initial_vy))) output.write('END\n') output.write('TONEMAP {}\n'.format(exposure))
def py_loop3_2Dsincos(x, y): # reverse the order of traversal u = zeros((len(x),len(y)), Float) from math import sin as msin, cos as mcos # x[i], y[j]: coordinates of grid point (i,j) for j in xrange(len(y)): for i in xrange(len(x)): u[i,j] = msin(x[i])*mcos(y[j]) return u
def py_loop2_2Dsincos(x, y): # inlined expressions u = zeros((len(x),len(y)), Float) from math import sin as msin, cos as mcos # x[i], y[j]: coordinates of grid point (i,j) for i in xrange(len(x)): for j in xrange(len(y)): u[i,j] = msin(x[i])*mcos(y[j]) return u
def onclick(self, event): """ Actions taken if a mouse button is clicked. In this case the following are done: (1) Store and print (x, y) value of cursor (2) If the image has wcs info (i.e., if wcsinfo is not None) then store and print the (RA, dec) value associated with the (x, y) """ self.xclick = event.xdata self.yclick = event.ydata print('') print('Mouse click x, y: %7.1f %7.1f' % (self.xclick, self.yclick)) """ Also show the (RA, dec) of the clicked position if the input file has a WCS solution NOTE: This needs to be handled differently if the displayed image has axes in pixels or in arcsec offsets """ if self.wcsinfo is not None: if self.mode == 'xy': pix = np.zeros((1, self.wcsinfo.naxis)) pix[0, 0] = self.xclick pix[0, 1] = self.yclick radec = self.wcsinfo.wcs_pix2world(pix, 0) self.raclick = radec[0, 0] self.decclick = radec[0, 1] else: """ For now use small-angle formula """ radec = self.radec cosdec = mcos(radec.dec.radian) self.raclick = radec.ra.degree + \ (self.xclick + self.zeropos[0]) / (3600. * cosdec) self.decclick = radec.dec.degree + self.yclick/3600. + \ self.zeropos[1] print('Mouse click ra, dec: %11.7f %+11.7f' % (self.raclick, self.decclick)) return
File "E:\workspace\blender\bl.py", line 1, in <module> bpy.data.objects['Armature'].pose.bones['Bone'].bone.select=True NameError: name 'bpy' is not defined >>> angles(0.02505994588136673, -0.2973966598510742, 1.097610592842102) Traceback (most recent call last): File "<pyshell#25>", line 1, in <module> angles(0.02505994588136673, -0.2973966598510742, 1.097610592842102) NameError: name 'angles' is not defined >>> ==================== RESTART: E:\workspace\blender\bl.py ==================== >>> angles(0.02505994588136673, -0.2973966598510742, 1.097610592842102) Traceback (most recent call last): File "<pyshell#26>", line 1, in <module> angles(0.02505994588136673, -0.2973966598510742, 1.097610592842102) File "E:\workspace\blender\bl.py", line 9, in angles x_ang=np.degrees(m.mcos(x/(np.sqrt(x*x+y*y+z*z)))) AttributeError: module 'math' has no attribute 'mcos' >>> ==================== RESTART: E:\workspace\blender\bl.py ==================== >>> angles(0.02505994588136673, -0.2973966598510742, 1.097610592842102) (0.02505994588136673, -0.2973966598510742, 1.097610592842102) >>> ==================== RESTART: E:\workspace\blender\bl.py ==================== >>> angles(0.02505994588136673, -0.2973966598510742, 1.097610592842102) (88.73758928928957, 105.15648229230935, 15.211492466311858) >>> angles(0.02505994588136673, -0.2973966598510742, 1.097610592842102) (88.73758928928957, 105.15648229230935, 15.211492466311858) >>> angles(0.02505994588136673, -0.2973966598510742, 1.097610592842102) (88.73758928928957, 105.15648229230935, 15.211492466311858) >>> angles(0.08089639246463776, 0.5640865564346313, 0.9844207763671875) (85.92168004574144, 60.26980375446668, 30.06552890564543)
def cos(a): return mcos(a)
def I(x, y): return msin(x)*mcos(y)