Python math.atan() Examples
The following are 30
code examples of math.atan().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
math
, or try the search function
.
Example #1
Source File: geometry.py From Localization with MIT License | 6 votes |
def c2s(self): R = self.dist(point(0, 0, 0)) lg = math.atan(self.y / self.x) lat = acos(self.z / R) return (lg, lat, R) # ~ def transform(self,p1,p2): # ~ if isinstance(p2,point): # ~ v=vec(p1,p2) # ~ rot=v.angle() # ~ return self.transform(p1,rot) # ~ else: # ~ temp=self-p1 # ~ rot=p2 # ~ px=math.cos(rot)*temp.x+math.sin(rot)*temp.y # ~ py=-math.sin(rot)*temp.x+math.cos(rot)*temp.y # ~ return point(px,py)
Example #2
Source File: angles.py From orbit-predictor with MIT License | 6 votes |
def ta_to_E(ta, ecc): """Eccentric anomaly from true anomaly. Parameters ---------- ta : float True anomaly (rad). ecc : float Eccentricity. Returns ------- E : float Eccentric anomaly. """ E = 2 * atan(sqrt((1 - ecc) / (1 + ecc)) * tan(ta / 2)) return E
Example #3
Source File: coordinate_systems.py From orbit-predictor with MIT License | 6 votes |
def ecef_to_llh(ecef_km): # WGS-84 ellipsoid parameters */ a = 6378.1370 b = 6356.752314 p = sqrt(ecef_km[0] ** 2 + ecef_km[1] ** 2) thet = atan(ecef_km[2] * a / (p * b)) esq = 1.0 - (b / a) ** 2 epsq = (a / b) ** 2 - 1.0 lat = atan((ecef_km[2] + epsq * b * sin(thet) ** 3) / (p - esq * a * cos(thet) ** 3)) lon = atan2(ecef_km[1], ecef_km[0]) n = a * a / sqrt(a * a * cos(lat) ** 2 + b ** 2 * sin(lat) ** 2) h = p / cos(lat) - n lat = degrees(lat) lon = degrees(lon) return lat, lon, h
Example #4
Source File: geo.py From kotori with GNU Affero General Public License v3.0 | 6 votes |
def turn_xyz_into_llh(x,y,z,system): """Convert 3D Cartesian x,y,z into Lat, Long and Height See http://www.ordnancesurvey.co.uk/gps/docs/convertingcoordinates3D.pdf""" a = abe_values[system][0] b = abe_values[system][1] e2 = abe_values[system][2] p = math.sqrt(x*x + y*y) long = math.atan(y/x) lat_init = math.atan( z / (p * (1.0 - e2)) ) v = a / math.sqrt( 1.0 - e2 * (math.sin(lat_init) * math.sin(lat_init)) ) lat = math.atan( (z + e2*v*math.sin(lat_init)) / p ) height = (p / math.cos(lat)) - v # Ignore if a bit out # Turn from radians back into degrees long = long / 2 / math.pi * 360 lat = lat / 2 / math.pi * 360 return [lat,long,height]
Example #5
Source File: macros.py From pyth with MIT License | 6 votes |
def trig(a, b=' '): if is_num(a) and isinstance(b, int): funcs = [math.sin, math.cos, math.tan, math.asin, math.acos, math.atan, math.degrees, math.radians, math.sinh, math.cosh, math.tanh, math.asinh, math.acosh, math.atanh] return funcs[b](a) if is_lst(a): width = max(len(row) for row in a) padded_matrix = [list(row) + (width - len(row)) * [b] for row in a] transpose = list(zip(*padded_matrix)) if all(isinstance(row, str) for row in a) and isinstance(b, str): normalizer = ''.join else: normalizer = list norm_trans = [normalizer(padded_row) for padded_row in transpose] return norm_trans return unknown_types(trig, ".t", a, b)
Example #6
Source File: route_manipulation.py From scenario_runner with MIT License | 6 votes |
def _location_to_gps(lat_ref, lon_ref, location): """ Convert from world coordinates to GPS coordinates :param lat_ref: latitude reference for the current map :param lon_ref: longitude reference for the current map :param location: location to translate :return: dictionary with lat, lon and height """ EARTH_RADIUS_EQUA = 6378137.0 # pylint: disable=invalid-name scale = math.cos(lat_ref * math.pi / 180.0) mx = scale * lon_ref * math.pi * EARTH_RADIUS_EQUA / 180.0 my = scale * EARTH_RADIUS_EQUA * math.log(math.tan((90.0 + lat_ref) * math.pi / 360.0)) mx += location.x my -= location.y lon = mx * 180.0 / (math.pi * EARTH_RADIUS_EQUA * scale) lat = 360.0 * math.atan(math.exp(my / (EARTH_RADIUS_EQUA * scale))) / math.pi - 90.0 z = location.z return {'lat': lat, 'lon': lon, 'z': z}
Example #7
Source File: angles.py From orbit-predictor with MIT License | 6 votes |
def E_to_ta(E, ecc): """True anomaly from eccentric anomaly. Parameters ---------- E : float Eccentric anomaly (rad). ecc : float Eccentricity. Returns ------- ta : float True anomaly (rad). """ ta = 2 * atan(sqrt((1 + ecc) / (1 - ecc)) * tan(E / 2)) return ta
Example #8
Source File: __init__.py From Arnold-For-Blender with GNU General Public License v3.0 | 6 votes |
def _view_update_camera(aspect, v3d, rv3d, camera): zoom = rv3d.view_camera_zoom z = ((_SQRT2 + zoom / 50) ** 2) / 4 cdata = v3d.camera.data fit = cdata.sensor_fit if fit == 'VERTICAL': sensor = cdata.sensor_height _sensor = (16 * sensor / 9) / z # sensor / (18 / 32) z *= 9 / 16 # 18 / 32 else: sensor = cdata.sensor_width _sensor = sensor / z lens = cdata.lens camera['fov'] = ('FLOAT', math.degrees(2 * math.atan(_sensor / (2 * lens)))) offset_x, offset_y = rv3d.view_camera_offset shift_x = cdata.shift_x shift_y = cdata.shift_y shx = 2 * z * (2 * offset_x + shift_x) shy = 2 * z * (2 * offset_y + shift_y * aspect) camera['screen_window_min'] = ('VECTOR2', (-1, -1)) camera['screen_window_max'] = ('VECTOR2', (1, 1)) return (zoom, fit, sensor, lens, offset_x, offset_y, shift_x, shift_y)
Example #9
Source File: visible_vertices.py From pyvisgraph with MIT License | 6 votes |
def angle(center, point): """Return the angle (radian) of point from center of the radian circle. ------p | / | / c|a/ """ dx = point.x - center.x dy = point.y - center.y if dx == 0: if dy < 0: return pi * 3 / 2 return pi / 2 if dy == 0: if dx < 0: return pi return 0 if dx < 0: return pi + atan(dy / dx) if dy < 0: return 2 * pi + atan(dy / dx) return atan(dy / dx)
Example #10
Source File: zoom.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
def pixel_to_lonlat(self, px, zoom): "Converts a pixel to a longitude, latitude pair at the given zoom level." if len(px) != 2: raise TypeError('Pixel should be a sequence of two elements.') # Getting the number of pixels for the given zoom level. npix = self._npix[zoom] # Calculating the longitude value, using the degrees per pixel. lon = (px[0] - npix) / self._degpp[zoom] # Calculating the latitude value. lat = RTOD * (2 * atan(exp((px[1] - npix) / (-1.0 * self._radpp[zoom]))) - 0.5 * pi) # Returning the longitude, latitude coordinate pair. return (lon, lat)
Example #11
Source File: DetectChars.py From ALPR-Indonesia with MIT License | 6 votes |
def angleBetweenChars(firstChar, secondChar): fltAdj = float(abs(firstChar.intCenterX - secondChar.intCenterX)) fltOpp = float(abs(firstChar.intCenterY - secondChar.intCenterY)) if fltAdj != 0.0: # check to make sure we do not divide by zero if the center X positions are equal, float division by zero will cause a crash in Python fltAngleInRad = math.atan(fltOpp / fltAdj) # if adjacent is not zero, calculate angle else: fltAngleInRad = 1.5708 # if adjacent is zero, use this as the angle, this is to be consistent with the C++ version of this program # end if fltAngleInDeg = fltAngleInRad * (180.0 / math.pi) # calculate angle in degrees return fltAngleInDeg # end function ################################################################################################### # if we have two chars overlapping or to close to each other to possibly be separate chars, remove the inner (smaller) char, # this is to prevent including the same char twice if two contours are found for the same char, # for example for the letter 'O' both the inner ring and the outer ring may be found as contours, but we should only include the char once
Example #12
Source File: gauge.py From Reinforcement-Learning-for-Self-Driving-Cars with Apache License 2.0 | 6 votes |
def _thick_line(self, start_point, end_point, fill, thickness): """Draws a line using polygons to give it a thickness""" if thickness == 1: self.line((start_point, end_point), fill=fill) else: # Angle of the line if end_point[0] == start_point[0]: # Catch a division by zero error a = math.pi / 2 else: a = math.atan((end_point[1] - start_point[1]) / (end_point[0] - start_point[0])) sin = math.sin(a) cos = math.cos(a) xdelta = sin * thickness / 2.0 ydelta = cos * thickness / 2.0 points = ((start_point[0] - xdelta, start_point[1] + ydelta), (start_point[0] + xdelta, start_point[1] - ydelta), (end_point[0] + xdelta, end_point[1] - ydelta), (end_point[0] - xdelta, end_point[1] + ydelta)) self.polygon(points, fill=fill)
Example #13
Source File: pointCloudFromCameraImage.py From soccer-matlab with BSD 2-Clause "Simplified" License | 6 votes |
def getRayFromTo(mouseX,mouseY): width, height, viewMat, projMat, cameraUp, camForward, horizon,vertical, _,_,dist, camTarget = p.getDebugVisualizerCamera() camPos = [camTarget[0] - dist*camForward[0],camTarget[1] - dist*camForward[1],camTarget[2] - dist*camForward[2]] farPlane = 10000 rayForward = [(camTarget[0]-camPos[0]),(camTarget[1]-camPos[1]),(camTarget[2]-camPos[2])] lenFwd = math.sqrt(rayForward[0]*rayForward[0]+rayForward[1]*rayForward[1]+rayForward[2]*rayForward[2]) invLen = farPlane*1./lenFwd rayForward = [invLen*rayForward[0],invLen*rayForward[1],invLen*rayForward[2]] rayFrom = camPos oneOverWidth = float(1)/float(width) oneOverHeight = float(1)/float(height) dHor = [horizon[0] * oneOverWidth,horizon[1] * oneOverWidth,horizon[2] * oneOverWidth] dVer = [vertical[0] * oneOverHeight,vertical[1] * oneOverHeight,vertical[2] * oneOverHeight] rayToCenter=[rayFrom[0]+rayForward[0],rayFrom[1]+rayForward[1],rayFrom[2]+rayForward[2]] ortho=[- 0.5 * horizon[0] + 0.5 * vertical[0]+float(mouseX)*dHor[0]-float(mouseY)*dVer[0], - 0.5 * horizon[1] + 0.5 * vertical[1]+float(mouseX)*dHor[1]-float(mouseY)*dVer[1], - 0.5 * horizon[2] + 0.5 * vertical[2]+float(mouseX)*dHor[2]-float(mouseY)*dVer[2]] rayTo = [rayFrom[0]+rayForward[0] +ortho[0], rayFrom[1]+rayForward[1] +ortho[1], rayFrom[2]+rayForward[2] +ortho[2]] lenOrtho = math.sqrt(ortho[0]*ortho[0]+ortho[1]*ortho[1]+ortho[2]*ortho[2]) alpha = math.atan(lenOrtho/farPlane) return rayFrom,rayTo, alpha
Example #14
Source File: epidemic.py From indras_net with GNU General Public License v3.0 | 6 votes |
def opposing_angle(pos1, pos2): ''' Returns the angle of the other_agent relative to the agent ''' x_dif = pos2[0] - pos1[0] y_dif = pos2[1] - pos1[1] if (x_dif != 0 and y_dif != 0): if (x_dif > 0): new_angle = 180 + degrees(atan(y_dif / x_dif)) else: new_angle = degrees(atan(y_dif / x_dif)) elif (y_dif != 0): if(y_dif > 0): new_angle = 270 else: new_angle = 90 else: if(x_dif > 0): new_angle = 180 else: new_angle = 0 return new_angle
Example #15
Source File: utils.py From verejne.digital with Apache License 2.0 | 5 votes |
def Mercator_to_WGS84(x, y): lat = math.degrees(2 * math.atan(math.exp(y / EARTH_EQUATORIAL_RADIUS)) - math.pi / 2) lon = math.degrees(x / EARTH_EQUATORIAL_RADIUS) return lat, lon # --- IO ---
Example #16
Source File: test_math.py From oss-ftp with MIT License | 5 votes |
def testAtanh(self): self.assertRaises(TypeError, math.atan) self.ftest('atanh(0)', math.atanh(0), 0) self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489) self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489) self.assertRaises(ValueError, math.atanh, 1) self.assertRaises(ValueError, math.atanh, -1) self.assertRaises(ValueError, math.atanh, INF) self.assertRaises(ValueError, math.atanh, NINF) self.assertTrue(math.isnan(math.atanh(NAN)))
Example #17
Source File: test_math.py From oss-ftp with MIT License | 5 votes |
def testAtan(self): self.assertRaises(TypeError, math.atan) self.ftest('atan(-1)', math.atan(-1), -math.pi/4) self.ftest('atan(0)', math.atan(0), 0) self.ftest('atan(1)', math.atan(1), math.pi/4) self.ftest('atan(inf)', math.atan(INF), math.pi/2) self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2) self.assertTrue(math.isnan(math.atan(NAN)))
Example #18
Source File: __init__.py From PyLidar3 with MIT License | 5 votes |
def _AngleCorr(cls,dist): if dist==0: return 0 else: return (atan(21.8*((155.3-dist)/(155.3*dist)))*(180/pi))
Example #19
Source File: joy_driver_pid.py From crazyflieROS with GNU General Public License v2.0 | 5 votes |
def fATAN(dist, r): return degrees(atan(dist))*sqrt(r)
Example #20
Source File: sphere.py From s2sphere with MIT License | 5 votes |
def uv_to_st(cls, u): if cls.PROJECTION == cls.LINEAR_PROJECTION: return 0.5 * (u + 1) elif cls.PROJECTION == cls.TAN_PROJECTION: return (2 * (1.0 / math.pi)) * (math.atan(u) * math.pi / 4.0) elif cls.PROJECTION == cls.QUADRATIC_PROJECTION: if u >= 0: return 0.5 * math.sqrt(1 + 3 * u) else: return 1 - 0.5 * math.sqrt(1 - 3 * u) else: raise ValueError('unknown projection type')
Example #21
Source File: merge_tiles.py From rosreestr2coord with MIT License | 5 votes |
def num2deg(xtile, ytile, zoom): """ This returns the NW-corner of the square. Use the function with xtile+1 and/or ytile+1 to get the other corners. With xtile+0.5 & ytile+0.5 it will return the center of the tile. """ n = 2.0 ** zoom lon_deg = xtile / n * 360.0 - 180.0 lat_rad = math.atan(math.sinh(math.pi * (1 - 2 * ytile / n))) lat_deg = math.degrees(lat_rad) return lat_deg, lon_deg
Example #22
Source File: utils.py From renpy-shader with MIT License | 5 votes |
def createPerspectiveBlender(lens, xResolution, yResolution, width, height, zMin, zMax): factor = lens / 32.0 ratio = xResolution / float(yResolution) fov = math.atan(0.5 / ratio / factor) fov = fov * 360 / math.pi return createPerspective(fov, width, height, zMin, zMax)
Example #23
Source File: __init__.py From py-expression-eval with MIT License | 5 votes |
def atand(self, a): return math.degrees(math.atan(a))
Example #24
Source File: utils.py From keras-face-recognition with MIT License | 5 votes |
def Alignment_1(img,landmark): if landmark.shape[0]==68: x = landmark[36,0] - landmark[45,0] y = landmark[36,1] - landmark[45,1] elif landmark.shape[0]==5: x = landmark[0,0] - landmark[1,0] y = landmark[0,1] - landmark[1,1] if x==0: angle = 0 else: angle = math.atan(y/x)*180/math.pi center = (img.shape[1]//2, img.shape[0]//2) RotationMatrix = cv2.getRotationMatrix2D(center, angle, 1) new_img = cv2.warpAffine(img,RotationMatrix,(img.shape[1],img.shape[0])) RotationMatrix = np.array(RotationMatrix) new_landmark = [] for i in range(landmark.shape[0]): pts = [] pts.append(RotationMatrix[0,0]*landmark[i,0]+RotationMatrix[0,1]*landmark[i,1]+RotationMatrix[0,2]) pts.append(RotationMatrix[1,0]*landmark[i,0]+RotationMatrix[1,1]*landmark[i,1]+RotationMatrix[1,2]) new_landmark.append(pts) new_landmark = np.array(new_landmark) return new_img, new_landmark
Example #25
Source File: projector.py From Projectors with GNU General Public License v3.0 | 5 votes |
def update_throw_ratio(proj_settings, context): """ Adjust some settings on a camera to achieve a throw ratio """ projector = get_projector(context) # Update properties of the camera. throw_ratio = proj_settings.get('throw_ratio') distance = 1 alpha = math.atan((distance/throw_ratio)*.5) * 2 projector.data.lens_unit = 'FOV' projector.data.angle = alpha projector.data.sensor_width = 10 projector.data.display_size = 1 # Adjust Texture to fit new camera ### w, h = get_resolution(proj_settings, context) aspect_ratio = w/h inverted_aspect_ratio = 1/aspect_ratio # Projected Texture update_projected_texture(proj_settings, context) # Update spotlight properties. spot = projector.children[0] nodes = spot.data.node_tree.nodes['Group'].node_tree.nodes if bpy.app.version < (2, 81): nodes['Mapping.001'].scale[0] = 1 / throw_ratio nodes['Mapping.001'].scale[1] = 1 / throw_ratio * inverted_aspect_ratio else: nodes['Mapping.001'].inputs[3].default_value[0] = 1 / throw_ratio nodes['Mapping.001'].inputs[3].default_value[1] = 1 / \ throw_ratio * inverted_aspect_ratio
Example #26
Source File: constrained.py From jMetalPy with MIT License | 5 votes |
def __evaluate_constraints(self, solution: FloatSolution) -> None: constraints = [0.0 for _ in range(self.number_of_constraints)] x1 = solution.variables[0] x2 = solution.variables[1] constraints[0] = (x1 * x1 + x2 * x2 - 1.0 - 0.1 * cos(16.0 * atan(x1 / x2))) constraints[1] = -2.0 * ((x1 - 0.5) * (x1 - 0.5) + (x2 - 0.5) * (x2 - 0.5) - 0.5) solution.constraints = constraints #set_overall_constraint_violation_degree(solution)
Example #27
Source File: main.py From angry-birds-python with MIT License | 5 votes |
def sling_action(): """Set up sling behavior""" global mouse_distance global rope_lenght global angle global x_mouse global y_mouse # Fixing bird to the sling rope v = vector((sling_x, sling_y), (x_mouse, y_mouse)) uv = unit_vector(v) uv1 = uv[0] uv2 = uv[1] mouse_distance = distance(sling_x, sling_y, x_mouse, y_mouse) pu = (uv1*rope_lenght+sling_x, uv2*rope_lenght+sling_y) bigger_rope = 102 x_redbird = x_mouse - 20 y_redbird = y_mouse - 20 if mouse_distance > rope_lenght: pux, puy = pu pux -= 20 puy -= 20 pul = pux, puy screen.blit(redbird, pul) pu2 = (uv1*bigger_rope+sling_x, uv2*bigger_rope+sling_y) pygame.draw.line(screen, (0, 0, 0), (sling2_x, sling2_y), pu2, 5) screen.blit(redbird, pul) pygame.draw.line(screen, (0, 0, 0), (sling_x, sling_y), pu2, 5) else: mouse_distance += 10 pu3 = (uv1*mouse_distance+sling_x, uv2*mouse_distance+sling_y) pygame.draw.line(screen, (0, 0, 0), (sling2_x, sling2_y), pu3, 5) screen.blit(redbird, (x_redbird, y_redbird)) pygame.draw.line(screen, (0, 0, 0), (sling_x, sling_y), pu3, 5) # Angle of impulse dy = y_mouse - sling_y dx = x_mouse - sling_x if dx == 0: dx = 0.00000000000001 angle = math.atan((float(dy))/dx)
Example #28
Source File: demo.py From unicorn-hat-hd with MIT License | 5 votes |
def tunnel(x, y, step): speed = step / 100.0 x -= (u_width / 2) y -= (u_height / 2) xo = math.sin(step / 27.0) * 2 yo = math.cos(step / 18.0) * 2 x += xo y += yo if y == 0: if x < 0: angle = -(math.pi / 2) else: angle = (math.pi / 2) else: angle = math.atan(x / y) if y > 0: angle += math.pi angle /= 2 * math.pi # convert angle to 0...1 range hyp = math.sqrt(math.pow(x, 2) + math.pow(y, 2)) shade = hyp / 2.1 shade = 1 if shade > 1 else shade angle += speed depth = speed + (hyp / 10) col1 = hue_to_rgb[step % 255] col1 = (col1[0] * 0.8, col1[1] * 0.8, col1[2] * 0.8) col2 = hue_to_rgb[step % 255] col2 = (col2[0] * 0.3, col2[1] * 0.3, col2[2] * 0.3) col = col1 if int(abs(angle * 6.0)) % 2 == 0 else col2 td = .3 if int(abs(depth * 3.0)) % 2 == 0 else 0 col = (col[0] + td, col[1] + td, col[2] + td) col = (col[0] * shade, col[1] * shade, col[2] * shade) return (col[0] * 255, col[1] * 255, col[2] * 255)
Example #29
Source File: test_math.py From ironpython2 with Apache License 2.0 | 5 votes |
def testAtan(self): self.assertRaises(TypeError, math.atan) self.ftest('atan(-1)', math.atan(-1), -math.pi/4) self.ftest('atan(0)', math.atan(0), 0) self.ftest('atan(1)', math.atan(1), math.pi/4) self.ftest('atan(inf)', math.atan(INF), math.pi/2) self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2) self.assertTrue(math.isnan(math.atan(NAN)))
Example #30
Source File: test_math.py From ironpython2 with Apache License 2.0 | 5 votes |
def testAtanh(self): self.assertRaises(TypeError, math.atan) self.ftest('atanh(0)', math.atanh(0), 0) self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489) self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489) self.assertRaises(ValueError, math.atanh, 1) self.assertRaises(ValueError, math.atanh, -1) self.assertRaises(ValueError, math.atanh, INF) self.assertRaises(ValueError, math.atanh, NINF) self.assertTrue(math.isnan(math.atanh(NAN)))