Python math 模块,radians() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用math.radians()

项目:coa_tools    作者:ndee85    | 项目源码 | 文件源码
def get_bone_rotation(self,bone):
        pose_bone = self.armature.pose.bones[bone.name]

        if bone.parent != None:
            local_mat = self.get_bone_transformation(bone.parent).inverted() * self.get_bone_transformation(bone)
        else:
            local_mat = self.get_bone_transformation(bone)    
        bone_euler_rot = local_mat.decompose()[1].to_euler()

        degrees = round(math.degrees(bone_euler_rot.y),2)
        return -math.radians(degrees)
项目:lammps-data-file    作者:kbsezginel    | 项目源码 | 文件源码
def unit_cell_volume(self):
        """
        Calculates unit cell volume of a given MOF object.
        """
        a = self.uc_size[0]
        b = self.uc_size[1]
        c = self.uc_size[2]
        alp = math.radians(self.uc_angle[0])
        bet = math.radians(self.uc_angle[1])
        gam = math.radians(self.uc_angle[2])

        volume = 1 - math.cos(alp)**2 - math.cos(bet)**2 - math.cos(gam)**2
        volume += 2 * math.cos(alp) * math.cos(bet) * math.cos(gam)
        volume = a * b * c * math.sqrt(volume)
        frac_volume = volume / (a * b * c)

        self.ucv = volume
        self.frac_ucv = frac_volume
项目:astrobase    作者:waqasbhatti    | 项目源码 | 文件源码
def angle_wrap(angle,radians=False):
    '''
    Wraps the input angle to 360.0 degrees.

    if radians is True: input is assumed to be in radians, output is also in
    radians

    '''

    if radians:
        wrapped = angle % (2.0*PI)
        if wrapped < 0.0:
            wrapped = 2.0*PI + wrapped

    else:

        wrapped = angle % 360.0
        if wrapped < 0.0:
            wrapped = 360.0 + wrapped

    return wrapped
项目:s2sphere    作者:sidewalklabs    | 项目源码 | 文件源码
def get_min_level(self, value):
        """Minimum cell level for given value.

        Return the minimum level such that the metric is at most the given
        value, or ``s2sphere.CellId.MAX_LEVEL`` if there is no such level.
        For example, ``s2sphere.MAX_DIAG.get_min_level(0.1)`` returns the
        minimum level such that all cell diagonal lengths are 0.1 or smaller.
        The return value is always a valid level.

        :param value:
            Depending on whether this is used in one or two dimensions, this is
            an angle in radians or a solid angle in steradians.
        """
        if value <= 0:
            return CellId.MAX_LEVEL

        m, x = math.frexp(value / self.deriv())
        level = max(0, min(CellId.MAX_LEVEL, -((x - 1) >> (self.__dim - 1))))
        assert level == CellId.MAX_LEVEL or self.get_value(level) <= value
        assert level == 0 or self.get_value(level - 1) > value
        return level
项目:s2sphere    作者:sidewalklabs    | 项目源码 | 文件源码
def get_max_level(self, value):
        """Maximum cell level for given value.

        Return the maximum level such that the metric is at least the given
        value, or zero if there is no such level.  For example,
        ``s2sphere.MIN_WIDTH.get_max_level(0.1)`` returns the maximum level
        such that all cells have a minimum width of 0.1 or larger.
        The return value is always a valid level.

        :param value:
            Depending on whether this is used in one or two dimensions, this is
            an angle in radians or a solid angle in steradians.
        """
        if value <= 0:
            return CellId.MAX_LEVEL

        m, x = math.frexp(self.deriv() / value)
        level = max(0, min(CellId.MAX_LEVEL, (x - 1) >> (self.__dim - 1)))
        assert level == 0 or self.get_value(level) >= value
        assert level == CellId.MAX_LEVEL or self.get_value(level + 1) < value
        return level
项目:s2sphere    作者:sidewalklabs    | 项目源码 | 文件源码
def __get_initial_candidates(self):
        if self.__max_cells >= 4:
            cap = self.__region.get_cap_bound()
            level = min(CellId.min_width().get_max_level(
                        2 * cap.angle().radians),
                        min(self.__max_level, CellId.MAX_LEVEL - 1))

            if self.__level_mod > 1 and level > self.__min_level:
                level -= (level - self.__min_level) % self.__level_mod

            if level > 0:
                cell_id = CellId.from_point(cap.axis())
                vertex_neighbors = cell_id.get_vertex_neighbors(level)
                for neighbor in vertex_neighbors:
                    self.__add_candidate(self.__new_candidate(Cell(neighbor)))
                return

        for face in range(6):
            self.__add_candidate(self.__new_candidate(FACE_CELLS[face]))
项目:mav_rtk_gps    作者:ethz-asl    | 项目源码 | 文件源码
def __init__(self):

        if rospy.has_param('~orientation_offset'):
            # Orientation offset as quaterion q = [x,y,z,w].
            self.orientation_offset = rospy.get_param('~orientation_offset')
        else:
            yaw_offset_deg = rospy.get_param('~yaw_offset_deg', 0.0)
            self.orientation_offset = tf.quaternion_from_euler(0.0, 0.0, math.radians(yaw_offset_deg))

        rospy.Subscriber(rospy.get_name() + "/imu_in", Imu, self.imu_callback)

        self.pub_imu_out = rospy.Publisher(rospy.get_name() + '/imu_out',
                                           Imu, queue_size=10)

        rospy.spin()
