Python math.tan() Examples

The following are 30 code examples for showing how to use math.tan(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module math , or try the search function .

Example 1
Project: PyOptiX   Author: ozen   File: common.py    License: 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 2
Project: rai-python   Author: MarcToussaint   File: transformations.py    License: 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 3
Project: sk1-wx   Author: sk1project   File: transforms.py    License: 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 4
Project: PyETo   Author: woodcrafty   File: fao.py    License: 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
Project: scenario_runner   Author: carla-simulator   File: ros_agent.py    License: MIT License 6 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 6
Project: pyth   Author: isaacg1   File: macros.py    License: 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 7
Project: orbit-predictor   Author: satellogic   File: angles.py    License: 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 8
Project: orbit-predictor   Author: satellogic   File: angles.py    License: 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 9
Project: MITx-6.00.1x   Author: ahmedkareem999   File: polySum.py    License: 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 10
Project: quaternion   Author: moble   File: quaternion_time_series.py    License: 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 11
Project: pyx   Author: pyx-project   File: test_box.py    License: 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 12
Project: pyshgp   Author: erp12   File: numeric.py    License: MIT License 5 votes vote down vote up
def _tan(x):
    return math.tan(x), 
Example 13
Project: suncalcPy   Author: Broham   File: suncalc.py    License: MIT License 5 votes vote down vote up
def rightAscension(l, b): 
	return atan(sin(l) * cos(e) - tan(b) * sin(e), cos(l)) 
Example 14
Project: suncalcPy   Author: Broham   File: suncalc.py    License: MIT License 5 votes vote down vote up
def azimuth(H, phi, dec):  
	return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi)) 
Example 15
Project: suncalcPy   Author: Broham   File: suncalc.py    License: MIT License 5 votes vote down vote up
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"]) 
Example 16
Project: Localization   Author: kamalshadi   File: geometry.py    License: MIT License 5 votes vote down vote up
def to_line(self):
        if (abs(self.a - math.pi / 2) < res) or (abs(self.a + math.pi / 2) < res):
            m = float('inf')
            b = self.c.x
            return line(m, b)
        m = math.tan(self.a)
        return line(m, self.c) 
Example 17
Project: hadrian   Author: modelop   File: dist.py    License: Apache License 2.0 5 votes vote down vote up
def QF(self, p):
        if (p < 0.0) or (p > 1.0):
            raise PFARuntimeException("invalid input", self.errcodeBase + 1, self.name, self.pos)
        elif (p == 1.0):
            return float("inf")
        elif (p == 0.0):
            return float("-inf")
        else:
            return self.loc + self.s*math.tan(math.pi*(p - 0.5))

################### F
# from: http://www.stat.tamu.edu/~jnewton/604/chap3.pdf 
Example 18
Project: hadrian   Author: modelop   File: pfamath.py    License: Apache License 2.0 5 votes vote down vote up
def __call__(self, state, scope, pos, paramTypes, x):
        if math.isinf(x) or math.isnan(x):
            return float("nan")
        else:
            return math.tan(x) 
Example 19
Project: sphere   Author: qedus   File: sphere.py    License: MIT License 5 votes vote down vote up
def st_to_uv(cls, s):
        if cls.PROJECTION == cls.LINEAR_PROJECTION:
            return 2 * s - 1
        elif cls.PROJECTION == cls.TAN_PROJECTION:
            s = math.tan((math.pi / 2.0) * s  - math.pi / 4.0)
            return s + (1.0 / (1 << 53)) * s
        elif cls.PROJECTION == cls.QUADRATIC_PROJECTION:
            if s >= 0.5:
                return (1.0 / 3.0) * (4 * s * s - 1)
            else:
                return (1.0 / 3.0) * (1 - 4 * (1 - s) * (1 - s))
        else:
            raise ValueError('unknown projection type') 
Example 20
Project: sphere   Author: qedus   File: sphere.py    License: MIT License 5 votes vote down vote up
def area(a, b, c):
    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)))))


