Python numpy.tan() Examples
The following are 30
code examples of numpy.tan().
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
numpy
, or try the search function
.
Example #1
Source File: test_mesh_io.py From simnibs with GNU General Public License v3.0 | 6 votes |
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])
Example #2
Source File: swiftshader_renderer.py From DOTA_models with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: utils_perspective.py From DIB-R with MIT License | 6 votes |
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) #####################################################
Example #4
Source File: kincar-flatsys.py From python-control with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #5
Source File: functions.py From tf-pose with Apache License 2.0 | 6 votes |
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
Example #6
Source File: kincar-flatsys.py From python-control with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #7
Source File: GLViewWidget.py From tf-pose with Apache License 2.0 | 6 votes |
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
Example #8
Source File: GLViewWidget.py From tf-pose with Apache License 2.0 | 6 votes |
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()
Example #9
Source File: dataset.py From HorizonNet with MIT License | 6 votes |
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)
Example #10
Source File: _continuous_distns.py From lambda-packs with MIT License | 5 votes |
def _ppf(self, q): return np.tan(np.pi*q-np.pi/2.0)
Example #11
Source File: conditional_simulation.py From gmpe-smtk with GNU Affero General Public License v3.0 | 5 votes |
def build_planar_surface(geometry): """ Builds the planar rupture surface from the openquake.nrmllib.models instance """ # Read geometry from wkt geom = wkt.loads(geometry.wkt) top_left = Point(geom.xy[0][0], geom.xy[1][0], geometry.upper_seismo_depth) top_right = Point(geom.xy[0][1], geom.xy[1][1], geometry.upper_seismo_depth) strike = top_left.azimuth(top_right) dip_dir = (strike + 90.) % 360. depth_diff = geometry.lower_seismo_depth - geometry.upper_seismo_depth bottom_right = top_right.point_at( depth_diff / np.tan(geometry.dip * (np.pi / 180.)), depth_diff, dip_dir) bottom_left = top_left.point_at( depth_diff / np.tan(geometry.dip * (np.pi / 180.)), depth_diff, dip_dir) return PlanarSurface(1.0, strike, geometry.dip, top_left, top_right, bottom_right, bottom_left)
Example #12
Source File: geodesy.py From typhon with MIT License | 5 votes |
def tand(x): """Tangent of argument in degrees.""" return np.tan(np.deg2rad(x))
Example #13
Source File: _continuous_distns.py From lambda-packs with MIT License | 5 votes |
def _ppf(self, q): return np.log(np.tan(np.pi*q/2.0))
Example #14
Source File: seglink.py From seglink with GNU General Public License v3.0 | 5 votes |
def tan(theta): return np.tan(theta / 180.0 * np.pi)
Example #15
Source File: test_old_ma.py From lambda-packs with MIT License | 5 votes |
def test_testUfuncs1(self): # Test various functions such as sin, cos. (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d self.assertTrue(eq(np.cos(x), cos(xm))) self.assertTrue(eq(np.cosh(x), cosh(xm))) self.assertTrue(eq(np.sin(x), sin(xm))) self.assertTrue(eq(np.sinh(x), sinh(xm))) self.assertTrue(eq(np.tan(x), tan(xm))) self.assertTrue(eq(np.tanh(x), tanh(xm))) with np.errstate(divide='ignore', invalid='ignore'): self.assertTrue(eq(np.sqrt(abs(x)), sqrt(xm))) self.assertTrue(eq(np.log(abs(x)), log(xm))) self.assertTrue(eq(np.log10(abs(x)), log10(xm))) self.assertTrue(eq(np.exp(x), exp(xm))) self.assertTrue(eq(np.arcsin(z), arcsin(zm))) self.assertTrue(eq(np.arccos(z), arccos(zm))) self.assertTrue(eq(np.arctan(z), arctan(zm))) self.assertTrue(eq(np.arctan2(x, y), arctan2(xm, ym))) self.assertTrue(eq(np.absolute(x), absolute(xm))) self.assertTrue(eq(np.equal(x, y), equal(xm, ym))) self.assertTrue(eq(np.not_equal(x, y), not_equal(xm, ym))) self.assertTrue(eq(np.less(x, y), less(xm, ym))) self.assertTrue(eq(np.greater(x, y), greater(xm, ym))) self.assertTrue(eq(np.less_equal(x, y), less_equal(xm, ym))) self.assertTrue(eq(np.greater_equal(x, y), greater_equal(xm, ym))) self.assertTrue(eq(np.conjugate(x), conjugate(xm))) self.assertTrue(eq(np.concatenate((x, y)), concatenate((xm, ym)))) self.assertTrue(eq(np.concatenate((x, y)), concatenate((x, y)))) self.assertTrue(eq(np.concatenate((x, y)), concatenate((xm, y)))) self.assertTrue(eq(np.concatenate((x, y, x)), concatenate((x, ym, x))))
Example #16
Source File: _continuous_distns.py From lambda-packs with MIT License | 5 votes |
def _isf(self, q): return np.tan(np.pi/2.0-np.pi*q)
Example #17
Source File: _continuous_distns.py From lambda-packs with MIT License | 5 votes |
def _ppf(self, q): return np.tan(np.pi/2*q)
Example #18
Source File: _continuous_distns.py From lambda-packs with MIT License | 5 votes |
def _ppf(self, q, c): val = (1.0-c)/(1.0+c) rcq = 2*np.arctan(val*np.tan(np.pi*q)) rcmq = 2*np.pi-2*np.arctan(val*np.tan(np.pi*(1-q))) return np.where(q < 1.0/2, rcq, rcmq)
Example #19
Source File: seismic.py From burnman with GNU General Public License v2.0 | 5 votes |
def attenuation_correction(v_p, v_s, v_phi, Qs, Qphi): """ Applies the attenuation correction following Matas et al. (2007), page 4. This is simplified, and there is also currently no 1D Q model implemented. The correction, however, only slightly reduces the velocities, and can be ignored for our current applications. Arguably, it might not be as relevant when comparing computations to PREM for periods of 1s as is implemented here. Called from :func:`burnman.main.apply_attenuation_correction` Parameters ---------- v_p : float P wave velocity in [m/s]. v_s : float S wave velocitiy in [m/s]. v_phi : float Bulk sound velocity in [m/s]. Qs : float shear quality factor [dimensionless] Qphi: float bulk quality factor [dimensionless] Returns ------- v_p : float corrected P wave velocity in [m/s]. v_s : float corrected S wave velocitiy in [m/s]. v_phi : float corrected Bulk sound velocity in [m/s]. """ beta = 0.3 # Matas et al. (2007) page 4 Qp = 3. / 4. * pow((v_p / v_s), 2.) * Qs # Matas et al. (2007) page 4 cot = 1. / np.tan(beta * np.pi / 2.) v_p *= 1. - 1. / 2. * cot * 1. / Qp # Matas et al. (2007) page 1 v_s *= 1. - 1. / 2. * cot * 1. / Qs v_phi *= 1. - 1. / 2. * cot * 1. / Qphi return v_p, v_s, v_phi
Example #20
Source File: test_core.py From recruit with Apache License 2.0 | 5 votes |
def test_no_masked_nan_warnings(self): # check that a nan in masked position does not # cause ufunc warnings m = np.ma.array([0.5, np.nan], mask=[0,1]) with warnings.catch_warnings(): warnings.filterwarnings("error") # test unary and binary ufuncs exp(m) add(m, 1) m > 0 # test different unary domains sqrt(m) log(m) tan(m) arcsin(m) arccos(m) arccosh(m) # test binary domains divide(m, 2) # also check that allclose uses ma ufuncs, to avoid warning allclose(m, 0.5)
Example #21
Source File: test_core.py From recruit with Apache License 2.0 | 5 votes |
def test_testUfuncRegression(self): # Tests new ufuncs on MaskedArrays. for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate', 'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan', 'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh', 'absolute', 'fabs', 'negative', 'floor', 'ceil', 'logical_not', 'add', 'subtract', 'multiply', 'divide', 'true_divide', 'floor_divide', 'remainder', 'fmod', 'hypot', 'arctan2', 'equal', 'not_equal', 'less_equal', 'greater_equal', 'less', 'greater', 'logical_and', 'logical_or', 'logical_xor', ]: try: uf = getattr(umath, f) except AttributeError: uf = getattr(fromnumeric, f) mf = getattr(numpy.ma.core, f) args = self.d[:uf.nin] ur = uf(*args) mr = mf(*args) assert_equal(ur.filled(0), mr.filled(0), f) assert_mask_equal(ur.mask, mr.mask, err_msg=f)
Example #22
Source File: test_core.py From recruit with Apache License 2.0 | 5 votes |
def test_basic_ufuncs(self): # Test various functions such as sin, cos. (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d assert_equal(np.cos(x), cos(xm)) assert_equal(np.cosh(x), cosh(xm)) assert_equal(np.sin(x), sin(xm)) assert_equal(np.sinh(x), sinh(xm)) assert_equal(np.tan(x), tan(xm)) assert_equal(np.tanh(x), tanh(xm)) assert_equal(np.sqrt(abs(x)), sqrt(xm)) assert_equal(np.log(abs(x)), log(xm)) assert_equal(np.log10(abs(x)), log10(xm)) assert_equal(np.exp(x), exp(xm)) assert_equal(np.arcsin(z), arcsin(zm)) assert_equal(np.arccos(z), arccos(zm)) assert_equal(np.arctan(z), arctan(zm)) assert_equal(np.arctan2(x, y), arctan2(xm, ym)) assert_equal(np.absolute(x), absolute(xm)) assert_equal(np.angle(x + 1j*y), angle(xm + 1j*ym)) assert_equal(np.angle(x + 1j*y, deg=True), angle(xm + 1j*ym, deg=True)) assert_equal(np.equal(x, y), equal(xm, ym)) assert_equal(np.not_equal(x, y), not_equal(xm, ym)) assert_equal(np.less(x, y), less(xm, ym)) assert_equal(np.greater(x, y), greater(xm, ym)) assert_equal(np.less_equal(x, y), less_equal(xm, ym)) assert_equal(np.greater_equal(x, y), greater_equal(xm, ym)) assert_equal(np.conjugate(x), conjugate(xm))
Example #23
Source File: test_old_ma.py From recruit with Apache License 2.0 | 5 votes |
def test_testUfuncRegression(self): f_invalid_ignore = [ 'sqrt', 'arctanh', 'arcsin', 'arccos', 'arccosh', 'arctanh', 'log', 'log10', 'divide', 'true_divide', 'floor_divide', 'remainder', 'fmod'] for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate', 'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan', 'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh', 'absolute', 'fabs', 'negative', 'floor', 'ceil', 'logical_not', 'add', 'subtract', 'multiply', 'divide', 'true_divide', 'floor_divide', 'remainder', 'fmod', 'hypot', 'arctan2', 'equal', 'not_equal', 'less_equal', 'greater_equal', 'less', 'greater', 'logical_and', 'logical_or', 'logical_xor']: try: uf = getattr(umath, f) except AttributeError: uf = getattr(fromnumeric, f) mf = getattr(np.ma, f) args = self.d[:uf.nin] with np.errstate(): if f in f_invalid_ignore: np.seterr(invalid='ignore') if f in ['arctanh', 'log', 'log10']: np.seterr(divide='ignore') ur = uf(*args) mr = mf(*args) assert_(eq(ur.filled(0), mr.filled(0), f)) assert_(eqmask(ur.mask, mr.mask))
Example #24
Source File: test_old_ma.py From recruit with Apache License 2.0 | 5 votes |
def test_testUfuncs1(self): # Test various functions such as sin, cos. (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d assert_(eq(np.cos(x), cos(xm))) assert_(eq(np.cosh(x), cosh(xm))) assert_(eq(np.sin(x), sin(xm))) assert_(eq(np.sinh(x), sinh(xm))) assert_(eq(np.tan(x), tan(xm))) assert_(eq(np.tanh(x), tanh(xm))) with np.errstate(divide='ignore', invalid='ignore'): assert_(eq(np.sqrt(abs(x)), sqrt(xm))) assert_(eq(np.log(abs(x)), log(xm))) assert_(eq(np.log10(abs(x)), log10(xm))) assert_(eq(np.exp(x), exp(xm))) assert_(eq(np.arcsin(z), arcsin(zm))) assert_(eq(np.arccos(z), arccos(zm))) assert_(eq(np.arctan(z), arctan(zm))) assert_(eq(np.arctan2(x, y), arctan2(xm, ym))) assert_(eq(np.absolute(x), absolute(xm))) assert_(eq(np.equal(x, y), equal(xm, ym))) assert_(eq(np.not_equal(x, y), not_equal(xm, ym))) assert_(eq(np.less(x, y), less(xm, ym))) assert_(eq(np.greater(x, y), greater(xm, ym))) assert_(eq(np.less_equal(x, y), less_equal(xm, ym))) assert_(eq(np.greater_equal(x, y), greater_equal(xm, ym))) assert_(eq(np.conjugate(x), conjugate(xm))) assert_(eq(np.concatenate((x, y)), concatenate((xm, ym)))) assert_(eq(np.concatenate((x, y)), concatenate((x, y)))) assert_(eq(np.concatenate((x, y)), concatenate((xm, y)))) assert_(eq(np.concatenate((x, y, x)), concatenate((x, ym, x))))
Example #25
Source File: ops.py From tributary with Apache License 2.0 | 5 votes |
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): if ufunc == np.add: if isinstance(inputs[0], Node): return inputs[0].__add__(inputs[1]) else: return inputs[1].__add__(inputs[0]) elif ufunc == np.subtract: if isinstance(inputs[0], Node): return inputs[0].__sub__(inputs[1]) else: return inputs[1].__sub__(inputs[0]) elif ufunc == np.multiply: if isinstance(inputs[0], Node): return inputs[0].__mul__(inputs[1]) else: return inputs[1].__mul__(inputs[0]) elif ufunc == np.divide: if isinstance(inputs[0], Node): return inputs[0].__truediv__(inputs[1]) else: return inputs[1].__truediv__(inputs[0]) elif ufunc == np.sin: return inputs[0].sin() elif ufunc == np.cos: return inputs[0].cos() elif ufunc == np.tan: return inputs[0].tan() elif ufunc == np.arcsin: return inputs[0].asin() elif ufunc == np.arccos: return inputs[0].acos() elif ufunc == np.arctan: return inputs[0].atan() elif ufunc == np.exp: return inputs[0].exp() elif ufunc == sp.special.erf: return inputs[0].erf() raise NotImplementedError('Not Implemented!')
Example #26
Source File: ops.py From tributary with Apache License 2.0 | 5 votes |
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): if ufunc == np.add: if isinstance(inputs[0], Node): return inputs[0].__add__(inputs[1]) else: return inputs[1].__add__(inputs[0]) elif ufunc == np.subtract: if isinstance(inputs[0], Node): return inputs[0].__sub__(inputs[1]) else: return inputs[1].__sub__(inputs[0]) elif ufunc == np.multiply: if isinstance(inputs[0], Node): return inputs[0].__mul__(inputs[1]) else: return inputs[1].__mul__(inputs[0]) elif ufunc == np.divide: if isinstance(inputs[0], Node): return inputs[0].__truediv__(inputs[1]) else: return inputs[1].__truediv__(inputs[0]) elif ufunc == np.sin: return inputs[0].sin() elif ufunc == np.cos: return inputs[0].cos() elif ufunc == np.tan: return inputs[0].tan() elif ufunc == np.arcsin: return inputs[0].asin() elif ufunc == np.arccos: return inputs[0].acos() elif ufunc == np.arctan: return inputs[0].atan() elif ufunc == np.exp: return inputs[0].exp() elif ufunc == sp.special.erf: return inputs[0].erf() raise NotImplementedError('Not Implemented!')
Example #27
Source File: ops.py From tributary with Apache License 2.0 | 5 votes |
def Tan(self): return unary(self, 'tan(' + self._name_no_id() + ')', (lambda x: math.tan(self.value())))
Example #28
Source File: test_camera.py From ratcave with MIT License | 5 votes |
def test_perspective_projection_updates(): proj = PerspectiveProjection() assert np.isclose(proj.projection_matrix[2, 2], (proj.z_far + proj.z_near) / (proj.z_near - proj.z_far)) assert np.isclose(proj.projection_matrix[0, 0], 1. / np.tan(np.radians(proj.fov_y / 2.)) / proj.aspect) proj.z_far = 30 assert np.isclose(proj.projection_matrix[2, 2], (proj.z_far + proj.z_near) / (proj.z_near - proj.z_far)) assert np.isclose(proj.projection_matrix[0, 0], 1. / np.tan(np.radians(proj.fov_y / 2.)) / proj.aspect) proj.aspect = .1 assert np.isclose(proj.projection_matrix[0, 0], 1. / np.tan(np.radians(proj.fov_y / 2.)) / proj.aspect) proj.fov_y = 25 assert np.isclose(proj.projection_matrix[0, 0], 1. / np.tan(np.radians(proj.fov_y / 2.)) / proj.aspect) with pytest.raises(ValueError): proj.z_far = -10 with pytest.raises(ValueError): proj.z_near = 100 with pytest.raises(ValueError): proj.z_near = -20 with pytest.raises(ValueError): p2 = PerspectiveProjection() p2.z_near = .1 p2.z_far = .01 with pytest.raises(ValueError): PerspectiveProjection(z_far=-.1) with pytest.raises(ValueError): proj.fov_y = -10
Example #29
Source File: camera.py From ratcave with MIT License | 5 votes |
def _update_projection_matrix(self): """np.array: The Camera's Projection Matrix. Will be an Orthographic matrix if ortho_mode is set to True.""" # replace gluPerspective (https://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml) ff = 1./np.tan(np.radians(self.fov_y / 2.)) # cotangent(fovy/2) zn, zf = self.z_near, self.z_far persp_mat = np.array([[ff/self.aspect, 0., 0., 0.], [ 0., ff, 0., 0.], [ 0., 0., (zf+zn)/(zn-zf), (2.*zf*zn)/(zn-zf)], [ 0., 0., -1., 0.]], dtype=np.float32) self.projection_matrix[:] = np.dot(persp_mat, self._get_shift_matrix()) # Apply lens shift
Example #30
Source File: demeter_iap.py From pysat with BSD 3-Clause "New" or "Revised" License | 5 votes |
def add_drift_sat_coord(inst): """ Calculate the ion velocity in satellite x,y,z coordinates Parameters ---------- inst : pysat.Instrument DEMETER IAP instrument class object Return ------ Adds data values iv_Ox, iv_Oy """ # Because np.radians isn't working for data coming from the DataFrame :( rad = np.array([np.radians(rr) for rr in inst['iv_negOz_angle']]) vxy = - inst['iv_Oz'] * np.tan(rad) rad = np.array([np.radians(rr) for rr in inst['iv_xOy_Ox_angle']]) inst['iv_Ox'] = vxy * np.cos(rad) inst['iv_Oy'] = vxy * np.sin(rad) inst.meta.data.units['iv_Ox'] = inst.meta.data.units['iv_Oz'] inst.meta.data.units['iv_Oy'] = inst.meta.data.units['iv_Oz'] # Because the ADV instrument is not fully aligned with the axis of the # satellite, reposition into satellite coordinates # (IS THIS ALREADY CORRECTED IN FILES?) print("WARNING the ADV instrument is not fully aligned with the axis of " + "the satellite and this may not have been corrected") return