def print_math(): """ Prints some calculated values. """ x = math.cos(math.pi()) print(x) y = math.sin(math.pi()) print('The sine of PI is y', y)
def callback_Voice_point(self, angle): if self.angle != angle: self.angle = angle print(self.angle) self.rot[3] = math.cos(angle / 360 * math.pi()) self.rot[2] = math.sin(angle / 360 * math.pi()) self.move(self.rot, self.pos1, self.callback_listener)
def cArg(z): if (z.re > 0): return math.atan(z.im / z.re) if (z.re < 0 and z.im >= 0): return math.atan(z.im / z.re) + math.pi() if (z.re < 0 and z.im < 0): return math.atan(z.im / z.re) - math.pi() if (z.re == 0 and z.im > 0): return math.pi() * 0.5 if (z.re == 0 and z.im < 0): return -math.pi() * 0.5 return None
def Range(self, entrada): d_2 = (coordenada_central.[0] - entrada.[0]) * relacion_pixel_cm #para convertirlo en cm if d_2 == 0: # en el puro centro h_1 = h if d_2 > 0: # a la derecha h_2 = d_2 * math.pi(angulo_laser) h_1 = h - h_2 if d_2 < 0: # a la izquierda d_2 = -d_2 h_2 = d_2 * math.pi(angulo_laser) h_1 = h + h_2
def input(): if wybor == 1: X = 1.1#float(input("Podaj x= ")) Y = 1.2#float(input("Podaj y= ")) Z = 1.3#float(input("Podaj z= ")) return kart2sfer(X,Y,Z) elif wybor == 2: R = 1.1#float(input("Podaj r= ")) T = 1.2#float(input("Podaj theta= ")) P = 1.3#float(input("Podaj phi= ")) if R >= 0.0 and P >= 0.0 and P < 2*math.pi() and T >= 0.0 and T <= math.pi(): return sfer2kart(R,T,P) else: print("error")
def __init__(self, M1, M2, Z, f=None): #Definitions, units self.GN = 6.67 * (10**-11) # m^3/(kg s^2) self.c = 3 * (10**8) #m/s self.Msol = 2 * (10**30) #kg self.Mpc = 3.086 * (10**22) #m self.M1 = M1 * self.Msol self.M2 = M2 * self.Msol self.Z = Z self.Mr = (((self.M1 * self.M2)**3) / (self.M1 + self.M2))**.2 integrand = lambda x: 2997.9 / .7 / math.sqrt((.3 * (1 + x)**3) + .7) self.Dcom = self.Mpc * integrate.quad(integrand, 0, Z)[0] self.DL = (1 + Z) * self.Dcom self.fi = f / (1 + Z) if f is not None else .01774 / (1 + Z) self.fr = self.fi * (1 + Z) self.Tc = lambda frad: ( (5 * (self.c**5)) / (256 * (self.fr**(8 / 3)) * ( (self.GN * self.Mr)**(5 / 3)) * (math.pi()**(8 / 3)))) - ( (5 * (self.c**5)) / (256 * (frad**(8 / 3)) * ( (self.GN * self.Mr)**(5 / 3)) * (math.pi**(8 / 3)))) self.hc = ((math.sqrt(2 / 3) * (((self.GN * self.Mr * (1 + Z)) / (self.c**3))**(5 / 6))) * (self.fi**(-1 / 6))) / ( (math.pi**(2 / 3)) * self.DL / self.c) self.hcf = lambda f: self.hc * ((f / self.fi)**(-1 / 6))
def calculate_loss(self, flow, density, viscosity): '''calculates the head loss for a given flowrate''' #flow in gpm, diameter in inches output in ft/sec velocity = 60*0.13368*flow/((self.diameter/24)**2*math.pi()) #diameter in inches, velocity in ft/sec, density in lb/ft3, viscosity in cP #validate the unit conversions in this formula! reynolds = (self.diameter*velocity*density/viscosity)/12/6.8948/144
def main(): #First Robot Data x = input( "Distance left robot is from middle (ft) Remember the central component is 3 in thick = " ) #Distance for I calculation m1 = input("Weight left robot is from middle (lbs) = " ) / 32.2 #mass for I calculation #Second robot data y = input( "Distance right robot is from middle (ft) Remember the central component is 3 in thick = " ) #Distance for I calculation m2 = input("Weight right robot is from middle (lbs) = " ) / 32.2 #mass for I calculation angle_desired = 8 * math.pi( ) / 180 #Max angle allowed for determining sensitivity of system and offset from ideal cg = ( 2 * 12 + 2 ) / 12 #CG of the support structure location in ft (converted from 2 ft 2 in to feet with percentages) ms = 93 #Mass of suppport structure in lbsf h = 54.375 / 12 #Distance from central pivot to the rung calcualted from the total 9 ft 3 and 3/8 in hight #and the subtraction of the initial starting height of the rung of 5 ft 3 in converted to feet R1 = math.sqrt(x**2 + h**2) R2 = math.sqrt(y**2 + h**2) return 0
def calculate_loss(self, flow, density, viscosity): '''calculates the head loss for a given flowrate''' #flow in gpm, diameter in inches output in ft/sec velocity = 60 * 0.13368 * flow / ((self.diameter / 24)**2 * math.pi()) #diameter in inches, velocity in ft/sec, density in lb/ft3, viscosity in cP #validate the unit conversions in this formula! reynolds = (self.diameter * velocity * density / viscosity) / 12 / 6.8948 / 144
def GHoop(): d = int(input("请输入所选箍筋的直径:")) global Asv1 Asv1 = (d**2 * math.pi()) / 4 n = int(input("请输入几支箍:")) psv = 0.24 * ft / fyv S = (n * Asv1) / b * psv print("箍筋间距S=%.2f" % S)
def goToPoint(self, coordinates): """Moves the robot in a straight line to a given point. Follows a 2-step system; 1. Orient heading towards point. 2. Move in straight line; Once in close range of point, stop. May be inefficient; no new process, spams server requests for data... Will stop if it starts moving away from point. Returns 0 if point reached (with a tolerance of DISTANCE_THRESHOLD), or 1 if robot was detected moving away from point. :param p1: The point, dictionary containing at least the x and y coordinates under indices 'X' and 'Y' respectively. """ #Part 1: Turn to aim at point self.setSpeed(0, 0) self.updateAttributes() bearing = self.getBearing(coordinates) if (bearing > BEARING_THRESHOLD or bearing < 2 * pi() - BEARING_THRESHOLD): if (bearing > pi()): self.setAngularSpeed(GOTOPOINT_ANG_SPEED) else: self.setAngularSpeed(-GOTOPOINT_ANG_SPEED) while (self.getBearing(coordinates) > BEARING_THRESHOLD or self.getBearing(coordinates) < 2 * pi() - BEARING_THRESHOLD): #While the robot isn't pointing at dest self.updateAttributes() #Is pointing ok, stop turning self.setSpeed(0, 0) #Part 2: Move forward until point is reached if (self.distanceTo(coordinates) > DISTANCE_THRESHOLD): self.setLinearSpeed(GOTOPOINT_LIN_SPEED) while (self.distanceTo(coordinates) > DISTANCE_THRESHOLD and previousDistance >= self.distanceTo(coordinates)): #Wait 100ms here maybe? previousDistance = self.distanceTo(coordinates) self.updateAttributes() if (previousDistance < self.distanceTo(coordinates)): print("Started moving away from point, stopping") result = 1 else: print("Distance threshold reached, stopping") result = 0 else: print("Already close to point") result = 0 #Stop moving self.setSpeed(0, 0) return result
def J1(u,v,wp,Ppv,zv): # Ppv is by definition purely real or imaginary. if abs(Ppv.real) > abs(Ppv.imag): Ppv = Ppv.real return 1/Ppv * (wp.ln_sigma_real(v-u) - wp.ln_sigma_real(u+v) + 2*u*zv.real) else: Ppv = Ppv.imag # NOTE: the -1 factor here is cancelled by the fact that we take the inverse of Ppv (so -1/(i*b) == i/b). return 1/Ppv * (wp.ln_sigma_imag(v-u) - wp.ln_sigma_imag(u+v) + pi() + 2*u*zv.imag)
def s(b): n_points_checked = 60 halv = int(n_points_checked * 0.5) temp = 0.0 for i in range(0, n_points_checked): x = (i - halv) * 0.2481 a = pi(x, b) - line[40 - halv + i][1] temp += a * a return temp
def s(b): n_points_checked = 380 halv = int(n_points_checked * 0.5) temp = 0.0 for i in range(n_points_checked): x = (i - halv) * 0.2481 a = pi(x, b) - line_array[line_len_2 - halv + i][1] temp += a * a return temp
def GaussianNormal(Sigma, x, mu): exponent=-.5*np.transpose(x-mu)*np.linalg.inv(Sigma)*(x-mu) print(exponent) print(np.linalg.det(Sigma)) p=(1/math.sqrt((2*math.pi())**3*np.linalg.det(Sigma)))#*math.exp(exponent) return p
def rbbox_transform(poly, angle): pi = math.pi() rad = angle / 360 * 2 * pi rot_mat = np.array([[np.cos(rad), -np.sin(rad)], [np.sin(rad), np.cos(rad)]]) ctr = np.mean(poly, axis=0) poly_ctr = poly - ctr poly_rot = np.dot(rot_mat, poly_ctr) + ctr return poly_rot
def calcula_velocidade_angular(): if (rospy.get_time() - tempo_inicial >= rate): tempo_final = rospy.get_time() velocidade_angular = 2 * math.pi() * (Pulsos / Pulsos_por_volta) / \ (tempo_final - tempo_inicial) Pulsos = 0 tempo_inicial = rospy.get_time() return velocidade_angular * sentido_rotacao() # conferir isso
def tau_d_calc(tau_be, z_angle): steps = 90 max_z_angle = pi() / 2 dz_angle = max_z_angle / steps z_angle = 0 integral = 0 while z_angle < max_z_angle: integral += tau_be * sin(z_angle) * cos(z_angle) * dz_angle tau_d = 2.0 * integral return tau_d
def do_sum(self): if self.op == "add": self.total += self.current if self.op == "minus": self.total -= self.current if self.op == "times": self.total *= self.current if self.op == "divide": self.total /= self.current if self.op == "raise": self.total = self.total**self.current if self.op == "rootof": self.total = self.total**(1 / self.current) if self.op == "fact": self.total = int(text_box.get()) self.total = math.factorial(self.total) if self.op == "ln": self.total = math.loge(self.current) if self.op == "log": self.total = math.log10(self.current) if self.op == "sine": self.total = math.sin(math.radians(self.current)) if self.op == "cosine": self.total = math.cos(math.radians(self.current)) if self.op == "tangent": self.total = math.tan(math.radians(self.current)) if self.op == "sinh": self.total = math.sinh(math.radians(self.current)) if self.op == "cosh": self.total = math.cosh(math.radians(self.current)) if self.op == "tanh": self.total = math.tanh(math.radians(self.current)) if self.op == "asin": self.total = math.asin(math.radians(self.current)) if self.op == "acos": self.total = math.acos(math.radians(self.current)) if self.op == "atan": self.total = math.atan(math.radians(self.current)) if self.op == "pi": self.total = math.pi(self.current) if self.op == "exp": self.total = math.exp(self.current) if self.op == "inv": self.total = 1 / self.current self.new_num = True self.op_pending = False self.display(self.total)
def __INIT__(self): # Astronomical Constants self.c = 299792458 # Speed of Light - in m/s self.h = 6.62607004081e-34 # Planck Constant - in J.s self.hbar = self.h/(2*math.pi()) # Inverse of h - in J.s self.G = 6.6725985e-11 # Gravitational Constant - in m^3(Kg*s^2) self.k = 1.380626e-23 # Boltzmann Constant - in J k^-1 self.sigma = 5.6705119e-8 # Stephan-Boltzmann Const. - in W/(m^2*K^4) self.Ks = 1.361 # Solar Constant - in W/m^2 self.g = 9.80665 # Gravitational Acceleration - in m/s^2 self.b = 2.897772917e-3 # Wien's Displacement Const. - in m K # Astronomical Units and Physical Constants self.AU = 149600000000 # Astronomical Unit - in meters self.parsec = 3.08567758074e16 # Parsec - in meters self.ly = 9463000000000000 # Light Year - in meters self.solM = 1.9889e30 # Solar Mass - in kilograms self.solRad = 695700000 # Solar Radius - in meters self.solLum = 3.828e26 # Solar Luminosity - in watts self.solTemp = 5780 # Solar Temperature - in kelvins self.solMinCHZ = 0.77 # Sol Inner habitable rad. - in AU self.solMaxCHZ = 1.18 # Sol Outer Habitable rad. - in AU self.solAbsMag = 4.77 # Solar Absolute Magnitude - in magnitudes self.eMass = 5.9722e24 # Earth's Mass - in kilograms self.eAtmoP = 101325 # Earth's Atmos. Pressure - in pascals # Payment Coefficients for Stars self.Scoef = 2880 self.Dcoef = 33737 self.HNcoef = 54309 # Payment Coefficients for Planets self.planets = 720 self.ClassI = 3974 self.ClassII_HMC = 23168 self.MRich = 52292 self.WW_Earth = 155581 self.ammonia = 232619 self.TCRock = 223971 self.TCHMC = 241607 self.TCWW = 279088
def update(state, a, delta): acc_x = read_raw_data(ACCEL_XOUT_H) acc_y = read_raw_data(ACCEL_YOUT_H) Vx = acc_x/16384.0 * dt Vy = acc_y/16384.0 * dt state.v = math.sqrt(Vx**2 + Vy**2) state.x = state.x + state.v * math.cos(state.yaw) * dt state.y = state.y + state.v * math.sin(state.yaw) * dt gyro_z = read_raw_data(GYRO_ZOUT_H) Gz = math.radians(dt*gyro_z/131.0) state.yaw = state.yaw + state.v / L * math.tan(Gz) * dt #torque, axel, wheel circumference target_v = state.v + a * dt #forward #delta delta_dependence = delta / math.pi() motor1.forward(max(min(target_v-delta_dependence),1),0) motor2.forward(max(min(target_v+delta_dependence),1),0) return state
def DoRond(self, fss, value): sys.stdout.write("\033[0m") self.message_JoyControl = False self.message_AutonomousMode = False self.message_Carre = False self.message_Triangle = False self.message_Croix = False if (not (self.message_Rond) and self.message): print 'Mode Rond' self.message_Rond = True #Calcul commande trajectoire perimetre_cercle = self.r_rotation * 2 * math.pi() vL = self.vmax deltaV = (vL * (self.r_rotation + (self.entraxe / 2.0)) / self.r_rotation) - vL k = self.vmax / (deltaV + vL) vL = k * vL wA = k * deltaV / (self.entraxe / 2) temps_th = perimetre_cercle / vL print "temps:", temps_th, "\t \t vL:", vL, "\t \t wA:", wA self.twist.linear.x = vL self.twist.linear.y = 0 self.twist.linear.z = 0 self.twist.angular.x = 0 self.twist.angular.y = 0 self.twist.angular.z = wA self.pub.publish(self.twist_real) sys.stdout.write("\033[37m") pass
def area(self): return pi() * (self.raio**2)
n_points_checked = 400 halv = int(n_points_checked * 0.5) temp = 0.0 for i in range(n_points_checked): x = (i - halv) * 0.2481 a = pi(x, b) - line_array[512 - halv + i][1] temp += a * a return temp # [sigma_1, x_sh, bkg, B ] x0 = array([0.73, 0.0, 1000.0, 14000.00]) # initial values for minimize print(x0) res = minimize(s, x0, method='nelder-mead', options={ 'xtol': 1e-2, 'disp': True, 'maxfev': 1e5, 'maxiter': 1e5 }) print(res.x) print(res.fun * 1e-6) # print out the whole line for i in range(1024): x = (i - 512) * 0.2481 # x in milimiters print(x, ", ", line_array[i][1], ", ", pi(x, res.x))
def deg2rad(deg): return deg * math.pi() / 180.0
def rad2deg(rad): return rad * 180.0 / math.pi()
halv = int(n_points_checked * 0.5) temp = 0.0 for i in range(n_points_checked): x = (i - halv) * 0.2481 a = pi(x, b) - line_array[line_len_2 - halv + i][1] temp += a * a return temp # [sigma_1, sigma_2, w_1, x_sh, bkg, B, b ] x0 = array([3.93, 1.26, 0.05, -5.03, 3047.0, 29031.0, 5.40]) # initial values for minimize print(x0) res = minimize(s, x0, method='nelder-mead', options={ 'xtol': 1e-2, 'disp': True, 'maxfev': 1e5, 'maxiter': 1e5 }) print(res.x) print(res.fun * 1e-6) # print out the whole line for i in range(380): x = (i - 190) * 0.2481 # x in milimiters print(x, ", ", line_array[line_len_2 - 190 + i][1], ", ", pi(x, res.x))
def pc2m(l): return au2m(l * 648000 / pi())
def pi(): import math print(valor.set('%g' % math.pi(float(b.get()))))
def Circumference(self): return 2*math.pi()*self._radius
def Area(self): return math.pi()*(self._radius**2)
def muNought(): return (4*math.pi())/10000000
import math math.pi()
def inverseDCTII(x): X = np.zeros(B) for k in range(B): X[k]= reduce(add, [math.cos(math.pi(n+0.5)*k/B) for n in range(N)])*math.sqrt(2/B) return X
def Diameter(A_m2): _ret = None # _ret = math.sqrt(A_m2 * 4 / math.pi()) # return _ret
def perimetro(self): return 2 * pi() * self.raio
# -*- coding: utf-8 -*- """ Created on Mon Feb 25 15:01:54 2019 @author: akshaf """ # Inbuilt Functions print type id int float str # math has properties which we can use for mathematical operations import math # to get the math funtions, use import math. dir(math) # This shows which all functions are supported by math function math.sqrt() math.pi() math.sin() math.log() # default is the base value of e math.log10() #we can use base 10 in this way math.cos() math.factorial() math.pow(2, 3)
def wavePropagation(sigma, epsilon, frequency): if(frequency > (sigma/(2*math.pi()*epsilon))): return True return False
"""function - DAY3""" import math math.ceil() # up math.floor() # down math.factorial() math.sin() math.cos() math.tan() math.radians() # Degrees to radians math.degrees() # Radians to degrees math.pi() #3.141592653589793 math.sqrt() import math def main(): """function"""
def calculaArea(self): return pow(self._raio,2)*pi()
import math print dir(math) print math.pi(1)
num=int(str_num.replace(",","")) import matplotlib.pyplot as plt str_speeds="38 42 20 40 39" str_armor="80 50 17 50 51" speeds=str_speeds.split(" ") armors=str_armor.split(" ") markers=["o","v","^","<",">"] for idx in range(len(speeds)): x=int(speeds[idx]) y=int(armors[idx]) plt.scatter(x,y,marker=markers[idx]) plt.show() speeds=str_speeds.split() csep_speeds=",".join(speeds) from math import pi pi() def func(): words="""ABC, DEF""" print(words) func()