本文整理汇总了Python中java.lang.Math.cos方法的典型用法代码示例。如果您正苦于以下问题:Python Math.cos方法的具体用法?Python Math.cos怎么用?Python Math.cos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.Math
的用法示例。
在下文中一共展示了Math.cos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: move
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def move(this):
if not this._first_time and this._explore_ttl:
this._explore_ttl -=1
if not this._explore_ttl % 50:
d('explore: '+str(this._explore_ttl))
if not this._explore_ttl:
this.me.setBehavior(exploring)
return
if this._join_ttl:
this._join_ttl -= 1
if this._join_ttl:
return
else:
sumx = sumy = 0
for p in this._join_points:
sumx += p[0]
sumy += p[1]
this._join_direction = self.towards(sumx/len(this._join_points), sumy/len(this._join_points))
this._first_time = 0
if not this._cached and len(this.me._killers) > 0:
if this._first_time:
for pos in this.resolve(this.me._killers, this.getCircle(len(this.me._killers), security_radius)):
k = this.me.getKillerByName(pos[0].getName())
k.setPosition(pos[1][0], pos[1][1])
this._cached = 1
else:
x = Math.cos(this._join_direction*Math.PI/180) * security_radius
y = Math.sin(this._join_direction*Math.PI/180) * security_radius
for pos in this.resolve(this.me._killers, this.getHalfCircle(len(this.me._killers), security_radius, x, y)):
k = this.me.getKillerByName(pos[0].getName())
k.setPosition(pos[1][0], pos[1][1])
this._cached = 1
this.sendCache()
示例2: bug_vector_x
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def bug_vector_x(percept, dist, scale, theta, p):
r = percept.getRadius() / 2
return (
Math.cos(deg2pi(180 + self.towards(percept.getX() + r, percept.getY() + r)))
* theta
/ Math.pow((dist / scale), p)
)
示例3: update_distances
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def update_distances():
covered=self.getCoveredDistance()
last_angle=mvt_mem.last_heading - deg_val(mvt_mem.direction)
toterm("la"+str(last_angle)+"lh"+str(mvt_mem.last_heading)+"di"+str(deg_val(mvt_mem.direction)))
ortho_increment=covered*Math.sin(last_angle)
dist_increment=covered*Math.cos(last_angle)
mvt_mem.valuable_distance += dist_increment
mvt_mem.orthogonal_error += ortho_increment
示例4: miseAJourMouvement
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def miseAJourMouvement():
# Mouvement normal et mise a jour des coordonnees
alpha = self.getHeading() * Math.PI / 180
depl_x = 2*Math.cos(alpha)
depl_y = 2*Math.sin(alpha)
if not self.isMoving():
self.randomHeading()
else:
coordonnees.setCoord(coordonnees.getX() + depl_x, coordonnees.getY() + depl_y)
示例5: compute_heading
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def compute_heading ():
if (mvt_mem.direction=="EAST"):
x_modifier=2000
y_modifier=0
elif (mvt_mem.direction=="WEST"):
x_modifier=-2000
y_modifier=0
elif (mvt_mem.direction=="SOUTH"):
x_modifier=0
y_modifier=+2000
elif (mvt_mem.direction=="NORTH"):
x_modifier=0
y_modifier=-1000
# on construit une liste de TOUS les objets répulsifs
repulsives = percepts.attackers.items () + \
percepts.explorers.items () + \
percepts.homes.items () + \
percepts.friends.items () + \
percepts.obstacles.items ()
# valeurs magiques
theta = 140
scale = 25
p = 2
u = 30
# composantes X et Y du vecteur direction final
X = 0
Y = 0
if repulsives:
for it, dist in repulsives:
X = X + Math.cos (deg2pi (180 + self.towards (it.getX(), it.getY()))) * theta / Math.pow (dist/scale, p)
Y = Y + Math.sin (deg2pi (180 + self.towards (it.getX(), it.getY()))) * theta / Math.pow (dist/scale, p)
toterm ("AFTER REPULSION:"+str(X) +" "+ str(Y))
X = X + Math.cos (deg2pi ( self.getHeading() ))*u
Y = Y + Math.sin (deg2pi ( self.getHeading() ))*u
toterm ("AFTER ATTRACTION:"+str(X) +" "+ str(Y))
X+=x_modifier
Y+=y_modifier
toterm ("NEW HEADING : "+str(self.towards (X, Y)))
self.setHeading (self.towards (X, Y))
示例6: getHalfCircle
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def getHalfCircle(this, num, radius, x, y):
if num == 1:
return [[x,y]]
axe = self.towards(x, y)
rayon = radius * (1 - Math.exp(-num/3))
offset = Math.PI / (num-1)
points = []
for i in range(num):
X = rayon*Math.cos(i*offset+Math.PI/2+axe*Math.PI/180)+x
Y = rayon*Math.sin(i*offset+Math.PI/2+axe*Math.PI/180)+y
points.append([X,Y])
return points
示例7: getCircle
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def getCircle(this, num, radius):
if num == 0:
return None
if num == 1:
return [[50,50]]
rayon = radius * (1 - Math.exp(-num/3))
offset = 2*Math.PI / num
points = []
for i in range(num):
X = rayon*Math.cos(i*offset)
Y = rayon*Math.sin(i*offset)
points.append([X,Y])
return points
示例8: skitter
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def skitter(_field):
_maxangle = 2 * Math.PI
_ordering = sortBy(_field)
_increment = _maxangle / len(_ordering)
_curangle = 0
g.nodes[0].outdegree
_maxdeg = outdegree.max + 1.0
for _n in _ordering:
_radius = 1 - Math.log((_n.outdegree + 1.0) / _maxdeg)
_radius = _radius * 500.0
_x = 500.0 + _radius * Math.cos(_curangle)
_y = 500.0 + _radius * Math.sin(_curangle)
_n.setX(_x)
_n.setY(_y)
_curangle += _increment
示例9: gene
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def gene(cible, p):
taille = 12
if p.getPerceptType() == "Home":
taille = 20
# Distance par rapport au tir
angle = self.towards(cible.getX(), cible.getY())
angle = Math.PI * angle / 180
t = Math.tan(angle)
s = Math.sin(angle)
c = Math.cos(angle)
dist_x = ( p.getX() + t* p.getY()) / (c + s * t)
dist_y = -p.getY()/c + t * dist_x
#print self.getAddress().getName() + " --> " + str(dist_x) + " --- " + str(dist_y)
return abs(dist_y) < taille and dist_x > 0 and dist_x< cible.distanceTo(Point())
示例10: setTrajectoire
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def setTrajectoire(this):
if this._explore:
if not self.isMoving() or self.getHeading() == 0:
self.randomHeading()
return
decalx = decaly = 0
for p in self.getPercepts():
type = p.getPerceptType()
dist = p.getDistance()
if dist < redirect_distance and p.getTeam() == self.getTeam() and (type == 'Home' or type == 'RocketLauncher' or type == 'Explorer'):
decalx += p.getX() / dist * (70-dist) / 120
decaly += p.getY() / dist * (70-dist) / 120
#~ d('distance: '+str(dist))
#~ d('direction originelle: '+str(self.towards(this._destX, this._destY)))
#~ d('direction modifiee: '+str(self.towards(Math.cos(self.towards(this._destX, this._destY))-decalx, Math.sin(self.towards(this._destX, this._destY))-decaly)))
self.setHeading(self.towards(Math.cos(self.towards(this._destX, this._destY)*Math.PI/180)-decalx, Math.sin(self.towards(this._destX, this._destY)*Math.PI/180)-decaly))
示例11: eviteAmis
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def eviteAmis(percepts):
dist1 = dist2 = 500
taille_robot = 20
liste_obstacles = []
for p in percepts:
centre = Point()
centre.setCoord(p.getX(), p.getY())
liste_obstacles.append(centre)
# on dessine 2 droite paralleles a la direction
# qui partent des bords du robot -> d1 : y = 12 et d2 : y = -12
# Dans nouveau repere : origine = self
# rotation du repere de l"angle de direction courant
direction = self.getHeading()
angle = Math.PI * direction / 180
t = Math.tan(angle)
s = Math.sin(angle)
c = Math.cos(angle)
for p in liste_obstacles:
# centre_x, centre_y : centre de l"obstacle dans le repere
centre_x = ( p.getX() + t* p.getY()) / (c + s * t)
centre_y = -p.getY()/c + t * centre_x
# savoir quelle droite prendre
if centre_x > 0:
if centre_y >= 0 and centre_y <= 2*taille_robot:
y = centre_y - taille_robot
dist1 = min(dist1,-Math.sqrt(taille_robot*taille_robot - y*y) + centre_x)
elif centre_y < 0 and centre_y >= -(2*taille_robot):
y = centre_y + taille_robot
dist2 = min(dist2,-Math.sqrt(taille_robot*taille_robot - y*y) + centre_x)
if min(dist1, dist2) <= 100 and abs(dist1 - dist2) > 2:
if dist1 < dist2:
direction += 100/dist1
else:
direction -= 100/dist2
self.setHeading(direction)
示例12: compute_heading
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def compute_heading (target, mode):
# composantes X et Y du vecteur direction final
X = Y = 0
for it, dist in percepts.friends.items ():
# percept, dist, scale, theta, p
X = X + vector_x (it, dist, 50, 60, 2)
Y = Y + vector_y (it, dist, 50, 60, 2)
for it, dist in percepts.bases.items ():
# Les bases sont boguées : repère sur le coin
# supérieur gauche
X = X + bug_vector_x (it, dist, 60, 70, 2)
Y = Y + bug_vector_y (it, dist, 60, 70, 2)
for it, dist in percepts.attackers.items ():
# devrait être négligeable...
X = X + vector_x (it, dist, 30, 70, 2)
Y = Y + vector_y (it, dist, 30, 70, 2)
for it, dist in percepts.explorers.items ():
X = X + vector_x (it, dist, 20, 60, 1)
Y = Y + vector_y (it, dist, 20, 60, 1)
for it, dist in percepts.homes.items ():
X = X + bug_vector_x (it, dist, 60, 70, 2)
Y = Y + bug_vector_y (it, dist, 60, 70, 2)
for it, dist in percepts.obstacles.items ():
radius = it.getRadius ()
X = X + vector_x (it, dist, 50+radius, 60, 2)
Y = Y + vector_y (it, dist, 50+radius, 60, 2)
# pour la cible
if mode == 'flee':
offset = 180
u = 12 # on s'arrache viiiiite !!
else:
offset = 0
u = 8
X = X + Math.cos (deg2pi (offset + self.towards (target.getX(), target.getY()))) * u * target.getDistance ()
Y = Y + Math.sin (deg2pi (offset + self.towards (target.getX(), target.getY()))) * u * target.getDistance ()
if immobile ():
toterm ("immobile")
self.setHeading (self.towards (X, Y))
示例13: isMasqued
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def isMasqued(x, y):
# on ne tire pas si un #@! de copain se trouve devant (verification des percepts seulement ?)
for p in self.getPercepts():
if p.getTeam() == self.getTeam() and p.getPerceptType() != 'Rocket':
if distance(p.getX(), p.getY()) > distance(x, y):
continue
a = self.towards(p.getX(), p.getY())*Math.PI/180
b = self.towards(x, y)
r = p.getRadius() + security_distance
cos = Math.cos(a - Math.PI/2)
sin = Math.sin(a - Math.PI/2)
inf = self.towards(p.getX() + r*cos, p.getY() + r*sin)
sup = self.towards(p.getX() - r*cos, p.getY() - r*sin)
#~ d('ene: x: '+str(x)+' y: '+str(y)+' A: '+str(b)+' a: '+str(b*Math.PI/180))
#~ d(' s: '+str(p.getX() + r*cos)+':'+str(p.getY() + r*sin)+' t: '+str(p.getX() - r*cos)+':'+str(p.getY() - r*sin))
#~ d('ami: x: '+str(p.getX())+' y: '+str(p.getY())+' A: '+str(a*180/Math.PI)+' a: '+str(a)+' r: '+str(r))
#~ d('ne pas tirer ene(A) entre '+str(inf)+' et '+str(sup))
#~ d('angles relatifs: ami: '+str((sup - inf) % 360)+' enemy: '+str((b - inf) % 360 ))
if ((b - inf) % 360 ) > ((sup - inf) % 360):
#~ d('boom!')
continue
#~ d('un ami me cache la cible!')
return 1
return 0
示例14: cos
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
# 2) The PlotXY axis system assumes that coordinates are a linear
# transformation of pixel coordinates. So coordinates on the plotted axes
# are not fully correct in some projections. They are correct only for small
# angles near the projection reference.
# Extract the WCS of the map and put some WCS info into variables
wcs=map.wcs
crpix1=wcs.crpix1
crpix2=wcs.crpix2
crval1=wcs.crval1
crval2=wcs.crval2
cdelt1=wcs.cdelt1
cdelt2=wcs.cdelt2
naxis1=wcs.naxis1
naxis2=wcs.naxis2
# cos(Dec)
cosd=Math.cos(Math.toRadians(crval2))
# Set the origin and the scale of the axes so that they coincide with the WCS.
myPlot[0].xcdelt=cdelt1/cosd # note the cos(Dec)!!!
myPlot[0].ycdelt=cdelt2
myPlot[0].xcrpix=crpix1
myPlot[0].ycrpix=crpix2
myPlot[0].xcrval=crval1
myPlot[0].ycrval=crval2
# Change the axis type so that we have ticks in degrees/hours, min, sec
# and the RA growing toward the left.
myPlot.xaxis.type=Axis.RIGHT_ASCENSION
myPlot.yaxis.type=Axis.DECLINATION
myPlot.xaxis.titleText="Right Ascension (J2000)"
myPlot.yaxis.titleText="Declination (J2000)"
# Set the axes ranges so that the image fills completely the plotting area
xrange=[crval1-(crpix1-0.5)*cdelt1/cosd*0.1,\
示例15: doIt
# 需要导入模块: from java.lang import Math [as 别名]
# 或者: from java.lang.Math import cos [as 别名]
def doIt():
mem.t += 1
if not self.isMoving():
self.setHeading(mem.go())
percepts = self.getPercepts()
# Vecteurs d'evitement
aurax = auray = 0
# nombre d'obstacles, explorers amis, rocketlauncher ennemis vus
ob = expl = rl = 0
# objectif choisi (seulement nouriture)
pmin = 0
for p in percepts:
d = self.distanceTo(p)+.0001
t = p.getPerceptType()
if d < 40:
aurax += p.getX()/d *(40-d)/150
auray += p.getY()/d *(40-d)/150
if p.getTeam() != self.getTeam():
if t=='Home' or t=='Explorer':
mem.send(self, p)
elif t=='RocketLauncher':
rl += 1
mem.send(self, p)
if d < 150:
aurax += p.getX()/d *(150-d)/70
auray += p.getY()/d *(150-d)/70
elif t=='Food' and (pmin==0 or d <= self.distanceTo(pmin)):
pmin=p
elif t=='Rocket':
if d < 150:
aurax += p.getX()/d *(150-d)/150
auray += p.getY()/d *(150-d)/150
elif t=='Obstacle':
ob += 1
if d < 150:
aurax += p.getX()/d *(150-d)/150
auray += p.getY()/d *(150-d)/150
elif t=='Explorer':
if d < 150:
aurax += p.getX()/d *(150-d)/150
auray += p.getY()/d *(150-d)/150
expl += 1
# Gestion de la nouriture (non teste)
if pmin != 0:
if self.distanceTo(pmin)<2: #if close enough
self.eat(pmin) #eat it
return
else: #else go towards it
self.setHeading(self.towards(pmin.getX(),pmin.getY()))
self.move()
return
# Calcul du vecteur de deplacement en fonction des vecteurs de force
# et du cap a maintenir
aurax = Math.cos(mem.but*Math.PI/180) - aurax
auray = Math.sin(mem.but*Math.PI/180) - auray
t = self.towards(aurax,auray)
# Changement de l'objectif
if ob > 3 or expl > 0 or rl > 2:
mem.but = t
# Deplacement effectif
self.setHeading(t)
self.move()