python类degrees()的实例源码

coordutils.py 文件源码 项目:astrobase 作者: waqasbhatti 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def decimal_to_dms(decimal_value):
    '''
    This converts from decimal degrees to DD:MM:SS, returned as a tuple.

    '''

    if decimal_value < 0:
        negative = True
        dec_val = fabs(decimal_value)
    else:
        negative = False
        dec_val = decimal_value

    degrees = trunc(dec_val)
    minutes_deg = dec_val - degrees

    minutes_mm = minutes_deg * 60.0
    minutes_out = trunc(minutes_mm)
    seconds = (minutes_mm - minutes_out)*60.0

    if negative:
        degrees = degrees
        return '-', degrees, minutes_out, seconds
    else:
        return '+', degrees, minutes_out, seconds
export_json.py 文件源码 项目:coa_tools 作者: ndee85 项目源码 文件源码 阅读 52 收藏 0 点赞 0 评论 0
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)
coordutils.py 文件源码 项目:astrobase 作者: waqasbhatti 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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
coordutils.py 文件源码 项目:astrobase 作者: waqasbhatti 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def dms_to_decimal(sign, degrees, minutes, seconds):
    '''
    Converts from DD:MM:SS to a decimal value. Returns decimal degrees.

    '''

    dec_deg = fabs(degrees) + fabs(minutes)/60.0 + fabs(seconds)/3600.0

    if sign == '-':
        return -dec_deg
    else:
        return dec_deg


############################
## DISTANCE AND XMATCHING ##
############################
bearing_from_mag.py 文件源码 项目:mav_rtk_gps 作者: ethz-asl 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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
geomath.py 文件源码 项目:qgis-shapetools-plugin 作者: NationalSecurityAgency 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def atan2d(y, x):
    """compute atan2(y, x) with the result in degrees"""

    if abs(y) > abs(x):
      q = 2; x, y = y, x
    else:
      q = 0
    if x < 0:
      q += 1; x = -x
    ang = math.degrees(math.atan2(y, x))
    if q == 1:
      ang = (180 if y >= 0 else -180) - ang
    elif q == 2:
      ang =  90 - ang
    elif q == 3:
      ang = -90 + ang
    return ang
geodesic.py 文件源码 项目:qgis-shapetools-plugin 作者: NationalSecurityAgency 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def Line(self, lat1, lon1, azi1,
           caps = GeodesicCapability.STANDARD |
           GeodesicCapability.DISTANCE_IN):
    """Return a GeodesicLine object

    :param lat1: latitude of the first point in degrees
    :param lon1: longitude of the first point in degrees
    :param azi1: azimuth at the first point in degrees
    :param caps: the :ref:`capabilities <outmask>`
    :return: a :class:`~geographiclib.geodesicline.GeodesicLine`

    This allows points along a geodesic starting at (*lat1*, *lon1*),
    with azimuth *azi1* to be found.  The default value of *caps* is
    STANDARD | DISTANCE_IN, allowing direct geodesic problem to be
    solved.

    """

    from geographiclib.geodesicline import GeodesicLine
    return GeodesicLine(self, lat1, lon1, azi1, caps)
geodesic.py 文件源码 项目:qgis-shapetools-plugin 作者: NationalSecurityAgency 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def DirectLine(self, lat1, lon1, azi1, s12,
                 caps = GeodesicCapability.STANDARD |
                 GeodesicCapability.DISTANCE_IN):
    """Define a GeodesicLine object in terms of the direct geodesic
    problem specified in terms of spherical arc length

    :param lat1: latitude of the first point in degrees
    :param lon1: longitude of the first point in degrees
    :param azi1: azimuth at the first point in degrees
    :param s12: the distance from the first point to the second in
      meters
    :param caps: the :ref:`capabilities <outmask>`
    :return: a :class:`~geographiclib.geodesicline.GeodesicLine`

    This function sets point 3 of the GeodesicLine to correspond to
    point 2 of the direct geodesic problem.  The default value of *caps*
    is STANDARD | DISTANCE_IN, allowing direct geodesic problem to be
    solved.

    """

    return self._GenDirectLine(lat1, lon1, azi1, False, s12, caps)
