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)
python类atan()的实例源码
def angle(vector1, vector2):
"""Return the angle between vector1 and vector2 in radians [0, pi]."""
u1 = vector1.normalize()
u2 = vector2.normalize()
cosine = u1 * u2
if cosine == 1.0:
return 0
elif cosine == -1.0:
return math.pi
elif cosine == 0.0:
return math.pi/2
# Unit vectors: sine == sqrt(1.0 ** 2 - cosine ** 2) if angle within [0, pi]
tangent = math.sqrt(1.0 - cosine * cosine) / cosine
return math.atan(tangent)
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]
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)
def _step(self, action):
assert self.action_space.contains(action), "%r (%s) invalid"%(action, type(action))
# Action Step
self.A.speed = (action[0]+action[1])/2.0 * 5.0
self.A.dir_Angle += math.atan((action[0] - action[1]) * self.A.speed / 2.0 / 5.0)
self.A.dir_Angle = ( self.A.dir_Angle + np.pi) % (2 * np.pi ) - np.pi
done = self.A.Move([self.BBox])
self.A.Sens(self.Course)
self.state = (1,) if self.A.EYE.obj == 1 else (0,)
if not done:
reward = 1.0
elif self.steps_beyond_done is None:
# Robot just went out over the boundary
self.steps_beyond_done = 0
reward = 1.0
else:
if self.steps_beyond_done == 0:
logger.warn("You are calling 'step()' even though this environment has already returned done = True. You should always call 'reset()' once you receive 'done = True' -- any further steps are undefined behavior.")
self.steps_beyond_done += 1
reward = 0.0
return np.array(self.state), reward, done, {'AgentPos':(self.A.pos_x,self.A.pos_y),'AegntDir':self.A.dir_Angle}
def calcRoll(self, accel):
x = accel[0]
y = accel[1]
z = accel[2]
try:
phi = math.atan(y / z)
except:
if y > 0:
phi = 1.0
else:
phi = -1.0
return phi
def calcPitch(self, accel):
x = accel[0]
y = accel[1]
z = accel[2]
try:
theta = math.atan(-x / math.sqrt(y * y + z * z))
except:
if x > 0:
theta = -1.0
else:
theta = 1.0
return theta
def calcYaw(self, magnet, roll, pitch):
magX = magnet[0]
magY = magnet[1]
magZ = magnet[2]
rowX = magX
rowY = -magY
rowZ = -magZ
row = np.matrix([[rowX], [rowY], [rowZ]])
A = np.matrix([ \
[math.cos(roll), math.sin(roll) * math.sin(pitch), math.cos(pitch) * math.sin(roll)] \
, [0, math.cos(pitch), -math.sin(pitch)] \
, [-math.sin(roll), math.sin(pitch) * math.cos(roll), math.cos(roll) * math.cos(pitch)] \
])
calib = A * row
calibX = row[0]
calibY = row[1]
calibZ = row[2]
try:
yaw = math.atan(calibY / calibX)
except:
if calibY > 0:
yaw = 1.0
else:
yaw = -1.0
return yaw
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')
def area(a, b, c):
"""Area of the triangle (a, b, c).
see :cpp:func:`S2::Area`
"""
assert is_unit_length(a)
assert is_unit_length(b)
assert is_unit_length(c)
sa = b.angle(c)
sb = c.angle(a)
sc = a.angle(b)
s = 0.5 * (sa + sb + sc)
if s >= 3e-4:
s2 = s * s
dmin = s - max(sa, max(sb, sc))
if dmin < 1e-2 * s * s2 * s2:
area = girard_area(a, b, c)
if dmin < 2 * (0.1 * area):
return area
return 4 * math.atan(math.sqrt(
max(0.0,
math.tan(0.5 * s) *
math.tan(0.5 * (s - sa)) *
math.tan(0.5 * (s - sb)) *
math.tan(0.5 * (s - sc)))
))
def __init__(self, root, tip, span, sweep=None, sweepangle=45.0):
self.root = root #: Root Chord of fin
self.tip = tip #: Tip Chord of fin
self.span = span #: Span ("height") of fin
self._length = root
if sweep is not None:
self.sweep = sweep #: Sweep length of the fin
self.sweepangle = atan(self.sweep / self.span)
"""Angle of sweep of the fin [radians]"""
else:
self.sweep = span * tan(radians(sweepangle))
self.sweepangle = radians(sweepangle)
def get_xy(alpha, beta, structure_settings):
r = structure_settings.r # short arm length (attached to the rotative axis)
a = structure_settings.a # long arm length
s = structure_settings.s # pen distance
xa = structure_settings.xa #left short arm x
xb = structure_settings.xb #right short arm x
# d is the first short arm extremity
xd = xa - r * math.sin(alpha)
yd = r * math.cos(alpha)
# e is the first short arm extremity
xe = xb - r * math.sin(beta)
ye = r * math.cos(beta)
de = compute_distance(xd, yd, xe, ye)
#theta is the angle formed by de and the left long arm
cos_theta = de/float(2 * a)
cos_theta = min(cos_theta, 1.0)
cos_theta = max(cos_theta, -1.0)
theta = math.acos(cos_theta)
#gamma is the angle formed by an horizontal axis and de
tan_gamma = (ye-yd)/float(xe-xd)
gamma = math.atan(tan_gamma)
#lambda is the angle formed by an horizontal axis and the left long arm
lam = theta + gamma
xt = xd + a * math.cos(lam) - s * math.sin(lam)
yt = yd + a * math.sin(lam) + s * math.cos(lam)
return xt, yt
def atand(self, x):
"""Returns the arc tan in degrees"""
return math.atan(x) * self.RADEG
def calc_user_look_at(pos_sat, lat, lon, alt, t):
pos = calc_pos(lat, lon, alt, t)
rx = pos_sat.x - pos.x
ry = pos_sat.y - pos.y
rz = pos_sat.z - pos.z
jd = julian_date(t)
theta = (theta_g_JD(jd) + lon) % TWO_PI
top_s = sin(lat) * cos(theta) * rx + \
sin(lat) * sin(theta) * ry - \
cos(lat) * rz
top_e = -sin(theta) * rx + \
cos(theta) * ry
top_z = cos(lat) * cos(theta) * rx + \
cos(lat) * sin(theta) * ry + \
sin(lat) * rz
az = atan(-top_e/top_s)
if top_s > 0:
az += pi
if az < 0:
az += TWO_PI
rg = (rx*rx + ry*ry + rz*rz)**0.5
el = asin(top_z/rg)
return (az, el, rg)
def unproject(x, y):
"""
Converts a x/y point to a lat/lng coordinate
"""
d = 180.0 / math.pi
return (
(2.0 * math.atan(math.exp(y / SphericalMercator.R)) - (math.pi / 2.0)) * d,
x * d / SphericalMercator.R
)
def fromGeographic(self, lat, lon):
lat = math.radians(lat)
lon = math.radians(lon-self.lon)
B = math.sin(lon) * math.cos(lat)
x = 0.5 * self.k * self.radius * math.log((1.+B)/(1.-B))
y = self.k * self.radius * ( math.atan(math.tan(lat)/math.cos(lon)) - self.latInRadians )
return (x,y)
def toGeographic(self, x, y):
x = x/(self.k * self.radius)
y = y/(self.k * self.radius)
D = y + self.latInRadians
lon = math.atan(math.sinh(x)/math.cos(D))
lat = math.asin(math.sin(D)/math.cosh(x))
lon = self.lon + math.degrees(lon)
lat = math.degrees(lat)
return (lat, lon)
def tLowDotOperator(stack, z, mode):
if mode == 1: # num
stack.append(utilities.formatNum(math.atan(z)))
elif mode == 2 or mode == 3: # str or list
stack.append(1 if z[::-1]==z else 0)
else:
monadNotImplemented(mode, '')
# ?
def __init__(self,g_pool , focal_length ):
super().__init__(g_pool , "Debug Visualizer", False)
self.focal_length = focal_length
self.image_width = 640 # right values are assigned in update
self.image_height = 480
camera_fov = math.degrees(2.0 * math.atan( self.image_height / (2.0 * self.focal_length)))
self.trackball = Trackball(camera_fov)
############## MATRIX FUNCTIONS ##############################
def __init__(self, g_pool, world_camera_intrinsics , cal_ref_points_3d, cal_observed_points_3d, eye_camera_to_world_matrix0 , cal_gaze_points0_3d, eye_camera_to_world_matrix1 = np.eye(4) , cal_gaze_points1_3d = [], run_independently = False , name = "Calibration Visualizer" ):
super().__init__( g_pool,name, run_independently)
self.image_width = 640 # right values are assigned in update
self.focal_length = 620
self.image_height = 480
self.eye_camera_to_world_matrix0 = eye_camera_to_world_matrix0
self.eye_camera_to_world_matrix1 = eye_camera_to_world_matrix1
self.cal_ref_points_3d = cal_ref_points_3d
self.cal_observed_points_3d = cal_observed_points_3d
self.cal_gaze_points0_3d = cal_gaze_points0_3d
self.cal_gaze_points1_3d = cal_gaze_points1_3d
if world_camera_intrinsics:
self.world_camera_width = world_camera_intrinsics['resolution'][0]
self.world_camera_height = world_camera_intrinsics['resolution'][1]
self.world_camera_focal = (world_camera_intrinsics['camera_matrix'][0][0] + world_camera_intrinsics['camera_matrix'][1][1] ) / 2.0
else:
self.world_camera_width = 0
self.world_camera_height = 0
self.world_camera_focal = 0
camera_fov = math.degrees(2.0 * math.atan( self.window_size[0] / (2.0 * self.focal_length)))
self.trackball = Trackball(camera_fov)
self.trackball.distance = [0,0,-80.]
self.trackball.pitch = 210
self.trackball.roll = 0
########### Open, update, close #####################