# Return true if the points A, B, C are strictly counterclockwise.  Return
# false if the points are clockwise or collinear (i.e. if they are all
# contained on some great circle).
#
# Due to numerical errors, situations may arise that are mathematically
# impossible, e.g. ABC may be considered strictly CCW while BCA is not.
# However, the implementation guarantees the following:
#
#   If simple_ccw(a,b,c), then !simple_ccw(c,b,a) for all a,b,c. 
Example 21
Project: exposure   Author: yuanming-hu   File: util.py    License: MIT License 5 votes vote down vote up
def largest_rotated_rect(w, h, angle):
  """
    Given a rectangle of size wxh that has been rotated by 'angle' (in
    radians), computes the width and height of the largest possible
    axis-aligned rectangle within the rotated rectangle.

    Original JS code by 'Andri' and Magnus Hoff from Stack Overflow

    Converted to Python by Aaron Snoswell
    """

  quadrant = int(math.floor(angle / (math.pi / 2))) & 3
  sign_alpha = angle if ((quadrant & 1) == 0) else math.pi - angle
  alpha = (sign_alpha % math.pi + math.pi) % math.pi

  bb_w = w * math.cos(alpha) + h * math.sin(alpha)
  bb_h = w * math.sin(alpha) + h * math.cos(alpha)

  gamma = math.atan2(bb_w, bb_w) if (w < h) else math.atan2(bb_w, bb_w)

  delta = math.pi - alpha - gamma

  length = h if (w < h) else w

  d = length * math.cos(alpha)
  a = d * math.sin(alpha) / math.sin(delta)

  y = a * math.cos(gamma)
  x = y * math.tan(gamma)

  return (bb_w - 2 * x, bb_h - 2 * y) 
Example 22
Project: ingrex_lib   Author: blackgear   File: utils.py    License: MIT License 5 votes vote down vote up
def calc_tile(lng, lat, zoomlevel):
    tilecounts = [1,1,1,40,40,80,80,320,1E3,2E3,2E3,4E3,8E3,16E3,16E3,32E3]
    rlat = radians(lat)
    tilecount = tilecounts[zoomlevel]
    xtile = int((lng + 180.0) / 360.0 * tilecount)
    ytile = int((1.0 - log(tan(rlat) + (1 / cos(rlat))) / pi) / 2.0 * tilecount)
    return xtile, ytile 
Example 23
Project: honeybee   Author: ladybug-tools   File: euclid.py    License: GNU General Public License v3.0 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 
Example 24
Project: honeybee   Author: ladybug-tools   File: view.py    License: GNU General Public License v3.0 5 votes vote down vote up
def get_view_dimension(self, max_x=None, max_y=None):
        """Get dimensions for this view as x, y.

        This method is same as vwrays -d
        """
        max_x = max_x or self.x_resolution
        max_y = max_y or self.y_resolution

        if self.view_type in (1, 4, 5):
            return min(max_x, max_y), min(max_x, max_y)

        vh = self.view_h_size
        vv = self.view_v_size

        if self.view_type == 0:
            hv_ratio = math.tan(math.radians(vh) / 2.0) / \
                math.tan(math.radians(vv) / 2.0)
        else:
            hv_ratio = vh / vv

        # radiance keeps the larges max size and tries to scale the other size
        # to fit the aspect ratio. In case the size doesn't match it reverses
        # the process.
        if max_y <= max_x:
            newx = int(round(hv_ratio * max_y))
            if newx <= max_x:
                return newx, max_y
            else:
                newy = int(round(max_x / hv_ratio))
                return max_x, newy
        else:
            newy = int(round(max_x / hv_ratio))
            if newy <= max_y:
                return max_x, newy
            else:
                newx = int(round(hv_ratio * max_y))
                return newx, max_y 
Example 25
Project: sk1-wx   Author: sk1project   File: patternctrls.py    License: GNU General Public License v3.0 5 votes vote down vote up
def get_trafo(self):
        x0 = self.origin_x.get_point_value()
        y0 = self.origin_y.get_point_value()
        sx = self.scale_x.get_value() / 100.0
        sy = self.scale_y.get_value() / 100.0
        shx = self.shear_x.get_value()
        shy = self.shear_y.get_value()

        if shx + shy > 85:
            if shx == self.transforms[3]:
                shy = 85 - shx
            else:
                shx = 85 - shy

        shx = math.pi * shx / 180.0
        shy = math.pi * shy / 180.0

        angle = math.pi * self.rotate.get_value() / 180.0

        trafo = [sx, 0.0, 0.0, sy, x0, y0]
        if angle:
            trafo2 = [math.cos(angle), math.sin(angle),
                      - math.sin(angle), math.cos(angle), 0.0, 0.0]
            trafo = libgeom.multiply_trafo(trafo, trafo2)
        if shx or shy:
            trafo2 = [1.0, math.tan(shy), math.tan(shx), 1.0, 0.0, 0.0]
            trafo = libgeom.multiply_trafo(trafo, trafo2)

        self.transforms = [sx, sy, shx, shy, angle]
        return trafo, [sx, sy, shx, shy, angle] 