geodesic.py 文件源码 项目:qgis-shapetools-plugin 作者: NationalSecurityAgency 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def ArcDirectLine(self, lat1, lon1, azi1, a12,
                 caps = GeodesicCapability.STANDARD |
                 GeodesicCapability.DISTANCE_IN):
    """Define a GeodesicLine object in terms of the direct geodesic
    problem specified in terms of spherical arc length

    :param lat1: latitude of the first point in degrees
    :param lon1: longitude of the first point in degrees
    :param azi1: azimuth at the first point in degrees
    :param a12: spherical arc length from the first point to the second
      in degrees
    :param caps: the :ref:`capabilities <outmask>`
    :return: a :class:`~geographiclib.geodesicline.GeodesicLine`

    This function sets point 3 of the GeodesicLine to correspond to
    point 2 of the direct geodesic problem.  The default value of *caps*
    is STANDARD | DISTANCE_IN, allowing direct geodesic problem to be
    solved.

    """

    return self._GenDirectLine(lat1, lon1, azi1, True, a12, caps)
LatLon.py 文件源码 项目:qgis-shapetools-plugin 作者: NationalSecurityAgency 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def parseDMSStringSingle(str):
        '''Parse a single coordinate either DMS or decimal degrees.
        It simply returns the value but doesn't maintain any knowledge
        as to whether it is latitude or longitude'''
        str = str.strip().upper()
        try:
            if re.search("[NSEW\xb0]", str) == None:
                coord = float(str)
            else:
                m = re.findall('(.+)\s*([NSEW])', str)
                if len(m) != 1 or len(m[0]) != 2:
                    raise ValueError('Invalid DMS Coordinate')
                coord = LatLon.parseDMS(m[0][0], m[0][1])
        except:
            raise ValueError('Invalid Coordinates')
        return coord
ArcItem.py 文件源码 项目:CPNSimulatorGui 作者: chris-kuhr 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def setPolygon(self):
        '''Calculate position and rotation of the arc arrow head.'''
        rotDeg = 0            
        xlength = self.pos1.x() - self.pos2.x()
        ylength = self.pos1.y() - self.pos2.y()
        d = math.sqrt( math.pow( xlength , 2) + math.pow( ylength , 2) )        
        if d > 0:
            beta = math.acos( xlength / d )
            rotDeg = math.degrees( beta ) 

        self.arrowPolygonObject.setPolygon( QtGui.QPolygonF( [
                                                 QtCore.QPointF( (self.pos2.x() -10),  (self.pos2.y() +5)), 
                                                 QtCore.QPointF( (self.pos2.x() -10) , (self.pos2.y() -5)), 
                                                 QtCore.QPointF(       self.pos2.x() ,      self.pos2.y())
                                                 ] ) ) 

        self.arrowPolygonObject.setBrush( QtGui.QBrush(QtCore.Qt.black) )

        """ self.angle()!!!!!!!!!"""
#         self.arcLinePolygon.angle()
#         self.arcLinePolygon.rotate(rotDeg)
#         self.arcLinePolygon.setPos( self.pos2 ) 

    #------------------------------------------------------------------------------------------------
ArrowGui.py 文件源码 项目:CPNSimulatorGui 作者: chris-kuhr 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def setPolygon(self):
        rotDeg = 0            
        xlength = self.pos1.x() - self.pos2.x()
        ylength = self.pos1.y() - self.pos2.y()
        d = math.sqrt( math.pow( xlength , 2) + math.pow( ylength , 2) )        
        if d > 0:
            beta = math.acos( xlength / d )
            rotDeg = math.degrees( beta ) 

        self.arcLinePolygon.setPolygon( QtGui.QPolygonF( [
                                                 QtCore.QPointF( (self.pos2.x() -10),  (self.pos2.y() +5)), 
                                                 QtCore.QPointF( (self.pos2.x() -10) , (self.pos2.y() -5)), 
                                                 QtCore.QPointF(       self.pos2.x() ,      self.pos2.y())
                                                 ] ) ) 

        self.arcLinePolygon.setBrush( QtGui.QBrush(QtCore.Qt.black) )

        """ self.angle()!!!!!!!!!"""
#         self.arcLinePolygon.angle()
#         self.arcLinePolygon.rotate(rotDeg)
#         self.arcLinePolygon.setPos( self.pos2 ) 
    #------------------------------------------------------------------------------------------------
