本文整理汇总了Python中math._cos函数的典型用法代码示例。如果您正苦于以下问题:Python _cos函数的具体用法?Python _cos怎么用?Python _cos使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_cos函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _measure
def _measure(p1, p2, p3):
""" Return hypotenuse, ratio and theta for a trio of ordered points.
"""
ha, hb = _hypot(p3.x - p1.x, p3.y - p1.y), _hypot(p2.x - p1.x, p2.y - p1.y)
va, vb = Vector(p1, p2), Vector(p1, p3)
theta = _atan2(va.y, va.x)
x = vb.x * _cos(-theta) - vb.y * _sin(-theta)
y = vb.x * _sin(-theta) + vb.y * _cos(-theta)
ratio = ha / hb
theta = _atan2(y, x)
return hb, ratio, theta
示例2: rotate
def rotate(m,angle,v):
"""
:param m: should be colunm major
:param angle: in degree
:param v:
:return: in row major
"""
c = _cos(angle)
s = _sin(angle)
axis = normalize(v)
temp =(1. - c) * axis
Rotate = numpy.zeros((4, 4), 'f')
Rotate[0][0] = c + temp[0] * axis[0]
Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2]
Rotate[0][2] = 0 + temp[0] * axis[2] - s * axis[1]
Rotate[1][0] = 0 + temp[1] * axis[0] - s * axis[2]
Rotate[1][1] = c + temp[1] * axis[1]
Rotate[1][2] = 0 + temp[1] * axis[2] + s * axis[0]
Rotate[2][0] = 0 + temp[2] * axis[0] + s * axis[1]
Rotate[2][1] = 0 + temp[2] * axis[1] - s * axis[0]
Rotate[2][2] = c + temp[2] * axis[2]
Result = numpy.zeros((4, 4), 'f')
Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2]
Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2]
Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2]
Result[3] = m[3]
return Result.T
示例3: rotozoom
def rotozoom(self, surface, angle, size):
"""
Return Surface rotated and resized by the given angle and size.
"""
if not angle:
width = int(surface.getWidth()*size)
height = int(surface.getHeight()*size)
return self.scale(surface, (width, height))
theta = angle*self.deg_rad
width_i = int(surface.getWidth()*size)
height_i = int(surface.getHeight()*size)
cos_theta = _fabs( _cos(theta) )
sin_theta = _fabs( _sin(theta) )
width_f = int( _ceil((width_i*cos_theta)+(height_i*sin_theta)) )
if width_f % 2:
width_f += 1
height_f = int( _ceil((width_i*sin_theta)+(height_i*cos_theta)) )
if height_f % 2:
height_f += 1
surf = Surface((width_f,height_f), BufferedImage.TYPE_INT_ARGB)
at = AffineTransform()
at.translate(width_f/2, height_f/2)
at.rotate(-theta)
g2d = surf.createGraphics()
ot = g2d.getTransform()
g2d.setTransform(at)
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
g2d.drawImage(surface, -width_i//2, -height_i//2, width_i, height_i, None)
g2d.setTransform(ot)
g2d.dispose()
return surf
示例4: rotate
def rotate(self, surface, angle):
"""
Return Surface rotated by the given angle.
"""
if not angle:
return surface.copy()
theta = angle*self.deg_rad
width_i = surface.getWidth()
height_i = surface.getHeight()
cos_theta = _fabs( _cos(theta) )
sin_theta = _fabs( _sin(theta) )
width_f = int( (width_i*cos_theta)+(height_i*sin_theta) )
height_f = int( (width_i*sin_theta)+(height_i*cos_theta) )
surf = Surface((width_f,height_f), BufferedImage.TYPE_INT_ARGB)
at = AffineTransform()
at.translate(width_f/2, height_f/2)
at.rotate(-theta)
g2d = surf.createGraphics()
ot = g2d.getTransform()
g2d.setTransform(at)
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
g2d.drawImage(surface, -width_i//2, -height_i//2, None)
g2d.setTransform(ot)
g2d.dispose()
return surf
示例5: gauss
def gauss(self, mu, sigma):
# """Gaussian distribution.
# mu is the mean, and sigma is the standard deviation. This is
# slightly faster than the normalvariate() function.
# Not thread-safe without a lock around calls.
# """
# When x and y are two variables from [0, 1), uniformly
# distributed, then
#
# cos(2*pi*x)*sqrt(-2*log(1-y))
# sin(2*pi*x)*sqrt(-2*log(1-y))
#
# are two *independent* variables with normal distribution
# (mu = 0, sigma = 1).
# (Lambert Meertens)
# (corrected version; bug discovered by Mike Miller, fixed by LM)
# Multithreading note: When two threads call this function
# simultaneously, it is possible that they will receive the
# same return value. The window is very small though. To
# avoid this, you have to use a lock around all calls. (I
# didn't want to slow this down in the serial case by using a
# lock here.)
__random = self.random
z = self.gauss_next
self.gauss_next = None
if z is None:
x2pi = __random() * TWOPI
g2rad = _sqrt(-2.0 * _log(1.0 - __random()))
z = _cos(x2pi) * g2rad
self.gauss_next = _sin(x2pi) * g2rad
return mu + z*sigma
示例6: vonmisesvariate
def vonmisesvariate(self, mu, kappa):
"""Circular data distribution.
mu is the mean angle, expressed in radians between 0 and 2*pi, and
kappa is the concentration parameter, which must be greater than or
equal to zero. If kappa is equal to zero, this distribution reduces
to a uniform random angle over the range 0 to 2*pi.
"""
random = self.random
if kappa <= 1e-06:
return TWOPI * random()
s = 0.5 / kappa
r = s + _sqrt(1.0 + s * s)
while 1:
u1 = random()
z = _cos(_pi * u1)
d = z / (r + z)
u2 = random()
if u2 < 1.0 - d * d or u2 <= (1.0 - d) * _exp(d):
break
q = 1.0 / r
f = (q + z) / (1.0 + q * z)
u3 = random()
if u3 > 0.5:
theta = (mu + _acos(f)) % TWOPI
else:
theta = (mu - _acos(f)) % TWOPI
return theta
示例7: vonmisesvariate
def vonmisesvariate(self, mu, kappa):
random = self.random
if kappa <= 9.9999999999999995e-007:
return TWOPI * random()
a = 1.0 + _sqrt(1.0 + 4.0 * kappa * kappa)
b = (a - _sqrt(2.0 * a)) / 2.0 * kappa
r = (1.0 + b * b) / 2.0 * b
while 1:
u1 = random()
z = _cos(_pi * u1)
f = (1.0 + r * z) / (r + z)
c = kappa * (r - f)
u2 = random()
if u2 >= c * (2.0 - c):
pass
if not (u2 > c * _exp(1.0 - c)):
break
u3 = random()
if u3 > 0.5:
theta = mu % TWOPI + _acos(f)
else:
theta = mu % TWOPI - _acos(f)
return theta
示例8: rotozoom
def rotozoom(self, surface, angle, size):
"""
Return Surface rotated and resized by the given angle and size.
"""
if not angle:
width = int(surface.get_width()*size)
height = int(surface.get_height()*size)
return self.scale(surface, (width, height))
theta = angle*self.deg_rad
width_i = int(surface.get_width()*size)
height_i = int(surface.get_height()*size)
cos_theta = _fabs( _cos(theta) )
sin_theta = _fabs( _sin(theta) )
width_f = int( _ceil((width_i*cos_theta)+(height_i*sin_theta)) )
if width_f % 2:
width_f += 1
height_f = int( _ceil((width_i*sin_theta)+(height_i*cos_theta)) )
if height_f % 2:
height_f += 1
surf = Surface((width_f,height_f))
surf.saveContext()
surf.translate(width_f/2.0, height_f/2.0)
surf.rotate(-theta)
surf.drawImage(surface.canvas, 0, 0, surface.get_width(), surface.get_height(), -width_i/2, -height_i/2, width_i, height_i)
surf.restoreContext()
return surf
示例9: vonmisesvariate
def vonmisesvariate(self, mu, kappa):
"""Circular data distribution.
mu is the mean angle, expressed in radians between 0 and 2*pi, and
kappa is the concentration parameter, which must be greater than or
equal to zero. If kappa is equal to zero, this distribution reduces
to a uniform random angle over the range 0 to 2*pi.
"""
random = self.random
if kappa <= 1e-06:
return TWOPI * random()
a = 1.0 + _sqrt(1.0 + 4.0 * kappa * kappa)
b = (a - _sqrt(2.0 * a)) / (2.0 * kappa)
r = (1.0 + b * b) / (2.0 * b)
while 1:
u1 = random()
z = _cos(_pi * u1)
f = (1.0 + r * z) / (r + z)
c = kappa * (r - f)
u2 = random()
if u2 < c * (2.0 - c) or u2 <= c * _exp(1.0 - c):
break
u3 = random()
if u3 > 0.5:
theta = mu % TWOPI + _acos(f)
else:
theta = mu % TWOPI - _acos(f)
return theta
示例10: gauss
def gauss(self, mu, sigma):
random = self.random
z = self.gauss_next
self.gauss_next = None
if z is None:
x2pi = random() * TWOPI
g2rad = _sqrt(-2.0 * _log(1.0 - random()))
z = _cos(x2pi) * g2rad
self.gauss_next = _sin(x2pi) * g2rad
return mu + z * sigma
示例11: vonmisesvariate
def vonmisesvariate(self, mu, kappa):
"""Circular data distribution.
mu is the mean angle, expressed in radians between 0 and 2*pi, and
kappa is the concentration parameter, which must be greater than or
equal to zero. If kappa is equal to zero, this distribution reduces
to a uniform random angle over the range 0 to 2*pi.
"""
# mu: mean angle (in radians between 0 and 2*pi)
# kappa: concentration parameter kappa (>= 0)
# if kappa = 0 generate uniform random angle
# Based upon an algorithm published in: Fisher, N.I.,
# "Statistical Analysis of Circular Data", Cambridge
# University Press, 1993.
# Thanks to Magnus Kessler for a correction to the
# implementation of step 4.
random = self.random
if kappa <= 1e-6:
return TWOPI * random()
a = 1.0 + _sqrt(1.0 + 4.0 * kappa * kappa)
b = (a - _sqrt(2.0 * a)) / (2.0 * kappa)
r = (1.0 + b * b) / (2.0 * b)
while 1:
u1 = random()
z = _cos(_pi * u1)
f = (1.0 + r * z) / (r + z)
c = kappa * (r - f)
u2 = random()
if not (u2 >= c * (2.0 - c) and u2 > c * _exp(1.0 - c)):
break
u3 = random()
if u3 > 0.5:
theta = (mu % TWOPI) + _acos(f)
else:
theta = (mu % TWOPI) - _acos(f)
return theta
示例12: vonmisesvariate
def vonmisesvariate(self, mu, kappa):
"""Circular data distribution.
mu is the mean angle, expressed in radians between 0 and 2*pi, and
kappa is the concentration parameter, which must be greater than or
equal to zero. If kappa is equal to zero, this distribution reduces
to a uniform random angle over the range 0 to 2*pi.
"""
# mu: mean angle (in radians between 0 and 2*pi)
# kappa: concentration parameter kappa (>= 0)
# if kappa = 0 generate uniform random angle
# Based upon an algorithm published in: Fisher, N.I.,
# "Statistical Analysis of Circular Data", Cambridge
# University Press, 1993.
# Thanks to Magnus Kessler for a correction to the
# implementation of step 4.
random = self.random
if kappa <= 1e-6:
return TWOPI * random()
s = 0.5 / kappa
r = s + _sqrt(1.0 + s * s)
while 1:
u1 = random()
z = _cos(_pi * u1)
d = z / (r + z)
u2 = random()
if u2 < 1.0 - d * d or u2 <= (1.0 - d) * _exp(d):
break
q = 1.0 / r
f = (q + z) / (1.0 + q * z)
u3 = random()
if u3 > 0.5:
theta = (mu + _acos(f)) % TWOPI
else:
theta = (mu - _acos(f)) % TWOPI
return theta
示例13: gauss
def gauss(self, mu, sigma):
"""Gaussian distribution.
mu is the mean, and sigma is the standard deviation. This is
slightly faster than the normalvariate() function.
Not thread-safe without a lock around calls.
"""
random = self.random
z = self.gauss_next
self.gauss_next = None
if z is None:
x2pi = random() * TWOPI
g2rad = _sqrt(-2.0 * _log(1.0 - random()))
z = _cos(x2pi) * g2rad
self.gauss_next = _sin(x2pi) * g2rad
return mu + z * sigma
示例14: rotate
def rotate(self, surface, angle):
"""
Return Surface rotated by the given angle.
"""
if not angle:
return surface.copy()
theta = angle*self.deg_rad
width_i = surface.get_width()
height_i = surface.get_height()
cos_theta = _fabs( _cos(theta) )
sin_theta = _fabs( _sin(theta) )
width_f = int( (width_i*cos_theta)+(height_i*sin_theta) )
height_f = int( (width_i*sin_theta)+(height_i*cos_theta) )
surf = Surface((width_f,height_f))
surf.saveContext()
surf.translate(width_f/2.0, height_f/2.0)
surf.rotate(-theta)
surf.drawImage(surface.canvas, -width_i/2, -height_i/2)
surf.restoreContext()
return surf
示例15: vonmisesvariate
def vonmisesvariate(self, mu, kappa):
random = self.random
if kappa <= 1e-06:
return TWOPI*random()
s = 0.5/kappa
r = s + _sqrt(1.0 + s*s)
while True:
u1 = random()
z = _cos(_pi*u1)
d = z/(r + z)
u2 = random()
if u2 < 1.0 - d*d or u2 <= (1.0 - d)*_exp(d):
break
q = 1.0/r
f = (q + z)/(1.0 + q*z)
u3 = random()
if u3 > 0.5:
theta = (mu + _acos(f)) % TWOPI
else:
theta = (mu - _acos(f)) % TWOPI
return theta