Python math.tan() Examples

The following are 30 code examples of math.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 math , or try the search function .
Example #1
Source File: ros_agent.py    From scenario_runner with MIT License 7 votes vote down vote up
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 
Example #2
Source File: macros.py    From pyth with MIT License 6 votes vote down vote up
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 #3
Source File: quaternion_time_series.py    From quaternion with MIT License 6 votes vote down vote up
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)) 
Example #4
Source File: fao.py    From PyETo with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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)) 
Example #5
Source File: transforms.py    From sk1-wx with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #6
Source File: polySum.py    From MITx-6.00.1x with MIT License 6 votes vote down vote up
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) 
Example #7
Source File: angles.py    From orbit-predictor with MIT License 6 votes vote down vote up
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: angles.py    From orbit-predictor with MIT License 6 votes vote down vote up
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 #9
Source File: transformations.py    From rai-python with MIT License 6 votes vote down vote up
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 
Example #10
Source File: test_box.py    From pyx with GNU General Public License v2.0 6 votes vote down vote up
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) 
Example #11
Source File: common.py    From PyOptiX with MIT License 6 votes vote down vote up
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 
Example #12
Source File: svgfile.py    From pyx with GNU General Public License v2.0 5 votes vote down vote up
def toTrafo(self, svgTrafo):
        t = trafo.identity
        for match in reversed(list(re.finditer(r"(?P<cmd>matrix|translate|scale|rotate|skewX|skewY)\((?P<args>[^)]*)\)", svgTrafo))):
            cmd = match.group("cmd")
            args = match.group("args")
            if cmd == "matrix":
                a, args = self.toFloat(args, units=False)
                b, args = self.toFloat(args, units=False)
                c, args = self.toFloat(args, units=False)
                d, args = self.toFloat(args, units=False)
                e, args = self.toFloat(args)
                f = self.toFloat(args, single=True)
                t = t * trafo.trafo_pt(((a, b), (c, d)), (e, f))
            elif cmd == "translate":
                args = list(self.toFloats(args))
                if len(args) == 1:
                    args.append(0)
                assert len(args) == 2
                t = t.translated_pt(args[0], args[1])
            elif cmd == "scale":
                args = list(self.toFloats(args, units=False))
                if len(args) == 1:
                    args.append(args[0])
                assert len(args) == 2
                t = t.scaled(args[0], args[1])
            elif cmd == "rotate":
                a, args = self.toFloat(args, units=False)
                if args:
                    b, args = self.toFloat(args)
                    c = self.toFloat(args, single=True)
                else:
                    b, c = 0, 0
                t = t.rotated_pt(a, b, c)
            elif cmd == "skewX":
                t = t * trafo.trafo_pt(((1, math.tan(self.toFloat(args, units=False, single=True)*math.pi/180)), (0, 1)))
            else:
                assert cmd == "skewY"
                t = t * trafo.trafo_pt(((1, 0), (math.tan(self.toFloat(args, units=False, single=True)*math.pi/180), 1)))
        return t 
Example #13
Source File: transform.py    From AugmentedAutoencoder with MIT License 5 votes vote down vote up
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, 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 
Example #14
Source File: test_math.py    From oss-ftp with MIT License 5 votes vote down vote up
def testTan(self):
        self.assertRaises(TypeError, math.tan)
        self.ftest('tan(0)', math.tan(0), 0)
        self.ftest('tan(pi/4)', math.tan(math.pi/4), 1)
        self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1)
        try:
            self.assertTrue(math.isnan(math.tan(INF)))
            self.assertTrue(math.isnan(math.tan(NINF)))
        except:
            self.assertRaises(ValueError, math.tan, INF)
            self.assertRaises(ValueError, math.tan, NINF)
        self.assertTrue(math.isnan(math.tan(NAN))) 
Example #15
Source File: transform.py    From AugmentedAutoencoder with MIT License 5 votes vote down vote up
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, 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 
Example #16
Source File: __init__.py    From py-expression-eval with MIT License 5 votes vote down vote up
def tand(self, a):
        return math.tan(math.radians(a)) 
Example #17
Source File: test_quadpack.py    From Computable with MIT License 5 votes vote down vote up
def test_typical(self):
        assert_quad(quad(self.lib.sin,0,5),quad(math.sin,0,5)[0])
        assert_quad(quad(self.lib.cos,0,5),quad(math.cos,0,5)[0])
        assert_quad(quad(self.lib.tan,0,1),quad(math.tan,0,1)[0])

    #@dec.skipif(_ctypes_missing, msg="Ctypes library could not be found")
    # This doesn't seem to always work.  Need a better way to figure out
    # whether the fast path is called. 
Example #18
Source File: test_quadpack.py    From Computable with MIT License 5 votes vote down vote up
def setUp(self):
        if sys.platform == 'win32':
            file = 'msvcrt.dll'
        elif sys.platform == 'darwin':
            file = 'libm.dylib'
        else:
            file = 'libm.so'
        self.lib = ctypes.CDLL(file)
        restype = ctypes.c_double
        argtypes = (ctypes.c_double,)
        for name in ['sin', 'cos', 'tan']:
            func = getattr(self.lib, name)
            func.restype = restype
            func.argtypes = argtypes 