Example 26
Project: laplacian-meshes   Author: bmershon   File: LapGUI.py    License: GNU General Public License v3.0 5 votes vote down vote up
def MouseMotion(self, evt):
        state = wx.GetMouseState()
        x, y = evt.GetPosition()
        [lastX, lastY] = self.MousePos
        self.handleMouseStuff(x, y)
        dX = self.MousePos[0] - lastX
        dY = self.MousePos[1] - lastY
        if evt.Dragging():
            idx = self.laplaceCurrentIdx
            if self.GUIState == STATE_CHOOSELAPLACEVERTICES and (state.CmdDown() or self.pressingC) and self.laplaceCurrentIdx in self.laplacianConstraints:
                #Move up laplacian mesh constraint based on where the user drags
                #the mouse
                t = self.camera.towards
                u = self.camera.up
                r = np.cross(t, u)
                P0 = self.laplacianConstraints[idx]
                #Construct a plane going through the point which is parallel to the
                #viewing plane
                plane = Plane3D(P0, t)
                #Construct a ray through the pixel where the user is clicking
                tanFOV = math.tan(self.camera.yfov/2)
                scaleX = tanFOV*(self.MousePos[0] - self.size.x/2)/(self.size.x/2)
                scaleY = tanFOV*(self.MousePos[1] - self.size.y/2)/(self.size.y/2)
                V = t + scaleX*r + scaleY*u
                ray = Ray3D(self.camera.eye, V)
                self.laplacianConstraints[idx] = ray.intersectPlane(plane)[1]
            else:
                #Translate/rotate shape
                if evt.MiddleIsDown():
                    self.camera.translate(dX, dY)
                elif evt.RightIsDown():
                    self.camera.zoom(-dY)#Want to zoom in as the mouse goes up
                elif evt.LeftIsDown():
                    self.camera.orbitLeftRight(dX)
                    self.camera.orbitUpDown(dY)
        self.Refresh() 
Example 27
Project: laplacian-meshes   Author: bmershon   File: meshView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def MouseMotion(self, evt):
        state = wx.GetMouseState()
        x, y = evt.GetPosition()
        [lastX, lastY] = self.MousePos
        self.handleMouseStuff(x, y)
        dX = self.MousePos[0] - lastX
        dY = self.MousePos[1] - lastY
        if evt.Dragging():
            idx = self.laplaceCurrentIdx
            if self.GUIState == STATE_CHOOSELAPLACEVERTICES and state.ControlDown() and self.laplaceCurrentIdx in self.laplacianConstraints:
                #Move up laplacian mesh constraint based on where the user drags
                #the mouse
                t = self.camera.towards
                u = self.camera.up
                r = np.cross(t, u)
                P0 = self.laplacianConstraints[idx]
                #Construct a plane going through the point which is parallel to the
                #viewing plane
                plane = Plane3D(P0, t)
                #Construct a ray through the pixel where the user is clicking
                tanFOV = math.tan(self.camera.yfov/2)
                scaleX = tanFOV*(self.MousePos[0] - self.size.x/2)/(self.size.x/2)
                scaleY = tanFOV*(self.MousePos[1] - self.size.y/2)/(self.size.y/2)
                V = t + scaleX*r + scaleY*u
                ray = Ray3D(self.camera.eye, V)
                self.laplacianConstraints[idx] = ray.intersectPlane(plane)[1]
            else:
                #Translate/rotate shape
                if evt.MiddleIsDown():
                    self.camera.translate(dX, dY)
                elif evt.RightIsDown():
                    self.camera.zoom(-dY)#Want to zoom in as the mouse goes up
                elif evt.LeftIsDown():
                    self.camera.orbitLeftRight(dX)
                    self.camera.orbitUpDown(dY)
        self.Refresh() 
Example 28
Project: laplacian-meshes   Author: bmershon   File: Cameras3D.py    License: GNU General Public License v3.0 5 votes vote down vote up
def getPerspectiveMatrix(yfov, aspect, near, far):
    f = 1.0/math.tan(yfov/2)
    nf = 1/(near - far)
    mat = np.zeros(16)
    mat[0] = f/aspect
    mat[5] = f
    mat[10] = (far + near)*nf
    mat[11] = -1
    mat[14] = (2*far*near)*nf
    return mat 
Example 29
Project: laplacian-meshes   Author: bmershon   File: Cameras3D.py    License: GNU General Public License v3.0 5 votes vote down vote up
def translate(self, dx, dy):
        length = self.center - self.eye
        length = np.sqrt(np.sum(length**2))*math.tan(self.yfov)
        dx = length*dx / float(self.pixWidth)
        dy = length*dy / float(self.pixHeight)
        r = np.cross(self.towards, self.up)
        self.center = self.center - dx*r - dy*self.up
        self.eye = self.eye - dx*r - dy*self.up
        self.updateVecsFromPolar() 
Example 30
Project: tributary   Author: timkpaine   File: ops.py    License: Apache License 2.0 5 votes vote down vote up
def Tan(self):
    return unary(self, 'tan(' + self._name_no_id() + ')', (lambda x: math.tan(self.value())))