项目:mav_rtk_gps    作者:ethz-asl    | 项目源码 | 文件源码
def mitsuta_mean(self, angles_array):
        # Function meant to work with degrees, covert inputs
        # from radians to degrees and output from degrees to radians
        D = math.degrees(angles_array[0])
        mysum = D
        for val in angles_array[1:]:
            val = math.degrees(val)
            delta = val - D
            if delta < -180.0:
                D = D + delta + 360.0
            elif delta < 180.0:
                D = D + delta
            else:
                D = D + delta - 360.0
            mysum = mysum + D
        m = mysum / len(angles_array)

        avg = math.radians((m + 360.0) % 360.0)
        # make sure avg is between -pi and pi
        if avg > math.pi:
            avg = avg - 2.0 * math.pi
        elif avg < -math.pi:
            avg = avg + 2.0 * math.pi

        return avg
项目:pyrsss    作者:butala    | 项目源码 | 文件源码
def iaga2df(iaga2002_fname, D_to_radians=True):
    """
    Parser the magnetometer data record stored in the IAGA-2002 format
    file *iaga2002_fname*. If *D_to_radians*, declination data (D) are
    converted from degrees to radians. Return the tuple with the
    :class:`DataFrame` containing the data and header information
    """
    with open(iaga2002_fname) as fid:
        # parse header
        header, cols = parse_header(fid)
        keys = ['B_' + x for x in cols]
        # parse data
        index = []
        data_map = defaultdict(list)
        for line in fid:
            toks = line.split()
            dt = datetime.strptime(toks[0] + ' ' + toks[1], '%Y-%m-%d %H:%M:%S.%f')
            index.append(dt)
            data = map(convert_float, toks[3:])
            for key_i, data_i in zip(keys, data):
                if key_i == 'B_D' and D_to_radians:
                    data_i = math.radians(data_i)
                data_map[key_i].append(data_i)
    df = PD.DataFrame(index=index, data=data_map)
    return df, header
项目:PokeAlarm    作者:PokeAlarm    | 项目源码 | 文件源码
def get_earth_dist(pt_a, pt_b=None):
    if type(pt_a) is str or pt_b is None:
        return 'unkn'  # No location set
    log.debug("Calculating distance from {} to {}".format(pt_a, pt_b))
    lat_a = radians(pt_a[0])
    lng_a = radians(pt_a[1])
    lat_b = radians(pt_b[0])
    lng_b = radians(pt_b[1])
    lat_delta = lat_b - lat_a
    lng_delta = lng_b - lng_a
    a = sin(lat_delta / 2) ** 2 + cos(lat_a) * cos(lat_b) * sin(lng_delta / 2) ** 2
    c = 2 * atan2(sqrt(a), sqrt(1 - a))
    radius = 6373000  # radius of earth in meters
    if config['UNITS'] == 'imperial':
        radius = 6975175  # radius of earth in yards
    dist = c * radius
    return dist


# Return the time as a string in different formats
项目:coralillo    作者:getfleety    | 项目源码 | 文件源码
def distance(self, loc):
        """
        Calculate the great circle distance between two points
        on the earth (specified in decimal degrees)
        """
        assert type(loc) == type(self)

        # convert decimal degrees to radians
        lon1, lat1, lon2, lat2 = map(radians, [
            self.lon,
            self.lat,
            loc.lon,
            loc.lat,
        ])

        # haversine formula
        dlon = lon2 - lon1
        dlat = lat2 - lat1
        a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
        c = 2 * asin(sqrt(a))
        r = 6371000 # Radius of earth in meters.
        return c * r
项目:AboveTustin    作者:kevinabrandon    | 项目源码 | 文件源码
def distance(pointA, pointB):
    """
    Calculate the great circle distance between two points 
    on the earth (specified in decimal degrees)

    http://stackoverflow.com/questions/15736995/how-can-i-quickly-estimate-the-distance-between-two-latitude-longitude-points
    """
    # convert decimal degrees to radians 
    lon1, lat1, lon2, lat2 = map(math.radians, [pointA[1], pointA[0], pointB[1], pointB[0]])

    # haversine formula 
    dlon = lon2 - lon1 
    dlat = lat2 - lat1 
    a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
    c = 2 * math.asin(math.sqrt(a)) 
    r = 3956  # Radius of earth in miles. Use 6371 for kilometers
    return c * r
项目:llk    作者:Tycx2ry    | 项目源码 | 文件源码
def mergeRotatedScaledPage(self, page2, rotation, scale):
        rotation = math.radians(rotation)
        rotating = [[math.cos(rotation), math.sin(rotation),0],
                    [-math.sin(rotation),math.cos(rotation), 0],
                    [0,                  0,                  1]]
        scaling = [[scale,0,    0],
                   [0,    scale,0],
                   [0,    0,    1]]
        ctm = utils.matrixMultiply(rotating, scaling)

        return self.mergeTransformedPage(page2,
                                         [ctm[0][0], ctm[0][1],
                                          ctm[1][0], ctm[1][1],
                                          ctm[2][0], ctm[2][1]])

    ##
    # This is similar to mergePage, but the stream to be merged is translated
    # and scaled by appling a transformation matrix.
    #
    # @param page2 An instance of {@link #PageObject PageObject} to be merged.
    # @param scale The scaling factor
    # @param tx    The translation on X axis
    # @param tx    The translation on Y axis