Example #19
Source File: cosmology.py    From easyGalaxy with MIT License 5 votes vote down vote up
def scale(self, z, cm=False, meter=False, pc=False, kpc=False, mpc=False):
        return math.tan(1.0 / 3600 * math.pi / 180) * self.Da(z,
                                                              cm=cm,
                                                              meter=meter,
                                                              pc=pc,
                                                              kpc=kpc,
                                                              mpc=mpc)

    # added 12/05/11 - Conor Mancone  Ages should be in years 
Example #20
Source File: tabledraw.py    From MangoByte with MIT License 5 votes vote down vote up
def render(self, draw, image, x, y, width, height):
		pos = (x, y + height)
		xshift = 0

		font_image_size = (self.text_size[0] + self.text_size[1], self.text_size[0] + self.text_size[1])
		font_pos = (int(self.text_size[1] / 2), self.text_size[0])
		font_center_pos = (font_pos[0], font_pos[1] + int(self.text_size[1] / 2))

		# background & border setup
		linestart = (pos[0] + width, pos[1])
		lineend = (linestart[0] + int(height / math.tan(self.rotation_rad)), linestart[1] - height)
		box_top = (tuplediff(lineend, (width, 0)), lineend)
		box_bottom = (tuplediff(linestart, (width, 0)), linestart)
		if self.background:
			draw.polygon([box_top[0], box_top[1], box_bottom[1], box_bottom[0]], fill=self.background)

		# border
		draw.line((tuplediff(linestart, (self.border_size, 0)), tuplediff(lineend, (self.border_size, 0))), fill=self.border_color, width=self.border_size)
		draw.line(box_top, fill=self.border_color, width=self.border_size)
		draw.line((tuplediff(box_bottom[0], (0 - self.border_size, self.border_size)), tuplediff(box_bottom[1], (0, self.border_size))), fill=self.border_color, width=self.border_size)

		# text
		text_image = Image.new('RGBA', font_image_size)
		text_draw = ImageDraw.Draw(text_image)
		text_draw.text(font_pos, self.text, font=self.font, fill=self.color)
		text_image = text_image.rotate(self.rotation, resample=Image.BILINEAR, center=font_center_pos)

		font_destination = tuplediff(pos, font_pos)
		font_destination = (font_destination[0] + int(width / 2) + xshift, font_destination[1] - int(self.text_size[1] / 2) - self.padding[2])
		image = paste_image(image, text_image, int(font_destination[0]), int(font_destination[1]))
		draw = ImageDraw.Draw(image)


		return image, draw 
Example #21
Source File: matrix.py    From xy with MIT License 5 votes vote down vote up
def perspective(self, fov, aspect, near, far):
        ymax = near * tan(fov * pi / 360)
        xmax = ymax * aspect
        return self.frustum(-xmax, xmax, -ymax, ymax, near, far) 
Example #22
Source File: mathGlyph.py    From Robofont-scripts with MIT License 5 votes vote down vote up
def _skewXByAngle(self, x, y, angle):
        return x + (y * tan(angle)) 
Example #23
Source File: transform.py    From sixd_toolkit with MIT License 5 votes vote down vote up
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, 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 
Example #24
Source File: transform.py    From patch_linemod with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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, 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 
Example #25
Source File: transform.py    From pygcode with GNU General Public License v3.0 5 votes vote down vote up
def get_outer_radius(self):
        """Radius from which each line forms a chord"""
        d_radius = self.arc_radius * (tan(self.wedge_angle / 4.) ** 2)
        return self.arc_radius + d_radius 
Example #26
Source File: transform.py    From pygcode with GNU General Public License v3.0 5 votes vote down vote up
def get_inner_radius(self):
        """Radius each line is tangential to"""
        d_radius = self.arc_radius * (tan(self.wedge_angle / 4.) ** 2)
        return self.arc_radius - d_radius 
Example #27
Source File: trigonometry.py    From visma with GNU General Public License v3.0 5 votes vote down vote up
def calculate(self, val):
        return self.coefficient * ((math.tan(val))**self.power) 
Example #28
Source File: trigonometry.py    From visma with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        super().__init__()
        self.value = 'tan' 
Example #29
Source File: test_math.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testTan(self):
        self.assertRaises(TypeError, math.tan)
        self.ftest('tan(0)', math.tan(0), 0)
        self.ftest('tan(pi/4)', math.tan(math.pi/4), 1)
        self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1)
        try:
            self.assertTrue(math.isnan(math.tan(INF)))
            self.assertTrue(math.isnan(math.tan(NINF)))
        except:
            self.assertRaises(ValueError, math.tan, INF)
            self.assertRaises(ValueError, math.tan, NINF)
        self.assertTrue(math.isnan(math.tan(NAN))) 
Example #30
Source File: euclid.py    From renpy-shader with MIT License 5 votes vote down vote up
def new_perspective(cls, fov_y, aspect, near, far):
        # from the gluPerspective man page
        f = 1 / math.tan(fov_y / 2)
        self = cls()
        assert near != 0.0 and near != far
        self.a = f / aspect
        self.f = f
        self.k = (far + near) / (near - far)
        self.l = 2 * far * near / (near - far)
        self.o = -1
        self.p = 0
        return self