iaga2002.py 文件源码 项目:pyrsss 作者: butala 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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
calibration_fit.py 文件源码 项目:pypilot 作者: pypilot 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def ComputeDeviation(points, fit):
    m, d  = 0, 0
    for p in points:
        v = vector.sub(p[:3], fit[:3])
        m += (1 - vector.dot(v, v) / fit[3]**2)**2

        if len(fit) > 4:
            n = vector.dot(v, p[3:]) / vector.norm(v)
            if abs(n) <= 1:
                ang = math.degrees(math.asin(n))
                d += (fit[4] - ang)**2
            else:
                d += 1e111
    m /= len(points)
    d /= len(points)
    return [m**.5, d**.5]
coords.py 文件源码 项目:satellite-tracker 作者: lofaldli 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def eci_to_latlon(pos, phi_0=0):
    (x, y, z) = pos
    rg = (x*x + y*y + z*z)**0.5
    z = z/rg
    if abs(z) > 1.0:
        z = int(z)

    lat = degrees(asin(z))
    lon = degrees(atan2(y, x)-phi_0)
    if lon > 180:
        lon -= 360
    elif lon < -180:
        lon += 360
    assert -90 <= lat <= 90
    assert -180 <= lon <= 180
    return lat, lon
MotionBlur.py 文件源码 项目:UPBGE-CommunityAddon 作者: elmeunick9 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def update(self):
        from bge import logic as G
        import math

        scene = G.getCurrentScene()
        own = self.own

        cam = scene.active_camera
        wtc = cam.world_to_camera

        own['rota'] = math.degrees(cam.localOrientation.to_euler().x)

        if 'init' not in own:
            set = cam.projection_matrix * wtc
            own['prev'] = set
            own['init'] = True
            self = MotionBlur
        set = (cam.projection_matrix * wtc)
        cameraMatrix = own['prev']

        self.x = cameraMatrix
        self.viewProjectionInverse = set.inverted()

        own['prev'] = set
rotor_calc.py 文件源码 项目:enigma2 作者: OpenLD 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def calcAzimuth(SatLon, SiteLat, SiteLon, Height_over_ocean = 0):

    def rev(number):
        return number - math.floor(number / 360.0) * 360

    sinRadSiteLat = math.sin(math.radians(SiteLat))
    cosRadSiteLat = math.cos(math.radians(SiteLat))

    Rstation = r_eq / (math.sqrt(1 - f * (2 - f) * sinRadSiteLat **2))
    Ra = (Rstation + Height_over_ocean) * cosRadSiteLat
    Rz = Rstation * (1 - f) ** 2 * sinRadSiteLat

    alfa_rx = r_sat * math.cos(math.radians(SatLon - SiteLon)) - Ra
    alfa_ry = r_sat * math.sin(math.radians(SatLon - SiteLon))
    alfa_rz = -Rz

    alfa_r_north = -alfa_rx * sinRadSiteLat + alfa_rz * cosRadSiteLat

    if alfa_r_north < 0:
        Azimuth = 180 + math.degrees(math.atan(alfa_ry / alfa_r_north))
    elif alfa_r_north > 0:
        Azimuth = rev(360 + math.degrees(math.atan(alfa_ry / alfa_r_north)))
    else:
        Azimuth = 0
    return Azimuth
rotor_calc.py 文件源码 项目:enigma2 作者: OpenLD 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def calcSatHourangle(SatLon, SiteLat, SiteLon):
    Azimuth = calcAzimuth(SatLon, SiteLat, SiteLon )
    Elevation = calcElevation(SatLon, SiteLat, SiteLon)

    a = - math.cos(math.radians(Elevation)) * math.sin(math.radians(Azimuth))
    b = math.sin(math.radians(Elevation)) * math.cos(math.radians(SiteLat)) - \
        math.cos(math.radians(Elevation)) * math.sin(math.radians(SiteLat)) * \
        math.cos(math.radians(Azimuth))

    # Works for all azimuths (northern & southern hemisphere)
    returnvalue = 180 + math.degrees(math.atan(a / b))

    if Azimuth > 270:
        returnvalue += 180
        if returnvalue > 360:
            returnvalue = 720 - returnvalue

    if Azimuth < 90:
        returnvalue = 180 - returnvalue

    return returnvalue