项目:llk    作者:Tycx2ry    | 项目源码 | 文件源码
def mergeRotatedScaledTranslatedPage(self, page2, rotation, scale, tx, ty):
        translation = [[1, 0, 0],
                       [0, 1, 0],
                       [tx,ty,1]]
        rotation = math.radians(rotation)
        rotating = [[math.cos(rotation), math.sin(rotation),0],
                    [-math.sin(rotation),math.cos(rotation), 0],
                    [0,                  0,                  1]]
        scaling = [[scale,0,    0],
                   [0,    scale,0],
                   [0,    0,    1]]
        ctm = utils.matrixMultiply(rotating, scaling)
        ctm = utils.matrixMultiply(ctm, translation)

        return self.mergeTransformedPage(page2, [ctm[0][0], ctm[0][1],
                                                 ctm[1][0], ctm[1][1],
                                                 ctm[2][0], ctm[2][1]])

    ##
    # Applys a transformation matrix the page.
    #
    # @param ctm   A 6 elements tuple containing the operands of the
    #              transformation matrix
项目:python-miio    作者:rytilahti    | 项目源码 | 文件源码
def manual_control(self, rotation: int, velocity: float,
                       duration: int=1500):
        """Give a command over manual control interface."""
        if rotation < -180 or rotation > 180:
            raise DeviceException("Given rotation is invalid, should "
                                  "be ]-180, 180[, was %s" % rotation)
        if velocity < -0.3 or velocity > 0.3:
            raise DeviceException("Given velocity is invalid, should "
                                  "be ]-0.3, 0.3[, was: %s" % velocity)

        self.manual_seqnum += 1
        params = {"omega": round(math.radians(rotation), 1),
                  "velocity": velocity,
                  "duration": duration,
                  "seqnum": self.manual_seqnum}

        self.send("app_rc_move", [params])
项目:Sverchok    作者:Sverchok    | 项目源码 | 文件源码
def rotation_matrix(theta, axis):
    """
    Return the rotation matrix associated with counterclockwise rotation about
    the given axis by theta radians.
    Adapted from
    http://stackoverflow.com/questions/6802577/python-rotation-of-3d-vector
    """
    axis = axis[:3]
    axis = axis/math.sqrt(np.dot(axis, axis))
    a = math.cos(theta/2.0)
    b, c, d = -axis*math.sin(theta/2.0)
    aa, bb, cc, dd = a*a, b*b, c*c, d*d
    bc, ad, ac, ab, bd, cd = b*c, a*d, a*c, a*b, b*d, c*d
    return np.array([[aa+bb-cc-dd, 2*(bc+ad), 2*(bd-ac), 0],
                     [2*(bc-ad), aa+cc-bb-dd, 2*(cd+ab), 0],
                     [2*(bd+ac), 2*(cd-ab), aa+dd-bb-cc, 0],
                     [0,         0,         0,           1]])
项目:osm2gtfs    作者:grote    | 项目源码 | 文件源码
def get_center_of_nodes(nodes):
        """Helper function to get center coordinates of a group of nodes

        """
        x = 0
        y = 0
        z = 0

        for node in nodes:
            lat = radians(float(node.lat))
            lon = radians(float(node.lon))

            x += cos(lat) * cos(lon)
            y += cos(lat) * sin(lon)
            z += sin(lat)

        x = float(x / len(nodes))
        y = float(y / len(nodes))
        z = float(z / len(nodes))

        center_lat = degrees(atan2(z, sqrt(x * x + y * y)))
        center_lon = degrees(atan2(y, x))

        return center_lat, center_lon
项目:osm2gtfs    作者:grote    | 项目源码 | 文件源码
def get_crow_fly_distance(from_tuple, to_tuple):
    """
    Uses the Haversine formmula to compute distance
    (https://en.wikipedia.org/wiki/Haversine_formula#The_haversine_formula)
    """
    lat1, lon1 = from_tuple
    lat2, lon2 = to_tuple

    lat1 = float(lat1)
    lat2 = float(lat2)
    lon1 = float(lon1)
    lon2 = float(lon2)

    radius = 6371  # km

    dlat = math.radians(lat2 - lat1)
    dlon = math.radians(lon2 - lon1)
    a = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.radians(lat1)) * \
        math.cos(math.radians(lat2)) * math.sin(dlon / 2) * math.sin(dlon / 2)
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    d = radius * c

    return d * 1000  # meters
项目:spiderfoot    作者:wi-fi-analyzer    | 项目源码 | 文件源码
def mergeRotatedPage(self, page2, rotation, expand=False):
        """
        This is similar to mergePage, but the stream to be merged is rotated
        by appling a transformation matrix.

        :param PageObject page2: the page to be merged into this one. Should be
            an instance of :class:`PageObject<PageObject>`.
        :param float rotation: The angle of the rotation, in degrees
        :param bool expand: Whether the page should be expanded to fit the
            dimensions of the page to be merged.
        """
        rotation = math.radians(rotation)
        return self.mergeTransformedPage(page2,
            [math.cos(rotation),  math.sin(rotation),
             -math.sin(rotation), math.cos(rotation),
             0,                   0], expand)
