本文整理汇总了Python中math.sin函数的典型用法代码示例。如果您正苦于以下问题:Python sin函数的具体用法?Python sin怎么用?Python sin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: distance_on_unit_sphere
def distance_on_unit_sphere(self,lat1, long1, lat2, long2):
"""
from john d cook website http://www.johndcook.com/blog/python_longitude_latitude/
:arg lat1: latitude value in degrees for clSite
:arg lon1: longitude value in degrees for clSite
:arg lat2: latitude value in degrees for zipcode
:arg lon2: longitude value in degrees for zipcode
:var all: see link for further explanation
"""
degrees_to_radians = math.pi/180.0
# phi = 90 - latitude
phi1 = (90.0 - lat1)*degrees_to_radians
phi2 = (90.0 - lat2)*degrees_to_radians
# theta = longitude
theta1 = long1*degrees_to_radians
theta2 = long2*degrees_to_radians
cos = (math.sin(phi1)*math.sin(phi2)*math.cos(theta1 - theta2) + math.cos(phi1)*math.cos(phi2))
arc = math.acos( cos )
#To get the distance in miles, multiply by 3960.
#To get the distance in kilometers, multiply by 6373.
arc = arc * 3960 #miles
return arc
示例2: show_visual
def show_visual(sec = False, radius = 39):
c = Canvas(2*radius+1, 2*radius+1)
x = 0
while True:
t = time.localtime()
c.draw_circle(radius,radius,radius,1)
c.draw_circle(radius,radius,radius-1,1)
for i in xrange(12):
dx = math.sin(2.0*math.pi*i/12)
dy = math.cos(2.0*math.pi*i/12)
if i%3 == 0:
c.draw_line(radius+int(dx*radius), radius-int(dy*radius), radius+int(0.8*dx*radius), radius-int(0.8*dy*radius),1)
else:
c.draw_line(radius+int(dx*radius), radius-int(dy*radius), radius+int(0.9*dx*radius), radius-int(0.9*dy*radius),1)
G = [((t[3]%12), 12, 0.4, 2), (t[4], 60, 0.6, 3), (t[5], 60, 0.8, 4)]
for gnomon in G:
dx = math.sin(2.0*math.pi*gnomon[0]/gnomon[1])
dy = math.cos(2.0*math.pi*gnomon[0]/gnomon[1])
c.draw_line(radius, radius, radius+int(dx*gnomon[2]*radius), radius-int(dy*gnomon[2]*radius), gnomon[3])
c.draw_line(radius, radius, radius-int(dx*gnomon[2]*radius/4), radius+int(dy*gnomon[2]*radius/4), gnomon[3])
c.render(width, height)
time.sleep(1)
for gnomon in G:
dx = math.sin(2.0*math.pi*gnomon[0]/gnomon[1])
dy = math.cos(2.0*math.pi*gnomon[0]/gnomon[1])
c.draw_line(radius, radius, radius+int(dx*gnomon[2]*radius), radius-int(dy*gnomon[2]*radius), 0)
c.draw_line(radius, radius, radius-int(dx*gnomon[2]*radius/4), radius+int(dy*gnomon[2]*radius/4), 0)
示例3: AngularDistance
def AngularDistance(RA1, DEC1, RA2, DEC2):
try:
RA1 = float(RA1)
DEC1 = float(DEC1)
RA2 = float(RA2)
DEC2 = float(DEC2)
# Converting everything to radians
ra1rad = RA1 * math.pi/180.
ra2rad = RA2 * math.pi/180.
dec1rad = DEC1 * math.pi/180.
dec2rad = DEC2 * math.pi/180.
# Calculate scalar product for determination of angular separation
x=math.cos(ra1rad)*math.cos(dec1rad)*math.cos(ra2rad)*math.cos(dec2rad)
y=math.sin(ra1rad)*math.cos(dec1rad)*math.sin(ra2rad)*math.cos(dec2rad)
z=math.sin(dec1rad)*math.sin(dec2rad)
rad=math.acos(x+y+z)
# Use Pythargoras approximation if rad < 1 arcsec
if rad<0.000004848:
rad=math.sqrt((math.cos(dec1rad)*(ra1rad-ra2rad))**2+(dec1rad-dec2rad)**2)
pass
# Angular separation in degrees
Angle = rad*180/math.pi
return Angle
except Exception, message:
print message
return float('nan')
示例4: gps_distance_between
def gps_distance_between(point_a, point_b):
"""
Calculate the orthodromic distance between two GPS readings.
point_a and point_b can be either of the two:
- tuples in the form (latitude, longitude).
- instances of the class logwork.Signal
The result is in metres.
ATTENTION: since latitude is given before longitude, if we are using the
X and Y representation, then we must pass in (Y, X) and *not* (X, Y)
Computed with the Haversine formula
(http://en.wikipedia.org/wiki/Haversine_formula)
"""
if hasattr(point_a, "latitude"):
a_lat, a_lon = math.radians(point_a.latitude), math.radians(point_a.longitude)
else:
a_lat, a_lon = math.radians(point_a[0]), math.radians(point_a[1])
if hasattr(point_b, "latitude"):
b_lat, b_lon = math.radians(point_b.latitude), math.radians(point_b.longitude)
else:
b_lat, b_lon = math.radians(point_b[0]), math.radians(point_b[1])
d_lat = b_lat - a_lat
d_lon = b_lon - a_lon
a = math.sin(d_lat / 2.0) ** 2 + math.cos(a_lat) * math.cos(b_lat) * math.sin(d_lon / 2.0) ** 2
c = 2 * math.asin(math.sqrt(a))
return EARTH_RADIUS * c * 1000
示例5: vorbiswindow
def vorbiswindow(j, K):
if j < 0:
return 0
elif j >= K:
return 0
z = sin(pi / K * (j + 0.5))
return sin(pi * 0.5 * z * z)
示例6: __init__
def __init__(self, lb, lb_length, up_angle, dn_angle, hb, hb_length):
# define the name
# (there is only one launchbar element) --> isn't it ?
name = 'YASim_Launchbar'
# Calculate points for the mesh
# here in the original script hb = hb - lb
# --> seems to be tuple - vector, that is not working
# assuming: (this step is necessary to get from global to local coordinates !!)
hb = hb - Vector(lb)
lb_tip = ORIGIN + lb_length * math.cos(dn_angle * DEG2RAD) * X - lb_length * math.sin(dn_angle * DEG2RAD) * Z
hb_tip = hb - hb_length * math.cos(dn_angle * DEG2RAD) * X - hb_length * math.sin(dn_angle * DEG2RAD) * Z
# create the mesh: launchbar and holdback extended position
lb_obj = mesh_create(name, lb, [ORIGIN, lb_tip, hb, hb_tip, lb_tip+0.05*Y, lb_tip-0.05*Y, hb_tip+0.05*Y, hb_tip-0.05*Y],
[(0,1),(0,2),(2,3),(4,5),(6,7)], [])
# set the created object active !!!!!!!
bpy.context.scene.objects.active = lb_obj
# draw dashed lines for the retracted position
# get the active mesh
mesh = bpy.context.object.data
lb_up = lb_length * math.cos(up_angle * DEG2RAD) * X - lb_length * math.sin(up_angle * DEG2RAD) * Z
hb_up = hb - hb_length * math.cos(up_angle * DEG2RAD) * X - hb_length * math.sin(up_angle * DEG2RAD) * Z
draw_dashed_line(mesh, ORIGIN, lb_up)
draw_dashed_line(mesh, hb, hb_up)
# set material
Item.set_material('grey2', (0.3,0.3,0.3), 1)
示例7: execute
def execute(self, context):
A = 6.283185307179586476925286766559 / 3
verts = [(sin(A * 1), 0.0, cos(A * 1)),
(sin(A * 2), 0.0, cos(A * 2)),
(sin(A * 3), 0.0, cos(A * 3)),
]
faces = [(0, 1, 2)]
mesh = bpy.data.meshes.new("Cube")
bm = bmesh.new()
for v_co in verts:
bm.verts.new(v_co)
for f_idx in faces:
bm.faces.new([bm.verts[i] for i in f_idx])
bm.to_mesh(mesh)
mesh.update()
object_utils.object_data_add(context, mesh)
return{'FINISHED'}
示例8: __init__
def __init__(self, scale=1.0):
self.translation = Vector3()
self.rotation = Vector3()
self.initialHeight = Vector3(0, 0, scale*StewartPlatformMath.SCALE_INITIAL_HEIGHT)
self.baseJoint = []
self.platformJoint = []
self.q = []
self.l = []
self.alpha = []
self.baseRadius = scale*StewartPlatformMath.SCALE_BASE_RADIUS
self.platformRadius = scale*StewartPlatformMath.SCALE_PLATFORM_RADIUS
self.hornLength = scale*StewartPlatformMath.SCALE_HORN_LENGTH
self.legLength = scale*StewartPlatformMath.SCALE_LEG_LENGTH;
for angle in self.baseAngles:
mx = self.baseRadius*cos(radians(angle))
my = self.baseRadius*sin(radians(angle))
self.baseJoint.append(Vector3(mx, my))
for angle in self.platformAngles:
mx = self.platformRadius*cos(radians(angle))
my = self.platformRadius*sin(radians(angle))
self.platformJoint.append(Vector3(mx, my))
self.q = [Vector3()]*len(self.platformAngles)
self.l = [Vector3()]*len(self.platformAngles)
self.alpha = [0]*len(self.beta)
示例9: refresh
def refresh(self, matrix):
matrix.fade(0.995)
y0 = matrix.height/2
x0 = matrix.width/2
if self.angle >= pi:
x0 -= 1
if self.angle > (0.5*pi) and self.angle < (1.5*pi):
y0 -= 1
x1 = int(self.x0 + self.radius * sin(self.angle-self.astep))
y1 = int(self.y0 + self.radius * cos(self.angle+self.astep))
x2 = int(self.x0 + self.radius * sin(self.angle))
y2 = int(self.y0 + self.radius * cos(self.angle))
matrix.drawPoly(
[(self.x0, self.y0), (x1, y1), (x2, y2)],
hsvToRgb(self.hue)
)
self.hue = fmod(self.hue+self.hstep, 1.0)
self.angle += self.astep
示例10: distance
def distance(origin, destination):
"""
Calculates both distance and bearing
"""
lat1, lon1 = origin
lat2, lon2 = destination
if lat1>1000:
(lat1,lon1)=dm2dd(lat1,lon1)
(lat2,lon2)=dm2dd(lat2,lon2)
print('converted to from ddmm to dd.ddd')
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
def calcBearing(lat1, lon1, lat2, lon2):
dLon = lon2 - lon1
y = math.sin(dLon) * math.cos(lat2)
x = math.cos(lat1) * math.sin(lat2) \
- math.sin(lat1) * math.cos(lat2) * math.cos(dLon)
return math.atan2(y, x)
bear= math.degrees(calcBearing(lat1, lon1, lat2, lon2))
return d,bear
示例11: sumVectors
def sumVectors(self, vectors):
""" sum all vectors (including targetvector)"""
endObstacleVector = (0,0)
##generate endvector of obstacles
#sum obstaclevectors
for vector in vectors:
vectorX = math.sin(math.radians(vector[1])) * vector[0] # x-position
vectorY = math.cos(math.radians(vector[1])) * vector[0] # y-position
endObstacleVector = (endObstacleVector[0]+vectorX,endObstacleVector[1]+vectorY)
#mean obstaclevectors
if len(vectors) > 0:
endObstacleVector = (endObstacleVector[0]/len(vectors), endObstacleVector[1]/len(vectors))
#add targetvector
targetVector = self.target
if targetVector != 0 and targetVector != None:
vectorX = math.sin(math.radians(targetVector[1])) * targetVector[0] # x-position
vectorY = math.cos(math.radians(targetVector[1])) * targetVector[0] # y-position
endVector = (endObstacleVector[0]+vectorX,endObstacleVector[1]+vectorY)
#endVector = (endVector[0]/2, endVector[1]/2)
else:
endVector = endObstacleVector
return endVector
示例12: update_location
def update_location(self, delta_encoder_count_1, delta_encoder_count_2):
"""
Update the robot's location
@rtype : DifferentialDriveRobotLocation
@return: Updated location
@param delta_encoder_count_1: Count of wheel 1's encoder since last update
@param delta_encoder_count_2: Count of wheel 2's encoder since last update
@type delta_encoder_count_1: int
@type delta_encoder_count_2: int
"""
dfr = delta_encoder_count_2 * 2 * math.pi / self.robot_parameters.steps_per_revolution
dfl = delta_encoder_count_1 * 2 * math.pi / self.robot_parameters.steps_per_revolution
ds = (dfr + dfl) * self.robot_parameters.wheel_radius / 2
dz = (dfr - dfl) * self.robot_parameters.wheel_radius / self.robot_parameters.wheel_distance
self.location.x_position += ds * math.cos(self.location.z_position + dz / 2)
self.location.y_position += ds * math.sin(self.location.z_position + dz / 2)
self.location.z_position += dz
self.globalLocation.x_position += ds * math.cos(self.globalLocation.z_position + dz / 2)
self.globalLocation.y_position += ds * math.sin(self.globalLocation.z_position + dz / 2)
self.globalLocation.z_position += dz
return self.location, self.globalLocation
示例13: distance
def distance(xlat, xlon, ylat, ylon):
dlon = ylon - xlon
dlat = ylat - xlat
a = sin(dlat / 2) ** 2 + cos(xlat) * cos(ylat) * sin(dlon / 2) ** 2
c = 2 * atan2(sqrt(a), sqrt(1 - a))
distance = R * c
return distance
示例14: calculate_initial_compass_bearing
def calculate_initial_compass_bearing(self, pointA, pointB):
"""
Calculates direction between two points.
Code based on compassbearing.py module
https://gist.github.com/jeromer/2005586
pointA: latitude/longitude for first point (decimal degrees)
pointB: latitude/longitude for second point (decimal degrees)
Return: direction heading in degrees (0-360 degrees, with 90 = North)
"""
if (type(pointA) != tuple) or (type(pointB) != tuple):
raise TypeError("Only tuples are supported as arguments")
lat1 = math.radians(pointA[0])
lat2 = math.radians(pointB[0])
diffLong = math.radians(pointB[1] - pointA[1])
# Direction angle (-180 to +180 degrees):
# θ = atan2(sin(Δlong).cos(lat2),cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong))
x = math.sin(diffLong) * math.cos(lat2)
y = math.cos(lat1) * math.sin(lat2) - (math.sin(lat1) * math.cos(lat2) * math.cos(diffLong))
initial_bearing = math.atan2(x, y)
# Direction calculation requires to normalize direction angle (0 - 360)
initial_bearing = math.degrees(initial_bearing)
compass_bearing = (initial_bearing + 360) % 360
return compass_bearing
示例15: calc_point_distance
def calc_point_distance( self, p1, p2 ) :
x1 = float( p1['x'] )
y1 = float( p1['y'] )
lat1 = x1 * math.pi / 180.0
long1 = y1 * math.pi / 180.0
sinl1 = math.sin( lat1 )
cosl1 = math.cos( lat1 )
x2 = float( p2['x'] )
y2 = float( p2['y'] )
lat2 = x2 * math.pi / 180.0
long2 = y2 * math.pi / 180.0
sinl2 = math.sin( lat2 )
cosl2 = math.cos( lat2 )
dl = long2 - long1
sindl = math.sin( dl )
cosdl = math.cos( dl )
a = cosl2 * sindl
b = cosl1 * sinl2 - sinl1 * cosl2 * cosdl
y = math.sqrt( a*a + b*b )
x = sinl1 * sinl2 + cosl1 * cosl2 * cosdl
d = math.atan2( y, x ) * 6372795 # радиус Земли
#print( "d=%d" % ( d ) )
return d