pong.py 文件源码 项目:CodeDay-Pong-AI 作者: ianjury 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def getStatistics(circle_x, circle_y, bar1_x, bar1_y, bar2_x, bar2_y):
    out = [0, 0, 0]
    midX = GLOBAL_WIDTH / 2
    midY = GLOBAL_HEIGHT / 2
    dx = midX - circle_x
    dy = midY - circle_y
    rads = atan2(-dy, dx)
    rads %= 2*pi
    angle = degrees(rads)
    if  (bar1_x - circle_x)**2 != 0:
        p1Distance = sqrt((bar1_y - circle_y)**2 / (bar1_x - circle_x)**2)
    if (bar2_x - circle_x)**2 != 0:
        p2Distance = sqrt((bar2_y - circle_y)**2 / (bar2_x - circle_x)**2)
    out[0] = angle
    out[1] = p1Distance
    out[2] = p2Distance
    return out

#determines how to move padel based on neural net input
geomath.py 文件源码 项目:AboveTustin 作者: kevinabrandon 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
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
utils_math.py 文件源码 项目:CC3501-2017-1 作者: ppizarror 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def xyz_to_spr(x, y, z):
    """Convierte las coordenadas cartesianas (x,y,z) a las coordenadas esfericas (r,phi,theta) con angulos en grados"""
    # Calculo el radio
    r = math.sqrt(x ** 2 + y ** 2 + z ** 2)
    # Calculo el angulo theta
    if z > 0:
        theta = math.atan(math.sqrt(x ** 2 + y ** 2) / z)
    elif z == 0:
        theta = math.pi / 2
    else:
        theta = math.pi + math.atan(math.sqrt(x ** 2 + y ** 2) / z)
    # Calculo el angulo phi
    if x > 0:
        if y > 0:
            phi = math.atan(y / x)
        else:
            phi = 2 * math.pi + math.atan(y / x)
    elif x == 0:
        phi = sgn(y) * math.pi / 2
    else:
        phi = math.pi + math.atan(y / x)
    theta = math.degrees(theta)
    phi = math.degrees(phi) % 360
    theta = min(max(theta, 0.000001), 180)
    return r, phi, theta
utils.py 文件源码 项目:CC3501-2017-1 作者: ppizarror 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def xyz_to_spr(x, y, z):
    """Convierte las coordenadas cartesianas (x,y,z) a las coordenadas esfericas (r,phi,theta) con angulos en grados"""
    # Calculo el radio
    r = math.sqrt(x ** 2 + y ** 2 + z ** 2)
    # Calculo el angulo theta
    if z > 0:
        theta = math.atan(math.sqrt(x ** 2 + y ** 2) / z)
    elif z == 0:
        theta = math.pi / 2
    else:
        theta = math.pi + math.atan(math.sqrt(x ** 2 + y ** 2) / z)
    # Calculo el angulo phi
    if x > 0:
        if y > 0:
            phi = math.atan(y / x)
        else:
            phi = 2 * math.pi + math.atan(y / x)
    elif x == 0:
        phi = sgn(y) * math.pi / 2
    else:
        phi = math.pi + math.atan(y / x)
    theta = math.degrees(theta)
    phi = math.degrees(phi) % 360
    theta = min(max(theta, 0.000001), 180)
    return r, phi, theta
cube_thingie.py 文件源码 项目:codecad 作者: bluecube 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def cube_with_base(unit_cube):
    """ Take a unit cube and turn it into a statue thingie, standing on one corner """
    m = cube_side / 2

    prepared_cube = unit_cube.scaled(cube_side) \
        .rotated_x(45) \
        .rotated_y(math.degrees(math.acos(math.sqrt(2/3)))) \
        .translated(0, 0, cube_side * math.sqrt(3) / 2 + base_height)

    bottom = rectangle(base_diameter, base_height).translated(0, base_height / 2)
    chamfer = rectangle(2 * base_chamfer, 2 * base_chamfer).rotated(-45).translated(base_diameter / 2, base_height)
    bottom = bottom - chamfer

    knob = rectangle(base_knob_diameter, base_height + base_knob_height) \
        .translated_y((base_height + base_knob_height) / 2)
    knob_chamfer = rectangle(2 * base_chamfer, 2 * base_chamfer) \
        .rotated(-45) \
        .translated(base_knob_diameter / 2, base_height + base_knob_height)
    knob = knob - knob_chamfer

    base = (bottom + knob).revolved().rotated_x(90)

    return prepared_cube + base