项目:spiderfoot    作者:wi-fi-analyzer    | 项目源码 | 文件源码
def mergeRotatedScaledPage(self, page2, rotation, scale, expand=False):
        """
        This is similar to mergePage, but the stream to be merged is rotated
        and scaled by appling a transformation matrix.

        :param PageObject page2: the page to be merged into this one. Should be
            an instance of :class:`PageObject<PageObject>`.
        :param float rotation: The angle of the rotation, in degrees
        :param float scale: The scaling factor
        :param bool expand: Whether the page should be expanded to fit the
            dimensions of the page to be merged.
        """
        rotation = math.radians(rotation)
        rotating = [[math.cos(rotation), math.sin(rotation), 0],
                    [-math.sin(rotation), math.cos(rotation), 0],
                    [0,                  0,                  1]]
        scaling = [[scale, 0,    0],
                   [0,    scale, 0],
                   [0,    0,    1]]
        ctm = utils.matrixMultiply(rotating, scaling)

        return self.mergeTransformedPage(page2,
                                         [ctm[0][0], ctm[0][1],
                                          ctm[1][0], ctm[1][1],
                                          ctm[2][0], ctm[2][1]], expand)
项目:mauzr    作者:eqrx    | 项目源码 | 文件源码
def create_ring_coordinates(radius, count):
    """ Create coordinates arranged in a ring.

    :param radius: Radius of the ring.
    :type radius: float
    :param count: Count of coordinates to generate.
    :type count: int
    :returns: Tuple of the coordinates.
    :rtype: tuple
    """

    pixelstep = math.radians(360/count)
    pixels = []
    for index in range(0, count):
        pixels.append((radius * math.cos(index*pixelstep),
                       radius * math.sin(index*pixelstep)))
    return pixels
项目:PokemonGo-SlackBot    作者:rubenmak    | 项目源码 | 文件源码
def bearing_degrees(lat1, lon1, lat2, lon2):
    """
    Convert location in bearing degrees to be able to give a direction of where the Pokemon is located.
    :param lat1: user location latitude
    :param lon1: user location longitude
    :param lat2: pokemon location latitude
    :param lon2: pokemon location longitude
    :return: bearing degrees
    """

    # convert decimal degrees to radians
    lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
    # calculate the angle
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    x = math.sin(dlon) * math.cos(lat2)
    y = math.cos(lat1) * math.sin(lat2) - (math.sin(lat1) * math.cos(lat2) * math.cos(dlon))
    initial_bearing = math.atan2(x, y)
    initial_bearing = math.degrees(initial_bearing)
    bearing = (initial_bearing + 360) % 360
    bearing = int(bearing)
    return bearing
项目:PokemonGo-SlackBot    作者:rubenmak    | 项目源码 | 文件源码
def bearing_degrees(lat1, lon1, lat2, lon2):
    """
    Convert location in bearing degrees to be able to give a direction of where the Pokemon is located.
    :param lat1: user location latitude
    :param lon1: user location longitude
    :param lat2: pokemon location latitude
    :param lon2: pokemon location longitude
    :return: bearing degrees
    """

    # convert decimal degrees to radians
    lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
    # calculate the angle
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    x = math.sin(dlon) * math.cos(lat2)
    y = math.cos(lat1) * math.sin(lat2) - (math.sin(lat1) * math.cos(lat2) * math.cos(dlon))
    initial_bearing = math.atan2(x, y)
    initial_bearing = math.degrees(initial_bearing)
    bearing = (initial_bearing + 360) % 360
    bearing = int(bearing)
    return bearing
项目:bpy_lambda    作者:bcongdon    | 项目源码 | 文件源码
def cube_map_render_pre(scene, use_force=False):

    if not do_run(scene.cube_map, use_force):
        return

    from math import radians

    camera = scene.camera
    data = camera.data.copy()

    data.lens_unit = 'FOV'
    data.angle = radians(90)
    data.type = 'PERSP'

    mat = camera.matrix_world

    loc = mat.to_translation()
    rot = mat.to_euler()
    zed = rot.z

    views = bpy.cube_map_views

    for view in views:
        view.setCamera(data, loc, zed)
项目:bpy_lambda    作者:bcongdon    | 项目源码 | 文件源码
def ang_match3D(pt1, pt2, pt3, exp_ang):
    ang_meas = get_line_ang_3D(pt1, pt2, pt3)
    '''
    print("pt1", pt1)  # debug
    print("pt2", pt2)  # debug
    print("pt3", pt3)  # debug
    print("exp_ang ", exp_ang)  # debug
    print("ang_meas ", ang_meas)  # debug
    '''
    return flts_alm_eq(ang_meas, exp_ang)


# Calculates rotation around axis or face normal at Pivot's location.
# Takes two 3D coordinate Vectors (piv_co and mov_co), rotation angle in
# radians (ang_diff_rad), and rotation data storage object (rot_dat).
# Aligns mov_co to world origin (0, 0, 0) and rotates aligned
# mov_co (mov_aligned) around axis stored in rot_dat. After rotation,
# removes world-origin alignment.
项目:bpy_lambda    作者:bcongdon    | 项目源码 | 文件源码
def prep_rotation_info(ref_pts, r_dat, curr_ms_stor, new_ms_stor):
    #print("curr angle", curr_ms_stor)  # debug
    #print("new angle", new_ms_stor)  # debug

    # workaround for negative angles and angles over 360 degrees
    if new_ms_stor < 0 or new_ms_stor > 360:
        new_ms_stor = new_ms_stor % 360
    r_dat.ang_diff_d = new_ms_stor - curr_ms_stor
    # fix for angles over 180 degrees
    if new_ms_stor > 180:
        r_dat.new_ang_r = radians(180 - (new_ms_stor % 180))
    else:
        r_dat.new_ang_r = radians(new_ms_stor)
    r_dat.ang_diff_r = radians(r_dat.ang_diff_d)
    r_dat.axis_lk = ref_pts.ax_lock


