本文整理汇总了Python中math.tan方法的典型用法代码示例。如果您正苦于以下问题:Python math.tan方法的具体用法?Python math.tan怎么用?Python math.tan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math
的用法示例。
在下文中一共展示了math.tan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate_camera_variables
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def calculate_camera_variables(eye, lookat, up, fov, aspect_ratio, fov_is_vertical=False):
import numpy as np
import math
W = np.array(lookat) - np.array(eye)
wlen = np.linalg.norm(W)
U = np.cross(W, np.array(up))
U /= np.linalg.norm(U)
V = np.cross(U, W)
V /= np.linalg.norm(V)
if fov_is_vertical:
vlen = wlen * math.tan(0.5 * fov * math.pi / 180.0)
V *= vlen
ulen = vlen * aspect_ratio
U *= ulen
else:
ulen = wlen * math.tan(0.5 * fov * math.pi / 180.0)
U *= ulen
vlen = ulen * aspect_ratio
V *= vlen
return U, V, W
示例2: shear_matrix
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def shear_matrix(angle, direction, point, normal):
"""Return matrix to shear by angle along direction vector on shear plane.
The shear plane is defined by a point and normal vector. The direction
vector must be orthogonal to the plane's normal vector.
A point P is transformed by the shear matrix into P" such that
the vector P-P" is parallel to the direction vector and its extent is
given by the angle of P-P'-P", where P' is the orthogonal projection
of P onto the shear plane.
>>> angle = (random.random() - 0.5) * 4*math.pi
>>> direct = numpy.random.random(3) - 0.5
>>> point = numpy.random.random(3) - 0.5
>>> normal = numpy.cross(direct, numpy.random.random(3))
>>> S = shear_matrix(angle, direct, point, normal)
>>> numpy.allclose(1.0, numpy.linalg.det(S))
True
"""
normal = unit_vector(normal[:3])
direction = unit_vector(direction[:3])
if abs(numpy.dot(normal, direction)) > 1e-6:
raise ValueError("direction and normal vectors are not orthogonal")
angle = math.tan(angle)
M = numpy.identity(4)
M[:3, :3] += angle * numpy.outer(direction, normal)
M[:3, 3] = -angle * numpy.dot(point[:3], normal) * direction
return M
示例3: get_trafo
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def get_trafo(self):
angle1 = self.h_shear.get_angle_value()
angle2 = self.v_shear.get_angle_value()
m12 = math.tan(angle1)
m21 = math.tan(angle2)
m11 = 1.0
m22 = 1.0 - (m12 * m21)
trafo = [m11, m21, -m12, m22, 0, 0]
bbox = self.get_selection_bbox()
w, h = self.get_selection_size()
bp = [bbox[0] + w * (1.0 + self.orientation[0]) / 2.0,
bbox[1] + h * (1.0 + self.orientation[1]) / 2.0]
new_bp = libgeom.apply_trafo_to_point(bp, trafo)
trafo[4] = bp[0] - new_bp[0]
trafo[5] = bp[1] - new_bp[1]
return trafo
示例4: sunset_hour_angle
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def sunset_hour_angle(latitude, sol_dec):
"""
Calculate sunset hour angle (*Ws*) from latitude and solar
declination.
Based on FAO equation 25 in Allen et al (1998).
:param latitude: Latitude [radians]. Note: *latitude* should be negative
if it in the southern hemisphere, positive if in the northern
hemisphere.
:param sol_dec: Solar declination [radians]. Can be calculated using
``sol_dec()``.
:return: Sunset hour angle [radians].
:rtype: float
"""
_check_latitude_rad(latitude)
_check_sol_dec_rad(sol_dec)
cos_sha = -math.tan(latitude) * math.tan(sol_dec)
# If tmp is >= 1 there is no sunset, i.e. 24 hours of daylight
# If tmp is <= 1 there is no sunrise, i.e. 24 hours of darkness
# See http://www.itacanet.org/the-sun-as-a-source-of-energy/
# part-3-calculating-solar-angles/
# Domain of acos is -1 <= x <= 1 radians (this is not mentioned in FAO-56!)
return math.acos(min(max(cos_sha, -1.0), 1.0))
示例5: build_camera_info
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def build_camera_info(self, attributes): # pylint: disable=no-self-use
"""
Private function to compute camera info
camera info doesn't change over time
"""
camera_info = CameraInfo()
# store info without header
camera_info.header = None
camera_info.width = int(attributes['width'])
camera_info.height = int(attributes['height'])
camera_info.distortion_model = 'plumb_bob'
cx = camera_info.width / 2.0
cy = camera_info.height / 2.0
fx = camera_info.width / (
2.0 * math.tan(float(attributes['fov']) * math.pi / 360.0))
fy = fx
camera_info.K = [fx, 0, cx, 0, fy, cy, 0, 0, 1]
camera_info.D = [0, 0, 0, 0, 0]
camera_info.R = [1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0]
camera_info.P = [fx, 0, cx, 0, 0, fy, cy, 0, 0, 0, 1.0, 0]
return camera_info
示例6: trig
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
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)
示例7: ta_to_E
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
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
示例8: E_to_ta
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
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
示例9: polysum
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def polysum(n,s):
'''
Input: n - number of sides(should be an integer)
s- length of each sides(can be an intger or a float)
Output: Returns Sum of area and the square of the perimeter of the regular polygon(gives a float)
'''
#Code
def areaOfPolygon(n,s):
#Pi = 3.1428
area = (0.25 * n * s ** 2)/math.tan(math.pi/n)
return area
def perimeterOfPolygon(n,s):
perimeter = n * s
return perimeter
sum = areaOfPolygon(n,s) + (perimeterOfPolygon(n,s) ** 2)
return round(sum,4)
示例10: frame_from_angular_velocity_integrand
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def frame_from_angular_velocity_integrand(rfrak, Omega):
import math
from numpy import dot, cross
from .numpy_quaternion import _eps
rfrakMag = math.sqrt(rfrak[0] * rfrak[0] + rfrak[1] * rfrak[1] + rfrak[2] * rfrak[2])
OmegaMag = math.sqrt(Omega[0] * Omega[0] + Omega[1] * Omega[1] + Omega[2] * Omega[2])
# If the matrix is really close to the identity, return
if rfrakMag < _eps * OmegaMag:
return Omega[0] / 2.0, Omega[1] / 2.0, Omega[2] / 2.0
# If the matrix is really close to singular, it's equivalent to the identity, so return
if abs(math.sin(rfrakMag)) < _eps:
return Omega[0] / 2.0, Omega[1] / 2.0, Omega[2] / 2.0
OmegaOver2 = Omega[0] / 2.0, Omega[1] / 2.0, Omega[2] / 2.0
rfrakHat = rfrak[0] / rfrakMag, rfrak[1] / rfrakMag, rfrak[2] / rfrakMag
return ((OmegaOver2 - rfrakHat * dot(rfrakHat, OmegaOver2)) * (rfrakMag / math.tan(rfrakMag))
+ rfrakHat * dot(rfrakHat, OmegaOver2) + cross(OmegaOver2, rfrak))
示例11: testDistance
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def testDistance(self):
b1 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
b2 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
b2.transform(trafo.translate(3, 0))
b3 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
b3.transform(trafo.translate(3, 3 * math.tan(math.pi/6)))
b4 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
b4.transform(trafo.translate(0, 3))
b5 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
b5.transform(trafo.translate(0.5, 0.5))
self.assertAlmostEqual(unit.topt(b1.boxdistance(b2)), unit.topt(2))
self.assertAlmostEqual(unit.topt(b1.boxdistance(b3)), unit.topt(math.sqrt(9*(1 + math.tan(math.pi/6)**2)) - math.sqrt(3)/2))
self.assertAlmostEqual(unit.topt(b1.boxdistance(b4)), unit.topt(3 - math.sqrt(3)/2))
self.assertAlmostEqual(unit.topt(b2.boxdistance(b1)), unit.topt(2))
self.assertAlmostEqual(unit.topt(b3.boxdistance(b1)), unit.topt(math.sqrt(9*(1 + math.tan(math.pi/6)**2)) - math.sqrt(3)/2))
self.assertAlmostEqual(unit.topt(b4.boxdistance(b1)), unit.topt(3 - math.sqrt(3)/2))
self.assertRaises(box.BoxCrossError, b1.boxdistance, b5)
self.assertRaises(box.BoxCrossError, b5.boxdistance, b1)
示例12: _tan
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def _tan(x):
return math.tan(x),
示例13: rightAscension
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def rightAscension(l, b):
return atan(sin(l) * cos(e) - tan(b) * sin(e), cos(l))
示例14: azimuth
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def azimuth(H, phi, dec):
return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi))
示例15: getMoonPosition
# 需要导入模块: import math [as 别名]
# 或者: from math import tan [as 别名]
def getMoonPosition(date, lat, lng):
lw = rad * -lng
phi = rad * lat
d = toDays(date)
c = moonCoords(d)
H = siderealTime(d, lw) - c["ra"]
h = altitude(H, phi, c["dec"])
# altitude correction for refraction
h = h + rad * 0.017 / tan(h + rad * 10.26 / (h + rad * 5.10))
return dict(azimuth=azimuth(H, phi, c["dec"]),altitude=h,distance=c["dist"])