osm_stops.py 文件源码 项目:osm2gtfs 作者: grote 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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
mesh_xoffsets.py 文件源码 项目:bpy_lambda 作者: bcongdon 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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.
mesh_xoffsets.py 文件源码 项目:bpy_lambda 作者: bcongdon 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def updatelock_pts(self, ref_pts):
    global curr_meas_stor
    set_lock_pts(ref_pts)
    if ref_pts.lp_ls == []:
        self.report({'ERROR'}, ref_pts.ax_lock+' axis lock creates identical points')
        ref_pts.lp_ls = ref_pts.rp_ls
        ref_pts.ax_lock = ''
    # update Measurement in curr_meas_stor
    lk_pts = ref_pts.lp_ls
    if ref_pts.cnt < 2:
        curr_meas_stor = 0.0
    elif ref_pts.cnt == 2:
        curr_meas_stor = get_dist(lk_pts[0].co3D, lk_pts[1].co3D)
    elif ref_pts.cnt == 3:
        line_ang_r = get_line_ang_3D(lk_pts[0].co3D, lk_pts[1].co3D, lk_pts[2].co3D)
        curr_meas_stor = degrees(line_ang_r)


# See if key was pressed that would require updating the axis lock info.
# If one was, update the lock points to use new info.
android_hooks.py 文件源码 项目:ATX 作者: NetEaseGame 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def radang(x, y):
    '''return (radius, angle) of a vector(x, y)'''
    if x == 0:
        if y == 0:
            return 0, 0
        return abs(y), 90+180*(y<0)
    if y == 0:
        return abs(x), 180*(x<0)

    r = math.sqrt(x*x+y*y)
    a = math.degrees(math.atan(y/x))
    if x < 0:
        a += 180
    elif y < 0:
        a += 360
    return r, a
util.py 文件源码 项目:Houston 作者: squaresLab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def gps_newpos(lat, lon, bearing, distance):
    """Extrapolate latitude/longitude given a heading and distance
    thanks to http://www.movable-type.co.uk/scripts/latlong.html .
    """
    from math import sin, asin, cos, atan2, radians, degrees

    lat1 = radians(lat)
    lon1 = radians(lon)
    brng = radians(bearing)
    dr = distance / radius_of_earth

    lat2 = asin(sin(lat1) * cos(dr) +
                cos(lat1) * sin(dr) * cos(brng))
    lon2 = lon1 + atan2(sin(brng) * sin(dr) * cos(lat1),
                        cos(dr) - sin(lat1) * sin(lat2))
    return (degrees(lat2), degrees(lon2))
util.py 文件源码 项目:Houston 作者: squaresLab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def current(self, deltat=None):
        """Return current wind speed and direction as a tuple
        speed is in m/s, direction in degrees."""
        if deltat is None:
            tnow = time.time()
            deltat = tnow - self.tlast
            self.tlast = tnow

        # update turbulance random walk
        w_delta = math.sqrt(deltat) * (1.0 - random.gauss(1.0, self.turbulance))
        w_delta -= (self.turbulance_mul - 1.0) * (deltat / self.turbulance_time_constant)
        self.turbulance_mul += w_delta
        speed = self.speed * math.fabs(self.turbulance_mul)
        return (speed, self.direction)

    # Calculate drag.
grid.py 文件源码 项目:siren 作者: ozsolarwind 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def dust(self, pyd, pxd, y1d, x1d, y2d, x2d):   # debug
        px = radians(pxd)
        py = radians(pyd)
        x1 = radians(x1d)
        y1 = radians(y1d)
        x2 = radians(x2d)
        y2 = radians(y2d)
        p_x = x2 - x1
        p_y = y2 - y1
        something = p_x * p_x + p_y * p_y
        u = ((px - x1) * p_x + (py - y1) * p_y) / float(something)
        if u > 1:
            u = 1
        elif u < 0:
            u = 0
        x = x1 + u * p_x
        y = y1 + u * p_y
        dx = x - px
        dy = y - py
        dist = sqrt(dx * dx + dy * dy)
        return [round(abs(dist) * RADIUS, 2), round(degrees(y), 6), round(degrees(x), 6)]


问题


面经


文章

微信
公众号

扫码关注公众号