# Takes: ed_type (Editor Type), new_free_co (Vector), ref_pts (ReferencePoints),
# and rDat (RotationData) as args. Uses new_free_co to calculate the rotation
# value and then rotates the selected objects or selected vertices using
# the obtained value.
项目:bpy_lambda    作者:bcongdon    | 项目源码 | 文件源码
def execute(self, context):
        try:
            GSP = context.lamp.GeoSunProperties

            dst = 1 if GSP.dst else 0

            az,el = sun_calculator.geoSunData(
                GSP.lat,
                GSP.long,
                GSP.year,
                GSP.month,
                GSP.day,
                GSP.hour + GSP.minute/60.0,
                -GSP.tz + dst
            )

            context.object.rotation_euler = ( math.radians(90-el), 0, math.radians(-az) )
            return {'FINISHED'}
        except Exception as err:
            self.report({'ERROR'}, str(err))
            return {'CANCELLED'}
项目:bpy_lambda    作者:bcongdon    | 项目源码 | 文件源码
def text(self, en, scene, name):
        """
        en: dxf entity
        name: ignored; exists to make separate and merged objects methods universally callable from _call_types()
        Returns a new single line text object.
        """
        if self.import_text:
            name = en.text[:8]
            d = bpy.data.curves.new(name, "FONT")
            d.body = en.plain_text()
            d.size = en.height
            o = bpy.data.objects.new(name, d)
            o.rotation_euler = Euler((0, 0, radians(en.rotation)), 'XYZ')
            basepoint = self.proj(en.basepoint) if hasattr(en, "basepoint") else self.proj((0, 0, 0))
            o.location = self.proj((en.insert)) + basepoint
            if hasattr(en, "thickness"):
                et = en.thickness / 2
                d.extrude = abs(et)
                if et > 0:
                    o.location.z += et
                elif et < 0:
                    o.location.z -= et
            return o
项目:bpy_lambda    作者:bcongdon    | 项目源码 | 文件源码
def create_bezier(objname, points, origin):
    curvedata = bpy.data.curves.new(name=objname, type='CURVE')
    curvedata.dimensions = '3D'

    myobject = bpy.data.objects.new(objname, curvedata)
    myobject.location = origin
    myobject.rotation_euler[2] = radians(90)

    bpy.context.scene.objects.link(myobject)

    polyline = curvedata.splines.new('BEZIER')
    polyline.bezier_points.add(len(points) - 1)

    for idx, (knot, h1, h2) in enumerate(points):
        point = polyline.bezier_points[idx]
        point.co = knot
        point.handle_left = h1
        point.handle_right = h2
        point.handle_left_type = 'FREE'
        point.handle_right_type = 'FREE'

    return myobject
项目:bpy_lambda    作者:bcongdon    | 项目源码 | 文件源码
def rotate_fix_armature(arm_data):
    global_matrix = Matrix.Rotation(radians(90), 4, "X")
    bpy.ops.object.mode_set(mode='EDIT', toggle=False)
    #disconnect all bones for ease of global rotation
    connectedBones = []
    for bone in arm_data.edit_bones:
        if bone.use_connect:
            connectedBones.append(bone.name)
            bone.use_connect = False

    #rotate all the bones around their center
    for bone in arm_data.edit_bones:
        bone.transform(global_matrix)

    #reconnect the bones
    for bone in connectedBones:
        arm_data.edit_bones[bone].use_connect = True
    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)


#Roughly scales the performer armature to match the enduser armature
#IN: perfromer_obj, enduser_obj, Blender objects whose .data is an armature.
项目:bpy_lambda    作者:bcongdon    | 项目源码 | 文件源码
def get_render_location(mypoint):

    v1 = Vector(mypoint)
    scene = bpy.context.scene
    co_2d = object_utils.world_to_camera_view(scene, scene.camera, v1)
    # Get pixel coords
    render_scale = scene.render.resolution_percentage / 100
    render_size = (int(scene.render.resolution_x * render_scale),
                   int(scene.render.resolution_y * render_scale))

    return [round(co_2d.x * render_size[0]), round(co_2d.y * render_size[1])]


# ---------------------------------------------------------
# Get center of circle base on 3 points
#
# Point a: (x,y,z) arc start
# Point b: (x,y,z) center
# Point c: (x,y,z) midle point in the arc
# Point d: (x,y,z) arc end
# Return:
# ang: angle (radians)
# len: len of arc
#
# ---------------------------------------------------------
项目:PcbDraw    作者:yaqwsx    | 项目源码 | 文件源码
def walk_components(board, export):
    module = board.GetModules()
    while True:
        if not module:
            return
        # Top is for Eagle boards imported to KiCAD
        if str(module.GetLayerName()) not in ["Top", "F.Cu"]:
            module = module.Next()
            continue
        lib = str(module.GetFPID().GetLibNickname()).strip()
        try:
            name = str(module.GetFPID().GetFootprintName()).strip()
        except AttributeError:
            # it seems we are working on Kicad >4.0.6, which has a changed method name
            name = str(module.GetFPID().GetLibItemName()).strip()
        value = unicode(module.GetValue()).strip()
        ref = unicode(module.GetReference()).strip()
        center = module.GetCenter()
        orient = math.radians(module.GetOrientation() / 10)
        pos = (center.x, center.y, orient)
        export(lib, name, value, ref, pos)
        module = module.Next()
