本文整理匯總了Python中numpy.tan方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.tan方法的具體用法?Python numpy.tan怎麽用?Python numpy.tan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.tan方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_camera
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def set_camera(self, fov_vertical, z_near, z_far, aspect):
width = 2*np.tan(np.deg2rad(fov_vertical)/2.0)*z_near*aspect;
height = 2*np.tan(np.deg2rad(fov_vertical)/2.0)*z_near;
egl_program = self.egl_program
c = np.eye(4, dtype=np.float32)
c[3,3] = 0
c[3,2] = -1
c[2,2] = -(z_near+z_far)/(z_far-z_near)
c[2,3] = -2.0*(z_near*z_far)/(z_far-z_near)
c[0,0] = 2.0*z_near/width
c[1,1] = 2.0*z_near/height
c = c.T
projection_matrix_o = glGetUniformLocation(egl_program, 'uProjectionMatrix')
projection_matrix = np.eye(4, dtype=np.float32)
projection_matrix[...] = c
projection_matrix = np.reshape(projection_matrix, (-1))
glUniformMatrix4fv(projection_matrix_o, 1, GL_FALSE, projection_matrix)
示例2: cor2xybound
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def cor2xybound(cor):
''' Helper function to clip max/min stretch factor '''
corU = cor[0::2]
corB = cor[1::2]
zU = -50
u = panostretch.coorx2u(corU[:, 0])
vU = panostretch.coory2v(corU[:, 1])
vB = panostretch.coory2v(corB[:, 1])
x, y = panostretch.uv2xy(u, vU, z=zU)
c = np.sqrt(x**2 + y**2)
zB = c * np.tan(vB)
xmin, xmax = x.min(), x.max()
ymin, ymax = y.min(), y.max()
S = 3 / abs(zB.mean() - zU)
dx = [abs(xmin * S), abs(xmax * S)]
dy = [abs(ymin * S), abs(ymax * S)]
return min(dx), min(dy), max(dx), max(dy)
示例3: test_triangle_angles
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def test_triangle_angles(self):
msh = mesh_io.Msh()
# 2 regular tetrahedron of edge size 1
msh.elm = mesh_io.Elements(
triangles=np.array(
[[1, 2, 3],
[1, 2, 3],
[1, 4, 2],
[1, 4, 2]], dtype=int))
msh.nodes = mesh_io.Nodes(np.array(
[[0, 0, 0],
[1, 0, 0],
[0, np.tan(np.pi/6), 0],
[0, 0, np.tan(np.pi/6)]], dtype=float))
angles = msh.triangle_angles()
assert np.allclose(angles[:3], [90, 30, 60])
assert np.allclose(angles[3:], [90, 60, 30])
示例4: vehicle_flat_reverse
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def vehicle_flat_reverse(zflag, params={}):
# Get the parameter values
b = params.get('wheelbase', 3.)
# Create a vector to store the state and inputs
x = np.zeros(3)
u = np.zeros(2)
# Given the flat variables, solve for the state
x[0] = zflag[0][0] # x position
x[1] = zflag[1][0] # y position
x[2] = np.arctan2(zflag[1][1], zflag[0][1]) # tan(theta) = ydot/xdot
# And next solve for the inputs
u[0] = zflag[0][1] * np.cos(x[2]) + zflag[1][1] * np.sin(x[2])
thdot_v = zflag[1][2] * np.cos(x[2]) - zflag[0][2] * np.sin(x[2])
u[1] = np.arctan2(thdot_v, u[0]**2 / b)
return x, u
# Function to compute the RHS of the system dynamics
示例5: perspectiveprojectionnp
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def perspectiveprojectionnp(fovy, ratio=1.0, near=0.01, far=10.0):
tanfov = np.tan(fovy / 2.0)
# top = near * tanfov
# right = ratio * top
# mtx = [near / right, 0, 0, 0, \
# 0, near / top, 0, 0, \
# 0, 0, -(far+near)/(far-near), -2*far*near/(far-near), \
# 0, 0, -1, 0]
mtx = [[1.0 / (ratio * tanfov), 0, 0, 0], \
[0, 1.0 / tanfov, 0, 0], \
[0, 0, -(far + near) / (far - near), -2 * far * near / (far - near)], \
[0, 0, -1.0, 0]]
# return np.array(mtx, dtype=np.float32)
return np.array([[1.0 / (ratio * tanfov)], [1.0 / tanfov], [-1]], dtype=np.float32)
#####################################################
示例6: makeArrowPath
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def makeArrowPath(headLen=20, tipAngle=20, tailLen=20, tailWidth=3, baseAngle=0):
"""
Construct a path outlining an arrow with the given dimensions.
The arrow points in the -x direction with tip positioned at 0,0.
If *tipAngle* is supplied (in degrees), it overrides *headWidth*.
If *tailLen* is None, no tail will be drawn.
"""
headWidth = headLen * np.tan(tipAngle * 0.5 * np.pi/180.)
path = QtGui.QPainterPath()
path.moveTo(0,0)
path.lineTo(headLen, -headWidth)
if tailLen is None:
innerY = headLen - headWidth * np.tan(baseAngle*np.pi/180.)
path.lineTo(innerY, 0)
else:
tailWidth *= 0.5
innerY = headLen - (headWidth-tailWidth) * np.tan(baseAngle*np.pi/180.)
path.lineTo(innerY, -tailWidth)
path.lineTo(headLen + tailLen, -tailWidth)
path.lineTo(headLen + tailLen, tailWidth)
path.lineTo(innerY, tailWidth)
path.lineTo(headLen, headWidth)
path.lineTo(0,0)
return path
示例7: projectionMatrix
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def projectionMatrix(self, region=None):
# Xw = (Xnd + 1) * width/2 + X
if region is None:
region = (0, 0, self.width(), self.height())
x0, y0, w, h = self.getViewport()
dist = self.opts['distance']
fov = self.opts['fov']
nearClip = dist * 0.001
farClip = dist * 1000.
r = nearClip * np.tan(fov * 0.5 * np.pi / 180.)
t = r * h / w
# convert screen coordinates (region) to normalized device coordinates
# Xnd = (Xw - X0) * 2/width - 1
## Note that X0 and width in these equations must be the values used in viewport
left = r * ((region[0]-x0) * (2.0/w) - 1)
right = r * ((region[0]+region[2]-x0) * (2.0/w) - 1)
bottom = t * ((region[1]-y0) * (2.0/h) - 1)
top = t * ((region[1]+region[3]-y0) * (2.0/h) - 1)
tr = QtGui.QMatrix4x4()
tr.frustum(left, right, bottom, top, nearClip, farClip)
return tr
示例8: pan
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def pan(self, dx, dy, dz, relative=False):
"""
Moves the center (look-at) position while holding the camera in place.
If relative=True, then the coordinates are interpreted such that x
if in the global xy plane and points to the right side of the view, y is
in the global xy plane and orthogonal to x, and z points in the global z
direction. Distances are scaled roughly such that a value of 1.0 moves
by one pixel on screen.
"""
if not relative:
self.opts['center'] += QtGui.QVector3D(dx, dy, dz)
else:
cPos = self.cameraPosition()
cVec = self.opts['center'] - cPos
dist = cVec.length() ## distance from camera to center
xDist = dist * 2. * np.tan(0.5 * self.opts['fov'] * np.pi / 180.) ## approx. width of view at distance of center point
xScale = xDist / self.width()
zVec = QtGui.QVector3D(0,0,1)
xVec = QtGui.QVector3D.crossProduct(zVec, cVec).normalized()
yVec = QtGui.QVector3D.crossProduct(xVec, zVec).normalized()
self.opts['center'] = self.opts['center'] + xVec * xScale * dx + yVec * xScale * dy + zVec * xScale * dz
self.update()
示例9: tangent
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def tangent(x, null=(-np.inf, np.inf), rtol=default_rtol, atol=default_atol):
'''
tangent(x) is equivalent to tan(x) except that it also works on sparse arrays.
The optional argument null (default, (-numpy.inf, numpy.inf)) may be specified to indicate what
value(s) should be assigned when x == -pi/2 or -pi/2. If only one number is given, then it is
used for both values; otherwise the first value corresponds to -pi/2 and the second to pi/2.
A value of x is considered to be equal to one of these valids based on numpy.isclose. The
optional arguments rtol and atol are passed along to isclose. If null is None, then no
replacement is performed.
'''
if sps.issparse(x):
x = x.copy()
x.data = tangent(x.data, null=null, rtol=rtol, atol=atol)
return x
else: x = np.asarray(x)
if rtol is None: rtol = default_rtol
if atol is None: atol = default_atol
try: (nln,nlp) = null
except Exception: (nln,nlp) = (null,null)
x = np.mod(x + pi, tau) - pi
ii = None if nln is None else np.where(np.isclose(x, neghpi, rtol=rtol, atol=atol))
jj = None if nlp is None else np.where(np.isclose(x, hpi, rtol=rtol, atol=atol))
x = np.tan(x)
if ii: x[ii] = nln
if jj: x[jj] = nlp
return x
示例10: cotangent
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def cotangent(x, null=(-np.inf, np.inf), rtol=default_rtol, atol=default_atol):
'''
cotangent(x) is equivalent to cot(x) except that it also works on sparse arrays.
The optional argument null (default, (-numpy.inf, numpy.inf)) may be specified to indicate what
value(s) should be assigned when x == 0 or pi. If only one number is given, then it is used for
both values; otherwise the first value corresponds to 0 and the second to pi. A value of x is
considered to be equal to one of these valids based on numpy.isclose. The optional arguments
rtol and atol are passed along to isclose. If null is None, then no replacement is performed.
'''
if sps.issparse(x): x = x.toarray()
else: x = np.asarray(x)
if rtol is None: rtol = default_rtol
if atol is None: atol = default_atol
try: (nln,nlp) = null
except Exception: (nln,nlp) = (null,null)
x = np.mod(x + hpi, tau) - hpi
ii = None if nln is None else np.where(np.isclose(x, 0, rtol=rtol, atol=atol))
jj = None if nlp is None else np.where(np.isclose(x, pi, rtol=rtol, atol=atol))
x = np.tan(x)
if ii: x[ii] = 1
if jj: x[jj] = 1
x = 1.0 / x
if ii: x[ii] = nln
if jj: x[jj] = nlp
return x
示例11: get_camera_matrix
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def get_camera_matrix(width, height, fov):
"""Returns a camera matrix from image size and fov."""
xc = (width-1.) / 2.
zc = (height-1.) / 2.
f = (width / 2.) / np.tan(np.deg2rad(fov / 2.))
camera_matrix = utils.Foo(xc=xc, zc=zc, f=f)
return camera_matrix
示例12: render_nodes
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def render_nodes(self, nodes, perturb=None, aux_delta_theta=0.):
self.set_building_visibility(True)
if perturb is None:
perturb = np.zeros((len(nodes), 4))
imgs = []
r = 2
elevation_z = r * np.tan(np.deg2rad(self.robot.camera_elevation_degree))
for i in range(len(nodes)):
xyt = self.to_actual_xyt(nodes[i])
lookat_theta = 3.0 * np.pi / 2.0 - (xyt[2]+perturb[i,2]+aux_delta_theta) * (self.task.delta_theta)
nxy = np.array([xyt[0]+perturb[i,0], xyt[1]+perturb[i,1]]).reshape(1, -1)
nxy = nxy * self.map.resolution
nxy = nxy + self.map.origin
camera_xyz = np.zeros((1, 3))
camera_xyz[...] = [nxy[0, 0], nxy[0, 1], self.robot.sensor_height]
camera_xyz = camera_xyz / 100.
lookat_xyz = np.array([-r * np.sin(lookat_theta),
-r * np.cos(lookat_theta), elevation_z])
lookat_xyz = lookat_xyz + camera_xyz[0, :]
self.r_obj.position_camera(camera_xyz[0, :].tolist(),
lookat_xyz.tolist(), [0.0, 0.0, 1.0])
img = self.r_obj.render(take_screenshot=True, output_type=0)
img = [x for x in img if x is not None]
img = np.concatenate(img, axis=2).astype(np.float32)
if perturb[i,3]>0:
img = img[:,::-1,:]
imgs.append(img)
self.set_building_visibility(False)
return imgs
示例13: test_target_completeness_def
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def test_target_completeness_def(self):
"""
Compare calculated completenesses for multiple targets under default population
settings.
"""
with RedirectStreams(stdout=self.dev_null):
TL = TargetList(ntargs=100,**copy.deepcopy(self.spec))
mode = list(filter(lambda mode: mode['detectionMode'] == True, TL.OpticalSystem.observingModes))[0]
IWA = mode['IWA']
OWA = mode['OWA']
rrange = TL.PlanetPopulation.rrange
maxd = (rrange[1]/np.tan(IWA)).to(u.pc).value
mind = (rrange[0]/np.tan(OWA)).to(u.pc).value
#want distances to span from outer edge below IWA to inner edge above OWA
TL.dist = np.logspace(np.log10(mind/10.),np.log10(maxd*10.),TL.nStars)*u.pc
Brown = EXOSIMS.Completeness.BrownCompleteness.BrownCompleteness(**copy.deepcopy(self.spec))
Garrett = EXOSIMS.Completeness.GarrettCompleteness.GarrettCompleteness(**copy.deepcopy(self.spec))
cBrown = Brown.target_completeness(TL)
cGarrett = Garrett.target_completeness(TL)
np.testing.assert_allclose(cGarrett,cBrown,rtol=0.1,atol=1e-6)
# test when scaleOrbits == True
TL.L = np.exp(np.random.uniform(low=np.log(0.1), high=np.log(10.), size=TL.nStars))
Brown.PlanetPopulation.scaleOrbits = True
Garrett.PlanetPopulation.scaleOrbits = True
cBrown = Brown.target_completeness(TL)
cGarrett = Garrett.target_completeness(TL)
cGarrett = cGarrett[cBrown != 0 ]
cBrown = cBrown[cBrown != 0]
meandiff = np.mean(np.abs(cGarrett - cBrown)/cBrown)
self.assertLessEqual(meandiff,0.1)
示例14: test_target_completeness_constrainOrbits
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def test_target_completeness_constrainOrbits(self):
"""
Compare calculated completenesses for multiple targets with constrain orbits set to true
"""
with RedirectStreams(stdout=self.dev_null):
TL = TargetList(ntargs=100,constrainOrbits=True,**copy.deepcopy(self.spec))
mode = list(filter(lambda mode: mode['detectionMode'] == True, TL.OpticalSystem.observingModes))[0]
IWA = mode['IWA']
OWA = mode['OWA']
rrange = TL.PlanetPopulation.rrange
maxd = (rrange[1]/np.tan(IWA)).to(u.pc).value
mind = (rrange[0]/np.tan(OWA)).to(u.pc).value
#want distances to span from outer edge below IWA to inner edge above OWA
TL.dist = np.logspace(np.log10(mind/10.),np.log10(maxd*10.),TL.nStars)*u.pc
Brown = EXOSIMS.Completeness.BrownCompleteness.BrownCompleteness(constrainOrbits=True,**copy.deepcopy(self.spec))
Garrett = EXOSIMS.Completeness.GarrettCompleteness.GarrettCompleteness(constrainOrbits=True,**copy.deepcopy(self.spec))
cBrown = Brown.target_completeness(TL)
cGarrett = Garrett.target_completeness(TL)
np.testing.assert_allclose(cGarrett,cBrown,rtol=0.1,atol=1e-6)
示例15: outside_IWA_filter
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tan [as 別名]
def outside_IWA_filter(self):
"""Includes stars with planets with orbits outside of the IWA
"""
PPop = self.PlanetPopulation
OS = self.OpticalSystem
s = np.tan(OS.IWA)*self.dist
L = np.sqrt(self.L) if PPop.scaleOrbits else 1.
i = np.where(s < L*np.max(PPop.rrange))[0]
self.revise_lists(i)