All Samples(754) | Call(636) | Derive(0) | Import(118)
degrees(x) Convert angle x from radians to degrees.
src/o/w/owyl-0.3/examples/boids.py owyl(Download)
import os import random from math import radians, degrees, sin, cos, pi, atan2 pi_2 = pi*2.0 pi_1_2 = pi/2.0 pi_1_4 = pi/4.0
seek_heading = self.getFacing(dx, dy)
my_heading = radians(self.rotation)
rsize = degrees(self.findRotationDelta(my_heading, seek_heading))
rchange = rsize * rate * dt
self.rotation += rchange
continue
my_heading = radians(self.rotation)
rsize = degrees(self.findRotationDelta(my_heading, n_heading))
# Factor in our turning rate and elapsed time.
rchange = rsize * rate * dt
flee_heading = heading_away_from_neighbors
my_heading = radians(self.rotation)
rsize = degrees(self.findRotationDelta(my_heading, flee_heading))
# Factor in our turning rate and elapsed time.
rchange = rsize * rate * dt
my_heading = radians(self.rotation)
# Find the rotation delta
rsize = degrees(self.findRotationDelta(my_heading, seek_heading))
# Factor in our turning rate and elapsed time.
rchange = rsize * rate * dt
src/p/y/pysolar-HEAD/solar.py pysolar(Download)
first_term = math.cos(latitude_rad) * math.cos(declination_rad) * math.cos(math.radians(hour_angle)) second_term = math.sin(latitude_rad) * math.sin(declination_rad) return math.degrees(math.asin(first_term + second_term)) def GetApparentSiderealTime(julian_day, jme, nutation): return GetMeanSiderealTime(julian_day) + nutation['longitude'] * math.cos(GetTrueEclipticObliquity(jme, nutation))
azimuth_rad = math.asin(math.cos(declination_rad) * math.sin(hour_angle_rad) / math.cos(altitude_rad)) if(math.cos(hour_angle_rad) >= (math.tan(declination_rad) / math.tan(latitude_rad))): return math.degrees(azimuth_rad) else: return (180 - math.degrees(azimuth_rad))
def GetFlattenedLatitude(latitude): latitude_rad = math.radians(latitude) return math.degrees(math.atan(0.99664719 * math.tan(latitude_rad))) # Geocentric functions calculate angles relative to the center of the earth. def GetGeocentricLatitude(jme):
a = math.sin(geocentric_latitude_rad) * math.cos(true_ecliptic_obliquity_rad) b = math.cos(geocentric_latitude_rad) * math.sin(true_ecliptic_obliquity_rad) * math.sin(apparent_sun_longitude_rad) delta = math.asin(a + b) return math.degrees(delta) def GetGeocentricSunRightAscension(apparent_sun_longitude, true_ecliptic_obliquity, geocentric_latitude): apparent_sun_longitude_rad = math.radians(apparent_sun_longitude)
b = math.tan(geocentric_latitude_rad) * math.sin(true_ecliptic_obliquity_rad) c = math.cos(apparent_sun_longitude_rad) alpha = math.atan2((a - b), c) return math.degrees(alpha) % 360 # Heliocentric functions calculate angles relative to the center of the sun. def GetHeliocentricLatitude(jme): b0 = GetCoefficient(jme, constants.B0) b1 = GetCoefficient(jme, constants.B1) return math.degrees((b0 + (b1 * jme)) / 10 ** 8)
l5 = GetCoefficient(jme, constants.L5) l = (l0 + l1 * jme + l2 * jme ** 2 + l3 * jme ** 3 + l4 * jme ** 4 + l5 * jme ** 5) / 10 ** 8 return math.degrees(l) % 360 def GetHourAngle(utc_datetime, longitude_deg): solar_time = GetSolarTime(longitude_deg, utc_datetime)
def GetIncidenceAngle(topocentric_zenith_angle, slope, slope_orientation, topocentric_azimuth_angle):
tza_rad = math.radians(topocentric_zenith_angle)
slope_rad = math.radians(slope)
so_rad = math.radians(slope_orientation)
taa_rad = math.radians(topocentric_azimuth_angle)
return math.degrees(math.acos(math.cos(tza_rad) * math.cos(slope_rad) + math.sin(slope_rad) * math.sin(tza_rad) * math.cos(taa_rad - math.pi - so_rad)))
a = -1 * prd * math.sin(ehp_rad) * math.sin(lha_rad) b = math.cos(gsd_rad) - prd * math.sin(ehp_rad) * math.cos(lha_rad) parallax = math.atan2(a, b) return math.degrees(parallax) def GetProjectedRadialDistance(elevation, latitude): flattened_latitude_rad = math.radians(GetFlattenedLatitude(latitude))
tsd_rad = math.radians(topocentric_sun_declination)
a = math.sin(tlha_rad)
b = math.cos(tlha_rad) * math.sin(latitude_rad) - math.tan(tsd_rad) * math.cos(latitude_rad)
return 180.0 + math.degrees(math.atan2(a, b)) % 360
def GetTopocentricElevationAngle(latitude, topocentric_sun_declination, topocentric_local_hour_angle):
latitude_rad = math.radians(latitude)
tsd_rad = math.radians(topocentric_sun_declination)
tlha_rad = math.radians(topocentric_local_hour_angle)
return math.degrees(math.asin((math.sin(latitude_rad) * math.sin(tsd_rad)) + math.cos(latitude_rad) * math.cos(tsd_rad) * math.cos(tlha_rad)))
lha_rad = math.radians(local_hour_angle)
a = (math.sin(gsd_rad) - pad * math.sin(ehp_rad)) * math.cos(psra_rad)
b = math.cos(gsd_rad) - (pad * math.sin(ehp_rad) * math.cos(lha_rad))
return math.degrees(math.atan2(a, b))
def GetTopocentricSunRightAscension(projected_radial_distance, equatorial_horizontal_parallax, local_hour_angle,
apparent_sun_longitude, true_ecliptic_obliquity, geocentric_latitude):
src/a/s/Astropysics-0.1.dev-r699/astropysics/coords/ephems.py Astropysics(Download)
def equatorialCoordinates(self):
"""
Returns the equatorial coordinates of this object at the current
date/time as a :class:`EquatorialCoordinates` object for the epoch at which
they are derived.
"""
from math import radians,degrees,cos,sin,atan2,sqrt
y = cecl*yg - secl*zg
z = secl*yg + cecl*zg
ra = degrees(atan2(y,x))
dec = degrees(atan2(z,sqrt(x*x+y*y)))
#cache for faster retrieval if JD is not changed
def Eapprox(self):
"""
*approximate* Eccentric anamoly - faster than proper numerical solution
of the E-M relation, but lower precision
"""
from math import radians,sin,cos,degrees
Mr = radians(self.M)
e = self.e
return degrees(Mr + e*sin(Mr)*(1.0 + e*cos(Mr)))
def vapprox(self):
"""
*approximate* Eccentric anamoly - faster than proper numerical solution
of the E-M relation, but lower precision
"""
from math import radians,sin,cos,atan2,sqrt,degrees
xv = cos(E) - e
yv = sqrt(1.0 - e*e) * sin(E)
return degrees(atan2(yv,xv))
def cartesianCoordinates(self,geocentric=False):
"""
Returns the heliocentric ecliptic rectangular coordinates of this object
at the current date/time as an (x,y,z) tuple (in AU)
"""
from math import radians,degrees,cos,sin,atan2,sqrt
def equatorialCoordinates(self):
"""
Returns the equatorial coordinates of the Sun at the current date/time
as a :class:`EquatorialCoordinates` object for the epoch at which they are
derived.
"""
from math import radians,degrees,cos,sin,atan2,sqrt
y = ys*cos(eclr)
z = ys*sin(eclr)
ra = degrees(atan2(y,x))
dec = degrees(atan2(z,sqrt(x*x+y*y)))
#cache for faster retrieval if JD is not changed
src/w/e/weewx-HEAD/trunk/experimental/astral.py weewx(Download)
import datetime import time from math import cos, sin, tan, acos, asin, atan2, floor, radians, degrees __version__ = "0.3+" __author__ = "Simon Kennedy <python@sffjunkie.co.uk>"
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = _jday_to_jcentury(_jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = _eq_of_time(newt)
solarDec = _sun_declination(newt)
hourangle = _hour_angle_dawn(latitude, solarDec, depression)
delta = longitude - degrees(hourangle)
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = _jday_to_jcentury(_jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = _eq_of_time(newt)
solarDec = _sun_declination(newt)
hourangle = _hour_angle_sunrise(latitude, solarDec)
delta = longitude - degrees(hourangle)
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = _jday_to_jcentury(_jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = _eq_of_time(newt)
solarDec = _sun_declination(newt)
hourangle = _hour_angle_sunset(latitude, solarDec)
delta = longitude - degrees(hourangle)
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = _jday_to_jcentury(_jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = _eq_of_time(newt)
solarDec = _sun_declination(newt)
hourangle = _hour_angle_dusk(latitude, solarDec, depression)
delta = longitude - degrees(hourangle)
elif csz < -1.0:
csz = -1.0
zenith = degrees(acos(csz))
azDenom = (cos(radians(latitude)) * sin(radians(zenith)))
else:
azRad = 1.0
azimuth = 180.0 - degrees(acos(azRad))
if hourangle > 0.0:
azimuth = -azimuth
Etime = y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0 - \
0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m
return degrees(Etime) * 4.0
def _sun_eq_of_center(juliancentury):
m = _geom_mean_anomaly_sun(juliancentury)
def _sun_declination(juliancentury):
e = _obliquity_correction(juliancentury)
lambd = _sun_apparent_long(juliancentury)
sint = sin(radians(e)) * sin(radians(lambd))
return degrees(asin(sint))
tananum = (cos(radians(e)) * sin(radians(lambd)))
tanadenom = (cos(radians(lambd)))
return degrees(atan2(tananum, tanadenom))
if __name__ == "__main__":
src/a/g/agtl-0.7.1.0-freerunner0/advancedcaching/astral.py agtl(Download)
# Shortened for AGTL by Daniel Fett import datetime from math import cos, sin, tan, acos, asin, atan2, floor, radians, degrees SUN_POSITION_CACHE_DURATION = 3600 # seconds
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = self._jday_to_jcentury(self._jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = self._eq_of_time(newt)
solarDec = self._sun_declination(newt)
hourangle = self._hour_angle_dawn(latitude, solarDec, self._depression)
delta = longitude - degrees(hourangle)
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = self._jday_to_jcentury(self._jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = self._eq_of_time(newt)
solarDec = self._sun_declination(newt)
hourangle = self._hour_angle_sunrise(latitude, solarDec)
delta = longitude - degrees(hourangle)
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = self._jday_to_jcentury(self._jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = self._eq_of_time(newt)
solarDec = self._sun_declination(newt)
hourangle = self._hour_angle_sunset(latitude, solarDec)
delta = longitude - degrees(hourangle)
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = self._jday_to_jcentury(self._jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = self._eq_of_time(newt)
solarDec = self._sun_declination(newt)
hourangle = self._hour_angle_dusk(latitude, solarDec, self._depression)
delta = longitude - degrees(hourangle)
elif csz < -1.0:
csz = -1.0
zenith = degrees(acos(csz))
azDenom = (cos(radians(latitude)) * sin(radians(zenith)))
else:
azRad = 1.0
azimuth = 180.0 - degrees(acos(azRad))
if hourangle > 0.0:
azimuth = -azimuth
elif csz < -1.0:
csz = -1.0
zenith = degrees(acos(csz))
azDenom = (cos(radians(latitude)) * sin(radians(zenith)))
else:
azRad = 1.0
azimuth = 180.0 - degrees(acos(azRad))
if hourangle > 0.0:
azimuth = -azimuth
Etime = y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0 - \
0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m
return degrees(Etime) * 4.0
def _sun_eq_of_center(self, juliancentury):
m = self._geom_mean_anomaly_sun(juliancentury)
def _sun_declination(self, juliancentury):
e = self._obliquity_correction(juliancentury)
lambd = self._sun_apparent_long(juliancentury)
sint = sin(radians(e)) * sin(radians(lambd))
return degrees(asin(sint))
tananum = (cos(radians(e)) * sin(radians(lambd)))
tanadenom = (cos(radians(lambd)))
return degrees(atan2(tananum, tanadenom))
def get_sun_azimuth_from_fix(self, fix):
if self.sun_cache_time == None or abs((fix.timestamp - self.sun_cache_time).seconds) > SUN_POSITION_CACHE_DURATION:
src/a/g/agtl-0.7.1.0-freerunner0/advancedcaching/geo.py agtl(Download)
dlon = math.radians(target.lon - self.lon);
y = math.sin(dlon) * math.cos(lat2)
x = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(dlon)
bearing = math.degrees(math.atan2(y, x))
return (360 + bearing) % 360
def transform(self, bearing, distance):
else:
rlon = ( (rlon1 - math.asin( math.sin(rbearing)* math.sin(rdistance) / math.cos(rlat) ) + math.pi ) % (2*math.pi) ) - math.pi
lat = math.degrees(rlat)
lon = math.degrees(rlon)
return Coordinate(lat, lon, self.name)
src/c/o/conwc-HEAD/trunk/code/conwc/core/vectormath.py conwc(Download)
"""
n = cross(v,w)
l = length(n)
a = math.degrees(math.asin(l/length(v)/length(w)))
n = scale(n,1./l)
return (n,a)
def cartesianToCylindrical (v) :
"""Convert cartesian coordinates [x,y,z] to cylindrical [r,theta,z]
The angle is given in degrees: theta: -180..180
"""
r = math.sqrt(v[0]*v[0]+v[1]*v[1])
theta = math.degrees( math.atan2(v[1],v[0]) )
def cartesianToSpherical (v) :
"""Convert cartesian coordinates [x,y,z] to spherical [long,lat,dist]
Angles are given in degrees: lat: -90..90, long:-180..180
"""
distance = length(v)
longitude = math.degrees( math.atan2(v[0],v[2]) )
if distance == 0:
distance = 0.000000000000000000001
latitude = math.degrees( math.asin(v[1]/distance) )
src/m/a/matplotlib-HEAD/toolkits/basemap-0.9.6.1/lib/matplotlib/toolkits/basemap/basemap.py matplotlib(Download)
# the projection limb).
npoints = int((dist+0.5*1000.*del_s)/(1000.*del_s))
if npoints < 2: npoints=2
lonlats = gc.npts(math.degrees(lon2),math.degrees(lat2),math.degrees(lon1),math.degrees(lat1),npoints)
lonstmp=[math.degrees(lon2)];latstmp=[math.degrees(lat2)]
for lon,lat in lonlats:
lonstmp.append(lon); latstmp.append(lat)
lonstmp.append(math.degrees(lon1)); latstmp.append(math.degrees(lat1))
az12,az21,dist = gc.inv(lon2,lat2,lon1,lat1,radians=True)
npoints = int((dist+0.5*1000.*del_s)/(1000.*del_s))
if npoints < 2: npoints=2
lonlats = gc.npts(math.degrees(lon2),math.degrees(lat2),math.degrees(lon1),math.degrees(lat1),npoints)
lonstmp=[math.degrees(lon2)];latstmp=[math.degrees(lat2)]
for lon,lat in lonlats:
lonstmp.append(lon); latstmp.append(lat)
lonstmp.append(math.degrees(lon1));latstmp.append(math.degrees(lat1))
src/a/s/astral-0.3/src/astral.py astral(Download)
"""
import datetime
from math import cos, sin, tan, acos, asin, atan2, floor, radians, degrees
try:
import pytz
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = self._jday_to_jcentury(self._jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = self._eq_of_time(newt)
solarDec = self._sun_declination(newt)
hourangle = self._hour_angle_dawn(latitude, solarDec, self._depression)
delta = longitude - degrees(hourangle)
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = self._jday_to_jcentury(self._jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = self._eq_of_time(newt)
solarDec = self._sun_declination(newt)
hourangle = self._hour_angle_sunrise(latitude, solarDec)
delta = longitude - degrees(hourangle)
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = self._jday_to_jcentury(self._jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = self._eq_of_time(newt)
solarDec = self._sun_declination(newt)
hourangle = self._hour_angle_sunset(latitude, solarDec)
delta = longitude - degrees(hourangle)
except:
raise AstralError('Sun remains below horizon on this day, at this location.')
delta = longitude - degrees(hourangle)
timeDiff = 4.0 * delta
timeUTC = 720.0 + timeDiff - eqtime
newt = self._jday_to_jcentury(self._jcentury_to_jday(t) + timeUTC / 1440.0)
eqtime = self._eq_of_time(newt)
solarDec = self._sun_declination(newt)
hourangle = self._hour_angle_dusk(latitude, solarDec, self._depression)
delta = longitude - degrees(hourangle)
elif csz < -1.0:
csz = -1.0
zenith = degrees(acos(csz))
azDenom = (cos(radians(latitude)) * sin(radians(zenith)))
else:
azRad = 1.0
azimuth = 180.0 - degrees(acos(azRad))
if hourangle > 0.0:
azimuth = -azimuth
elif csz < -1.0:
csz = -1.0
zenith = degrees(acos(csz))
azDenom = (cos(radians(latitude)) * sin(radians(zenith)))
else:
azRad = 1.0
azimuth = 180.0 - degrees(acos(azRad))
if hourangle > 0.0:
azimuth = -azimuth
Etime = y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0 - \
0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m
return degrees(Etime) * 4.0
def _sun_eq_of_center(self, juliancentury):
m = self._geom_mean_anomaly_sun(juliancentury)
def _sun_declination(self, juliancentury):
e = self._obliquity_correction(juliancentury)
lambd = self._sun_apparent_long(juliancentury)
sint = sin(radians(e)) * sin(radians(lambd))
return degrees(asin(sint))
tananum = (cos(radians(e)) * sin(radians(lambd)))
tanadenom = (cos(radians(lambd)))
return degrees(atan2(tananum, tanadenom))
def _init_cities(self):
cities = _CITY_INFO.split('\n')
src/c/o/conwc-HEAD/trunk/trashbin/sandbox/vector.py conwc(Download)
"""
n = cross(v,w)
l = length(n)
a = math.degrees(math.asin(l/length(v)/length(w)))
n = scale(n,1./l)
return (n,a)
def cartesianToCylindrical (v) :
"""Convert cartesian coordinates [x,y,z] to cylindrical [r,theta,z]
The angle is given in degrees: theta: -180..180
"""
r = math.sqrt(v[0]*v[0]+v[1]*v[1])
theta = math.degrees( math.atan2(v[1],v[0]) )
def cartesianToSpherical (v) :
"""Convert cartesian coordinates [x,y,z] to spherical [long,lat,dist]
Angles are given in degrees: lat: -90..90, long:-180..180
"""
distance = length(v)
longitude = math.degrees( math.atan2(v[0],v[2]) )
latitude = math.degrees( math.asin(v[1]/distance) )
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next