项目:py-noisemaker    作者:aayars    | 项目源码 | 文件源码
def spiral(freq=1.0, center_x=0.0, center_y=0.0, range_x=1.0, range_y=1.0, width=1.0, height=1.0, **kwargs):
    """
    """

    kink = random.random() * 5.0 - 2.5

    x = []
    y = []

    count = freq * freq

    for i in range(count):
        fract = i / count

        degrees = fract * 360.0 * math.radians(1) * kink

        x.append((center_x + math.sin(degrees) * fract * range_x) % width)
        y.append((center_y + math.cos(degrees) * fract * range_y) % height)

    return x, y
项目:BiblioPixel2    作者:ManiacalLabs    | 项目源码 | 文件源码
def pointOnCircle(cx, cy, radius, angle):
    """Calculates the coordinates of a point on a circle given the center point, radius, and angle"""
    angle = math.radians(angle) - (math.pi / 2)
    x = cx + radius * math.cos(angle)
    if x < cx:
        x = math.ceil(x)
    else:
        x = math.floor(x)

    y = cy + radius * math.sin(angle)

    if y < cy:
        y = math.ceil(y)
    else:
        y = math.floor(y)

    return (int(x), int(y))
项目:coa_tools    作者:ndee85    | 项目源码 | 文件源码
def get_sprite_rotation(self,sprite_name):
        obj = bpy.data.objects[sprite_name]
        euler_rot = obj.matrix_basis.to_euler()
        degrees = math.degrees(euler_rot[1])
        return -math.radians(degrees)

    ### convert windows slashes to linux slashes
项目:coa_tools    作者:ndee85    | 项目源码 | 文件源码
def execute(self, context):
        sprite_object = None    
        if context.active_object != None:
            sprite_object = get_sprite_object(context.active_object)

        scene = context.scene
        if self.create:
            context.scene.objects.active = None
            bpy.ops.object.camera_add(view_align=True, enter_editmode=False, location=(0, -self.resolution[0] * get_addon_prefs(context).sprite_import_export_scale, 0), rotation=(radians(90), 0, 0))
        cam = context.active_object
        context.scene.objects.active = cam
        cam.data.type = "ORTHO"
        scene.render.pixel_filter_type = "BOX"
        scene.render.alpha_mode = "TRANSPARENT"

        if sprite_object != None:
            cam.parent = sprite_object

        if self.set_resolution:
            ortho_scale = max(self.resolution[0],self.resolution[1])
            cam.data.ortho_scale = ortho_scale/100

            scene.render.resolution_x = self.resolution[0]
            scene.render.resolution_y = self.resolution[1]
            cam.location[1] = -self.resolution[0] * get_addon_prefs(context).sprite_import_export_scale
            scene.render.resolution_percentage = 100
        scene.camera = cam
        if bpy.context.space_data.region_3d.view_perspective != "CAMERA":
            bpy.ops.view3d.viewnumpad(type="CAMERA")
        return{"FINISHED"}
项目:tree-gen    作者:friggog    | 项目源码 | 文件源码
def turn_right(self, angle):
        """Turn the turtle right about the axis perpendicular to the direction
        it is facing"""
        axis = (self.dir.cross(self.right))
        axis.normalize()
        self.dir.rotate(Quaternion(axis, math.radians(angle)))
        self.dir.normalize()
        self.right.rotate(Quaternion(axis, math.radians(angle)))
        self.right.normalize()
项目:tree-gen    作者:friggog    | 项目源码 | 文件源码
def pitch_up(self, angle):
        """Pitch the turtle up about the right axis"""
        self.dir.rotate(Quaternion(self.right, math.radians(angle)))
        self.dir.normalize()
项目:tree-gen    作者:friggog    | 项目源码 | 文件源码
def roll_right(self, angle):
        """Roll the turtle right about the direction it is facing"""
        self.right.rotate(Quaternion(self.dir, math.radians(angle)))
        self.right.normalize()
项目:tree-gen    作者:friggog    | 项目源码 | 文件源码
def calc_helix_points(turtle, rad, pitch):
    """ calculates required points to produce helix bezier curve with given radius and pitch in direction of turtle"""
    # alpha = radians(90)
    # pit = pitch/(2*pi)
    # a_x = rad*cos(alpha)
    # a_y = rad*sin(alpha)
    # a = pit*alpha*(rad - a_x)*(3*rad - a_x)/(a_y*(4*rad - a_x)*tan(alpha))
    # b_0 = Vector([a_x, -a_y, -alpha*pit])
    # b_1 = Vector([(4*rad - a_x)/3, -(rad - a_x)*(3*rad - a_x)/(3*a_y), -a])
    # b_2 = Vector([(4*rad - a_x)/3, (rad - a_x)*(3*rad - a_x)/(3*a_y), a])
    # b_3 = Vector([a_x, a_y, alpha*pit])
    # axis = Vector([0, 0, 1])

    # simplifies greatly for case inc_angle = 90
    points = [Vector([0, -rad, -pitch / 4]),
              Vector([(4 * rad) / 3, -rad, 0]),
              Vector([(4 * rad) / 3, rad, 0]),
              Vector([0, rad, pitch / 4])]

    # align helix points to turtle direction and randomize rotation around axis
    trf = turtle.dir.to_track_quat('Z', 'Y')
    spin_ang = rand_in_range(0, 2 * pi)
    for p in points:
        p.rotate(Quaternion(Vector([0, 0, 1]), spin_ang))
        p.rotate(trf)

    return points[1] - points[0], points[2] - points[0], points[3] - points[0], turtle.dir.copy()
