本文整理汇总了Python中math.cos函数的典型用法代码示例。如果您正苦于以下问题:Python cos函数的具体用法?Python cos怎么用?Python cos使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cos函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例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: simplesnr
def simplesnr(f,h,i=None,years=1,noisemodel=None,includewd=None):
if i == None:
h0 = h * math.sqrt(16.0/5.0) # rms average over inclinations
else:
h0 = h * math.sqrt((1 + math.cos(i)**2)**2 + (2*math.cos(i))**2)
return h0 * math.sqrt(years * 365.25*24*3600) / math.sqrt(lisanoise(f,noisemodel,includewd))
示例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: rotate_point
def rotate_point(point, center, angle):
""" Rotate a point around another point
"""
angle = math.radians(angle)
x = center[0] + (point[0] - center[0]) * math.cos(angle) - (point[1] - center[1]) * math.sin(angle);
y = center[1] - (point[0] - center[0]) * math.sin(angle) + (point[1] - center[1]) * math.cos(angle);
return (x, y)
示例6: cart2tether_actual
def cart2tether_actual(sz,xyz):
#convert a cartesian goal to tether length goals. assumes the tethers go to points on the outside edge of the end effector.
#returns a more precise estimate of tether length, but one that is inadmissible to the get_xyz_pos function
#goal : 1x3 array [x,y,z]
# L = 1x4 array [L0,L1,L2,L3] spiral zipper and each tether length
#finds the axis-angle rotation matrix from the column's vertical pose.
theta = sz.angle_between([0,0,sz.L[0]], xyz)
k = np.cross([0,0,sz.L[0]],xyz)
if np.linalg.norm(k) != 0: #ensures k is a unit vector where its norm == 1
k = k/np.linalg.norm(k)
Xk = k[0]
Yk = k[1]
Zk = k[2]
v = 1 - m.cos(theta)
R = np.array( [[m.cos(theta) + (Xk**2*v) , (Xk*Yk*v) - (Zk*m.sin(theta)), (Xk*Zk*v) + Yk*m.sin(theta)],\
[((Yk*Xk*v) + Zk*m.sin(theta)), m.cos(theta) + (Yk**2*v) , (Yk*Zk*v) - Xk*m.sin(theta)],\
[(Zk*Xk*v) - Yk*m.sin(theta), (Zk*Yk*v) + Xk*m.sin(theta) , m.cos(theta) + (Zk**2*v) ]])
#calculates position vector of the column tether attachment points in the world frame
OB1 = xyz + np.dot(R,sz.ef[0])
OB2 = xyz + np.dot(R,sz.ef[1])
OB3 = xyz + np.dot(R,sz.ef[2])
L0 = m.sqrt((xyz[0]**2+xyz[1]**2+xyz[2]**2)) # should just be sz.L[0] if not there is a math mistake
L1 = np.linalg.norm(OB1 - sz.p[0])
L2 = np.linalg.norm(OB2 - sz.p[1])
L3 = np.linalg.norm(OB3 - sz.p[2])
L = [L0,L1,L2,L3]
return L
示例7: distance_on_unit_sphere
def distance_on_unit_sphere(lat1, long1, lat2, long2):
# Convert latitude and longitude to
# spherical coordinates in radians.
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
# Compute spherical distance from spherical coordinates.
# For two locations in spherical coordinates
# (1, theta, phi) and (1, theta, phi)
# cosine( arc length ) =
# sin phi sin phi' cos(theta-theta') + cos phi cos phi'
# distance = rho * arc length
cos = (math.sin(phi1)*math.sin(phi2)*math.cos(theta1 - theta2) +
math.cos(phi1)*math.cos(phi2))
arc = math.acos(cos)
# Remember to multiply arc by the radius of the earth
# in your favorite set of units to get length.
return arc * EARTH_RADIUS_MILES
示例8: 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
示例9: update
def update(self):
if self.turning_right:
self.rot -= 5
if self.turning_left:
self.rot += 5
a = [0.0,0.0]
if self.boost_endtime > rabbyt.get_time():
f = 3*(self.boost_endtime - rabbyt.get_time())/self.boost_length
a[0] += cos(radians(self.boost_rot))*f
a[1] += sin(radians(self.boost_rot))*f
self.create_boost_particle()
if self.accelerating:
a[0] += cos(radians(self.rot))*.9
a[1] += sin(radians(self.rot))*.9
self.create_dust_particle(self.dust_r)
self.create_dust_particle(self.dust_l)
ff = .9 # Friction Factor
self.velocity[0] *= ff
self.velocity[1] *= ff
self.velocity[0] += a[0]
self.velocity[1] += a[1]
self.x += self.velocity[0]
self.y += self.velocity[1]
示例10: 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
示例11: __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)
示例12: 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
示例13: 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
示例14: 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
示例15: __init__
def __init__(self,pos,direction,d_range):
self.surface = pygame.surface.Surface((50,50))
self.surface.fill((0,250,200))
self.rect = pygame.rect.Rect(pos[0],pos[1],50,50)
self.dir = direction
self.dist = 0
self.range = d_range
speed = 2
dx = 0
dy = 0
if self.dir>0:
if self.dir>90:
dy = speed*math.sin(180-self.dir)
dx = speed*math.cos(180-self.dir)
else:
dy = speed*math.sin(self.dir)
dx = speed*math.cos(self.dir)
else:
if self.dir<-90:
dy = speed*math.sin(180+self.dir)
dx = speed*math.cos(180+self.dir)
else:
dy = speed*math.sin(self.dir)
dx = speed*math.cos(self.dir)
self.dx = dx
self.dy = dy