def arctan(): os.system('cls') global pi global e global cont print("This calculator operates in radian mode!") time.sleep(1) while cont not in ["n","N"]: while True: try: os.system('cls') print("Please enter the tangent you wish to compute the angle of.") time.sleep(1) ang_1 = float(input("Enter tan>>")) total = math.arctan(ang_1) print(total) time.sleep(1) break except: print("Error: Invalid Input") time.sleep(1) os.system('cls') while True: cont = input("Do you wish to continue:Y or N?>>") if cont in ["y","Y"]: break elif cont in ["n", "N"]: break else: print("Error: Invalid Input") time.sleep(1) os.system('cls') os.system('cls')
def _render_linearring(self, f, data, pxlsz, ss): c = self._slatectx c.set_operator(cr.OPERATOR_OVER) ss.style_stroke(c, data, pxlsz) c.move_to(*self.imgcoords(*f.coords[0])) for x, y in f.coords[1:]: c.line_to(self.imgcoords(x,y)) c.close_path() c.stroke() label = ss.get_label(data) if label and len(label) > 0 and ss.style_label(c, data, pxlsz): xoff, yoff = ss.get_labeloffsets(data, pxlsz) c.save() c.move_to(0,0) anchor = self.imgcoords(f.interpolate(xoff, normalized=True)) xbear, ybear, width, height, _0, _1 = cr.text_extents(label) width = width * pxlsz[0] adv = self.imgcoords(*f.interpolate(f.length*xoff + width)) angle = math.arctan((adv[1] - anchor[1]) / (adv[0] - anchor[0])) c.translate(-yoff*height) c.rotate(angle) c.translate(*anchor) if ss.style_labelhalo(c, data, pxlsz): c.text_path(label) c.stroke() c.text_path(label) if ss.style_labelfill(c, data, pxlsz): c.fill_preserve() if ss.style_labelstroke(c, data, pxlsz): c.stroke() c.restore()
def getAngleStr(ValC, *offset): # grab optional argument try: offset = offset[0] except: offset = 0.0 # initalize angle array angle = arctan(ValC.imag, ValC.real) - offset #print("Angle = {0}".format(angle)) if angle < -pi: angle = angle + pi elif angle > pi: angle = angle - pi tempList = [abs(angle - j * pi / 6) for j in range(-6, 7)] idx = tempList.index(min(tempList)) if idx == 0: # phi ~ -pi return " +" + Dark + "e^(-6/6pi) " + noColor return " - " elif idx == 1: # phi ~ (-5/6)pi return " +" + Dark + "e^(-5/6pi) " + noColor return " -" + Dark + "e^(pi/6) " + noColor elif idx == 2: # phi ~ (-4/6)pi return " +" + Dark + "e^(-4/6pi) " + noColor return " -" + Dark + "e^(pi/3) " + noColor elif idx == 3: # phi ~ (-3/6)pi return " +" + Dark + "e^(-3/6pi) " + noColor return " -" + Dark + "i " + noColor elif idx == 4: # phi ~ (-2/6)pi return " +" + Dark + "e^(-2/6pi) " + noColor return " -" + Dark + "e^(2pi/3) " + noColor elif idx == 5: # phi ~ (-1/6)pi return " +" + Dark + "e^(-1/6pi) " + noColor return " -" + Dark + "e^(5pi/6) " + noColor elif idx == 6: # phi ~ 0 return " +" + Dark + "e^(00/6pi) " + noColor return " + " elif idx == 7: # phi ~ (+1/6)pi return " +" + Dark + "e^(+1/6pi) " + noColor return " +" + Dark + "e^(pi/6) " + noColor elif idx == 8: # phi ~ (+2/6)pi return " +" + Dark + "e^(+2/6pi) " + noColor return " +" + Dark + "e^(pi/3) " + noColor elif idx == 9: # phi ~ (+3/6)pi return " +" + Dark + "e^(+3/6pi) " + noColor return " +" + Dark + "i " + noColor elif idx == 10: # phi ~ (+4/6)pi return " +" + Dark + "e^(+4/6pi) " + noColor return " +" + Dark + "e^(2pi/3) " + noColor elif idx == 11: # phi ~ (+5/6)pi return " +" + Dark + "e^(+5/6pi) " + noColor return " +" + Dark + "e^(5pi/6) " + noColor elif idx == 12: # phi ~ (+6/6)pi return " +" + Dark + "e^(+6/6pi) " + noColor return " - "
def mate_search(self, blob): if blob.target_mate == 0: # tries to find love within a cetain radius timer = 0 best_distance = blob.sight bride = "__N/A__" for partner in population: if partner is blob: pass elif partner.ai_stance == "__mate_search__": dx = partner.x - blob.x dy = partner.y - blob.y distance = ((dx**2) + (dy**2))**0.5 if distance < best_distance: best_distance = distance bride = timer timer += 1 #----- if bride != "__N/A__": partner = population[bride] blob.target_mate = partner dx = partner.x - blob.x dy = partner.y - blob.y alpha = arctan(dy / dx) if dx < 0: alpha += pi blob.angle = pi / 2 - alpha else: self.friend_search(blob) elif Collision.check_sex(blob, blob.target_mate) == "__true__": #child making blob.reproduce(blob.target_mate) self.move(blob)
def get_spot_properties(moments): """ returns properties of the spot from moments dictionary provided by cv2 opencv-python library Input keys in the dictionary: 'm00', 'm10', 'm01', 'm20', 'm11', 'm02', 'm30', 'm21', 'm12', 'm03', 'mu20', 'mu11', 'mu02', 'mu30', 'mu21', 'mu12', 'mu03 ', 'nu20', 'nu11', 'nu02', 'nu30', 'nu21', 'nu12', 'nu03' mu - central moments m - raw moments nu - scale inveriant Hu moments 1) M. K. Hu, "Visual Pattern Recognition by Moment Invariants", IRE Trans. Info. Theory, vol. IT-8, pp.179–187, 1962 2) http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=cvmatchshapes#humoments Hu Moments' OpenCV method Parameters ---------- m :: (dictionary) dictionary from moments Returns ------- eccentricity :: (float) Examples -------- >>> spot_properties = get_spot_properties(m) """ from numpy import arctan m = moments moments['mu00'] = moments['m00'] #calculate new modified central moments m["mu'20"] = moments['mu20']/moments['mu00'] m["mu'02"] = moments['mu02']/moments['mu00'] m["mu'11"]= moments['mu11']/moments['mu00'] lambda_large = 0.5*(m["mu'20"] + m["mu'02"] + (4*m["mu'11"]**2 + (m["mu'20"]-m["mu'02"])**2)**0.5) lambda_small = 0.5*(m["mu'20"] + m["mu'02"] - (4*m["mu'11"]**2 + (m["mu'20"]-m["mu'02"])**2)**0.5) #calculate eccentricity eccentricity = (1-(lambda_large/lambda_small))**0.5 #calculate theta angle theta = 0.5*arctan(2*m["mu'11"]/(m["mu'20"]-m["mu'02"])) result = {} result['eccentricity'] = eccentricity result['theta'] = theta result['axis_large'] = lambda_large result['axis_small'] = lambda_small return result
def precession_rate(self): self.x_critical = 0 self.y_critical = 0 self.t_critical = 0 for i in range(len(self.x) - 2): self.r_i = math.sqrt(self.x[i]**2 + self.y[i]**2) self.r_i1 = math.sqrt(self.x[i + 1]**2 + self.y[i + 1]**2) self.r_i2 = math.sqrt(self.x[i + 2]**2 + self.y[i + 2]**2) if self.r_i < self.r_i1 and self.r_i1 > self.r_i2: self.x_critical = self.x[i + 1] self.y_critical = self.y[i + 1] self.t_critical = self.dt * (i + 1) break self.rate = math.arctan( self.y_critical / self.x_critical) / self.t_critical return self.rate
def scan_callback(self, data): '''Checks LIDAR data''' inf = 6 sum_x = 0 sum_y = 0 self.data = data.ranges for i in range(500): if (self.data[i] >= 6 or self.data[i] == inf): self.data[i] = 6 elif (self.data[i] == 0.0): continue sum_x += math.cos(float(i) / 500 * 2 * pi) * self.data[i] sum_y += math.sin(float(i) / 500 * w * pi) * self.data[i] self.cmd.drive_angle = k * math.arctan(sum_y / sum_x) self.drive_callback()
def xy_SPM_to_Real(P, ind, Gx, Gy): res = [] for i in range(len(P)): if ind == 1: res.append(P[i].real) elif ind == 2: res.append(P[i].imag) elif ind == 3: res.append(math.sqrt(P[i].real * P[i].real + P[i].imag * P[i].imag)) elif ind == 4: res.append(math.arctan(math.abs((P[i].imag + 0.0) / P[i].real))) elif ind == 5: res.append((P[i].real * P[i].real + P[i].imag * P[i].imag) / (Gx[i] * Gy[i])) elif ind == 6: res.append(math.sqrt(P[i].real * P[i].real + P[i].imag * P[i].imag) / Gx[i]) return res
def p4EfficiencyForPeakingOrbits(tiltAngle, eclipticLatitude, inclination): b0 = eclipticLatitude i = inclination theta = tiltAngle fh = p4ChipHeightAndWidth[0] * degree fw = p4ChipHeightAndWidth[1] * degree h = fh*math.cos(theta) + fw*math.sin(theta) if ((b0 < h/2) & (i > b0 + h/2) & (i > abs(b0 - h/2))): lowEnd = abs(b0 - h/2) elif b0 > h/2: lowEnd = abs(b0 - h/2) else: lowEnd = 0 if b0 <= h/2: return 0.5 else: return 0.5 - 1 / math.pi * math.arctan(1/math.sin(i) * math.sin(lowEnd) / math.sqrt(1 - (1/math.sin(i) * math.sin(lowEnd))**2))
def hungry(self, blob): if blob.target_plant == 0: # tries to find food within a cetain radius timer = 0 best_distance = blob.sight food = "__N/A__" for plant in plant_pop: dx = plant.x - blob.x dy = plant.y - blob.y distance = ((dx**2) + (dy**2))**0.5 if distance < best_distance: best_distance = distance food = timer timer += 1 if food != "__N/A__": plant = plant_pop[food] blob.target_plant = plant dx = plant.x - blob.x dy = plant.y - blob.y alpha = arctan(dy / dx) if dx < 0: alpha += pi blob.angle = pi / 2 - alpha else: self.friend_search(blob) self.move(blob)
def _render_linestring(self, f, data, pxlsz, ss): c = self._slatectx c.set_operator(cr.OPERATOR_OVER) where = self.imgcoords(*f.coords[0]) ss.style_stroke(c, data, pxlsz) ss.style.strokecap(c, data, pxlsz) c.move_to(*where) for x, y in f.coords[1:]: c.line_to(self.imgcoords(x, y)) c.stroke() label = ss.get_label(data) if label and len(label) > 0 and ss.style_label(c, data, pxlsz): xoff, yoff = ss.get_labeloffsets(data, pxlsz) c.save() c.move_to(0, 0) anchor = self.imgcoords(f.interpolate(xoff, normalized=True)) xbear, ybear, width, height, _0, _1 = cr.text_extents(label) width = width * pxlsz[0] adv = self.imgcoords(*f.interpolate(f.length * xoff + width)) angle = math.arctan((adv[1] - anchor[1]) / (adv[0] - anchor[0])) c.translate(-yoff * height) c.rotate(angle) c.translate(*anchor) if ss.style_labelhalo(c, data, pxlsz): c.text_path(label) c.stroke() c.text_path(label) if ss.style_labelfill(c, data, pxlsz): c.fill_preserve() if ss.style_labelstroke(c, data, pxlsz): c.stroke() c.restore()
player.jumping = True elif event.type == KEYUP: if event.key == K_w: moving_forward = False elif event.key == K_a: moving_left = False elif event.key == K_s: moving_back = False elif event.key == K_d: moving_right = False if pygame.mouse.get_pos() == old_mouse_pos: fix_alpha, fix_beta = player.alpha, player.beta pygame.mouse.set_pos(w, h) else: mx, my = pygame.mouse.get_pos() a, b = arctan(w - mx, player.fov), arctan(h - my, sqrt((w - mx)**2 + player.fov**2)) player.alpha, player.beta = fix_alpha + a * player.sensitivity, fix_beta + b * player.sensitivity old_mouse_pos = pygame.mouse.get_pos() if player.beta < -pi / 2 + bb: player.beta = -pi / 2 + bb elif player.beta > pi / 2 - bb: player.beta = pi / 2 - bb player.control_below() if player.jumping: player.jump() if player.free_falling: player.free_fall()
def get_slope(x1, y1, x2, y2): #두 점의 좌표를 가지고 기울기를 구하는 함수 (이번 코드에는 사용하지 않았음 ㅎㅎ;) if x1 != x2: #분모가 0이되는 상황 방지 radian = math.arctan((y2 - y1) / (x2 - x1)) return radian
def __pow__(self, other): """ マクローリン展開すると Do McLaughlin expansion exp(e x) = 1 + e x 以降の式変形の準備 and ready for following transration; Z = z + e z' = exp(log(Z)) log(Z) = log(|Z| exp(e arg(Z))) = log|Z| + e arg(Z) arg(Z) = arctan(z' / z) 以下を仮定 supposed; X = x + e x' Y = y + e y' X ** Y = exp(log(X)) ** Y = exp(Y log(X)) = exp((y + e y')(log|X| + e arg(X))) = exp(y log|X| + e (y' log|X| + y arg(X))) = (|X| ** y)(1 + e (y' log|X| + y arg(X))) = a + e a b a = |X| ** y b = y' log|X| + y arg(X) if x' = 0 and y' = 0 then a = |X| ** y = |x| ** y => x ** y arg(X) = 0 b = 0 X ** Y = a else: 上記の通りa, b, arg(X)それぞれを計算する。 As mentioned above after calculating each buf value; a, b, arg(X). """ if is_dual(other): # otherがDual型の場合 # if the type of 'other' is 'Dual', if self.ndim == 0 and other.ndim == 0: # 点同士の演算はここで行う # Do point-to-point calculations here. # ndarrayじゃなければNumpyよりもmathの方が早い # If it is not ndarray, 'math' is faster than 'Numpy'. if other.im: if self.im: alpha = abs(self)**other.re argX = math.atan(self.im / self.re) beta = (other.im * math.log(abs(self)) + other.re * argX) else: alpha = self.re**other.re beta = other.im * math.log(abs(self.re)) return Dual(alpha, alpha * beta) else: if self.im: alpha = abs(self)**other.re argX = math.arctan(self.im / self.re) beta = other.re * argX return Dual(alpha, alpha * beta) else: # other.imもself.imも0の場合は # 数値に変換して計算させる。 # If 'other.im' and 'self.im' is 0, # calculate it by converting it # to a numerical value. other = other.re else: # それ以外の場合は定義通り計算する。 # Otherwise compute as defined. absX = abs(self) alpha = absX**other.re argX = np.arctan(self.im / self.re) beta = other.im * np.log(absX) + other.re * argX return Dual(alpha, alpha * beta) # otherがDual型ではない場合は普通に計算して返す。 # If the type of 'other' isn't 'Dual', return Numpy calculations. return Dual(np.power(self.re, other), other * np.power(self.re, other - 1) * self.im)
def angles_to_mouse(mx, my, fovd, w, h): """Returns appropriate rotation according to mouse position.""" u, v = w - mx, h - my alpha = arctan(u, fovd) beta = arctan(v, sqrt(u**2 + fovd**2)) return alpha, beta
def getPolar(self): return (self.norme(self.getCarthesian()), m.arctan(self.getCarthesian()[1] / self.getCarthesian()[0]))
def reflect_about(p1,p2): ''' Input: 2 points that define a line to reflect about. Output: Corresponding 3x3 reflect about matrix. ''' return translate(-p1,-p2)*rotate(math.atan2(p2/p1))*reflect_x*rotate(-math.arctan(p2/p1))*translate(p1,p2)
def ecef2geodetic(x, y, z, ell=None, deg=True): """ convert ECEF (meters) to geodetic coordinates Parameters ---------- x : float target x ECEF coordinate (meters) y : float target y ECEF coordinate (meters) z : float target z ECEF coordinate (meters) ell : Ellipsoid, optional reference ellipsoid deg : bool, optional degrees input/output (False: radians in/out) Returns ------- lat : float target geodetic latitude lon : float target geodetic longitude h : float target altitude above geodetic ellipsoid (meters) based on: You, Rey-Jer. (2000). Transformation of Cartesian to Geodetic Coordinates without Iterations. Journal of Surveying Engineering. doi: 10.1061/(ASCE)0733-9453 """ if ell is None: ell = Ellipsoid() r = sqrt(x**2 + y**2 + z**2) E = sqrt(ell.semimajor_axis**2 - ell.semiminor_axis**2) # eqn. 4a u = sqrt(0.5 * (r**2 - E**2) + 0.5 * sqrt((r**2 - E**2)**2 + 4 * E**2 * z**2)) Q = hypot(x, y) huE = hypot(u, E) # eqn. 4b Beta = arctan(huE / u * z / hypot(x, y)) # eqn. 13 eps = ((ell.semiminor_axis * u - ell.semimajor_axis * huE + E**2) * sin(Beta)) / (ell.semimajor_axis * huE * 1 / cos(Beta) - E**2 * cos(Beta)) Beta += eps # %% final output lat = arctan(ell.semimajor_axis / ell.semiminor_axis * tan(Beta)) lon = arctan2(y, x) # eqn. 7 alt = hypot(z - ell.semiminor_axis * sin(Beta), Q - ell.semimajor_axis * cos(Beta)) # inside ellipsoid? inside = x**2 / ell.semimajor_axis**2 + y**2 / ell.semimajor_axis**2 + z**2 / ell.semiminor_axis**2 < 1 if inside: alt = -alt if deg: lat = degrees(lat) lon = degrees(lon) return lat, lon, alt
def getTerminatorLat(long, decl): return math.arctan(-math.cos(long) / math.tan(decl))
def arctan_val(r): if r >= -1 and r <= 1: p = m.arctan(r) return p else: print('error')
def Direction(self): return math.arctan( abs(self[0].y - self[1].y) / abs(self[0].x - self[1].x))
def polar(self): self.rho = self.modulus() self.theta = math.arctan(self.i / self.r) return (self.rho, self.theta)
def relative_sa(alpha, beta, x, y, z): x, y, z = rotate_z(-alpha, x, y, z) x, y, z = rotate_y(beta, x, y, z) axy = arctan(y, x) az = arctan(z, sqrt(x**2 + y**2)) return axy, az
P06 = [[-b],[l2+a],[-h],[1]] ''' creating equation of motion for platofrm center of grav ''' ## f(t) is a function of time! X = 0 #g(x) the vertial acis of CoG may be a func of time and x Y = 0 #height of cog, can be fixed or variable with x and y Z = h #make sure its deriv. of Y! theta0 = math.arctan(Y) #distance covered by center of gravity d = math.sqrt(x**2+y**2) #overall angle of rotation around z axis of reference beta = math.arctan(y/x) #angle of rotation around x0 axis of platform alpha = 0 ''' motion of legs '''
def calcTheta(self): self.theta = math.arctan(self.velocity_y, self.velocity_x)
def arctan(self): return self._gennode('arctan(' + self._name + ')', (lambda x: math.arctan(self.value())), [self], self._trace)