项目:tree-gen    作者:friggog    | 项目源码 | 文件源码
def apply_tropism(turtle, tropism_vector):
    """Apply tropism_vector to turtle direction"""
    h_cross_t = turtle.dir.cross(tropism_vector)
    # calc angle to rotate by (from ABoP) multiply to achieve accurate results from WP attractionUp param
    alpha = 10 * h_cross_t.magnitude
    h_cross_t.normalize()
    # rotate by angle about axis perpendicular to turtle direction and tropism vector
    turtle.dir.rotate(Quaternion(h_cross_t, radians(alpha)))
    turtle.dir.normalize()
    turtle.right.rotate(Quaternion(h_cross_t, radians(alpha)))
    turtle.right.normalize()
项目:lammps-data-file    作者:kbsezginel    | 项目源码 | 文件源码
def calculate_cut_off(self):
        """
        Calculate cut-off radius as Rc = L/2 from a given MOF object.
        """
        width_a = self.ucv / (self.uc_size[1] * self.uc_size[2] / math.sin(math.radians(self.uc_angle[0])))
        width_b = self.ucv / (self.uc_size[0] * self.uc_size[2] / math.sin(math.radians(self.uc_angle[1])))
        width_c = self.ucv / (self.uc_size[0] * self.uc_size[1] / math.sin(math.radians(self.uc_angle[2])))
        self.cut_off = min(width_a / 2, width_b / 2, width_c / 2)
项目:lammps-data-file    作者:kbsezginel    | 项目源码 | 文件源码
def pbc_parameters(self):
        """
        Calculates constants used in periodic boundary conditions.
        """
        uc_cos = [math.cos(math.radians(a)) for a in self.uc_angle]
        uc_sin = [math.sin(math.radians(a)) for a in self.uc_angle]
        a, b, c = self.uc_size
        v = self.frac_ucv

        xf1 = 1 / a
        xf2 = - uc_cos[2] / (a * uc_sin[2])
        xf3 = (uc_cos[0] * uc_cos[2] - uc_cos[1]) / (a * v * uc_sin[2])
        yf1 = 1 / (b * uc_sin[2])
        yf2 = (uc_cos[1] * uc_cos[2] - uc_cos[0]) / (b * v * uc_sin[2])
        zf1 = uc_sin[2] / (c * v)
        self.to_frac = [xf1, xf2, xf3, yf1, yf2, zf1]

        xc1 = a
        xc2 = b * uc_cos[2]
        xc3 = c * uc_cos[1]
        yc1 = b * uc_sin[2]
        yc2 = c * (uc_cos[0] - uc_cos[1] * uc_cos[2]) / uc_sin[2]
        zc1 = c * v / uc_sin[2]
        self.to_car = [xc1, xc2, xc3, yc1, yc2, zc1]
项目:lammps-data-file    作者:kbsezginel    | 项目源码 | 文件源码
def uc_vectors(cls, uc_size, uc_angle):
        """
        Calculate unit cell vectors for given unit cell size and angles
        """
        a = uc_size[0]
        b = uc_size[1]
        c = uc_size[2]
        alpha = math.radians(uc_angle[0])
        beta = math.radians(uc_angle[1])
        gamma = math.radians(uc_angle[2])

        x_v = [a, 0, 0]
        y_v = [b * math.cos(gamma), b * math.sin(gamma), 0]
        z_v = [0.0] * 3
        z_v[0] = c * math.cos(beta)
        z_v[1] = (c * b * math.cos(alpha) - y_v[0] * z_v[0]) / y_v[1]
        z_v[2] = math.sqrt(c * c - z_v[0] * z_v[0] - z_v[1] * z_v[1])
        uc_vectors = [x_v, y_v, z_v]
        return uc_vectors
项目:PGO-mapscan-opt    作者:seikur0    | 项目源码 | 文件源码
def get_distance(location1, location2):
    lat1, lng1 = location1
    lat2, lng2 = location2

    lat1, lng1, lat2, lng2 = map(radians, (lat1, lng1, lat2, lng2))

    d = sin(0.5*(lat2 - lat1)) ** 2 + cos(lat1) * cos(lat2) * sin(0.5*(lng2 - lng1)) ** 2
    return 2 * earth_Rrect * asin(sqrt(d))
项目:sappho    作者:lily-mayfield    | 项目源码 | 文件源码
def radial(cls, r, theta):
        """Provide a radial acceleration.

         Arguments:
             r (float): speed in pixels per second (per second)
             theta (float): angle in degrees (0 = +X axis, 90 = +Y axis)
         """
        radians = math.radians(theta)
        ax = r * math.cos(radians)
        ay = r * math.sin(radians)
        return cls(ax=ax, ay=ay)
项目:j3dview    作者:blank63    | 项目源码 | 文件源码
def create_matrix(self,parent_joint,parent_joint_matrix):
        # The calculation of the local matrix is an optimized version of
        # local_matrix = T*IPS*R*S if ignore_parent_scale else T*R*S
        # where S, R and T is the scale, rotation and translation matrix
        # respectively and IPS is the inverse parent scale matrix.

        cx = cos(radians(self.rotation_x))
        sx = sin(radians(self.rotation_x))
        cy = cos(radians(self.rotation_y))
        sy = sin(radians(self.rotation_y))
        cz = cos(radians(self.rotation_z))
        sz = sin(radians(self.rotation_z))

        if self.ignore_parent_scale:
            ips_x = 1/parent_joint.scale_x
            ips_y = 1/parent_joint.scale_y
            ips_z = 1/parent_joint.scale_z
        else:
            ips_x = 1
            ips_y = 1
            ips_z = 1

        local_matrix = numpy.empty((3,4),numpy.float32)
        local_matrix[0,0] = cy*cz*self.scale_x*ips_x
        local_matrix[1,0] = cy*sz*self.scale_x*ips_y
        local_matrix[2,0] = -sy*self.scale_x*ips_z
        local_matrix[0,1] = (sx*sy*cz - cx*sz)*self.scale_y*ips_x
        local_matrix[1,1] = (sx*sy*sz + cx*cz)*self.scale_y*ips_y
        local_matrix[2,1] = sx*cy*self.scale_y*ips_z
        local_matrix[0,2] = (cx*sy*cz + sx*sz)*self.scale_z*ips_x
        local_matrix[1,2] = (cx*sy*sz - sx*cz)*self.scale_z*ips_y
        local_matrix[2,2] = cx*cy*self.scale_z*ips_z
        local_matrix[0,3] = self.translation_x
        local_matrix[1,3] = self.translation_y
        local_matrix[2,3] = self.translation_z

        return matrix3x4_multiply(parent_joint_matrix,local_matrix)
项目:j3dview    作者:blank63    | 项目源码 | 文件源码
def create_matrix(self):
        c = cos(radians(self.rotation))
        s = sin(radians(self.rotation))
        R = numpy.matrix([[c,-s,0],[s,c,0],[0,0,1]])
        S = numpy.matrix([[self.scale_s,0,0],[0,self.scale_t,0],[0,0,1]])
        C = numpy.matrix([[1,0,self.center_s],[0,1,self.center_t],[0,0,1]])
        T = numpy.matrix([[1,0,self.translation_s],[0,1,self.translation_t],[0,0,1]])

        # Only types 0x00, 0x06, 0x07, 0x08 and 0x09 have been tested
        if self.matrix_type in {0x00,0x02,0x0A,0x0B,0x80}:
            P = numpy.matrix([[1,0,0,0],[0,1,0,0],[0,0,0,1]])
        elif self.matrix_type == 0x06:
            P = numpy.matrix([[0.5,0,0,0.5],[0,-0.5,0,0.5],[0,0,0,1]])
        elif self.matrix_type == 0x07:
            P = numpy.matrix([[0.5,0,0.5,0],[0,-0.5,0.5,0],[0,0,1,0]])
        elif self.matrix_type in {0x08,0x09}:
            P = numpy.matrix([[0.5,0,0.5,0],[0,-0.5,0.5,0],[0,0,1,0]])*numpy.matrix(self.projection_matrix)
        else:
            raise ValueError('invalid texture matrix type')

        M = T*C*S*R*C.I*P

        if self.shape == gx.TG_MTX2x4:
            return M[:2,:]
        elif self.shape == gx.TG_MTX3x4:
            return M
        else:
            raise ValueError('invalid texture matrix shape')
项目:j3dview    作者:blank63    | 项目源码 | 文件源码
def update(self,time):
        scale_x = self.scale_x.interpolate(time)
        scale_y = self.scale_y.interpolate(time)
        scale_z = self.scale_z.interpolate(time)
        rotation_x = self.rotation_x.interpolate(time)
        rotation_y = self.rotation_y.interpolate(time)
        rotation_z = self.rotation_z.interpolate(time)
        translation_x = self.translation_x.interpolate(time)
        translation_y = self.translation_y.interpolate(time)
        translation_z = self.translation_z.interpolate(time)

        cx = cos(radians(rotation_x))
        sx = sin(radians(rotation_x))
        cy = cos(radians(rotation_y))
        sy = sin(radians(rotation_y))
        cz = cos(radians(rotation_z))
        sz = sin(radians(rotation_z))

        R = numpy.matrix([[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1.0]]) #<-?
        R[0,0] = cy*cz
        R[0,1] = (sx*sy*cz - cx*sz)
        R[0,2] = (cx*sy*cz + sx*sz)
        R[1,0] = cy*sz
        R[1,1] = (sx*sy*sz + cx*cz)
        R[1,2] = (cx*sy*sz - sx*cz)
        R[2,0] = -sy
        R[2,1] = sx*cy
        R[2,2] = cx*cy

        S = numpy.matrix([[scale_x,0,0,0],[0,scale_y,0,0],[0,0,scale_z,0],[0,0,0,1]])
        C = numpy.matrix([[1,0,0,self.center_x],[0,1,0,self.center_y],[0,0,1,self.center_z],[0,0,0,1]])
        T = numpy.matrix([[1,0,0,translation_x],[0,1,0,translation_y],[0,0,1,translation_z],[0,0,0,1]])

        self.texture_matrix[:] = (T*C*S*R*C.I)[:self.row_count,:]
项目:j3dview    作者:blank63    | 项目源码 | 文件源码
def update_projection_matrix(self):
        u = self.z_near*tan(radians(self.fov))
        r = u*self.width()/self.height()
        self.projection_matrix = create_frustum_matrix(-r,r,-u,u,self.z_near,self.z_far)
        self.projection_matrix_need_update = False