当前位置: 首页>>代码示例>>Python>>正文


Python lang.Math类代码示例

本文整理汇总了Python中java.lang.Math的典型用法代码示例。如果您正苦于以下问题:Python Math类的具体用法?Python Math怎么用?Python Math使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Math类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: bug_vector_y

def bug_vector_y(percept, dist, scale, theta, p):
    r = percept.getRadius() / 2
    return (
        Math.sin(deg2pi(180 + self.towards(percept.getX() + r, percept.getY() + r)))
        * theta
        / Math.pow((dist / scale), p)
    )
开发者ID:hasanzorlu,项目名称:kalle-martin-group,代码行数:7,代码来源:SamMaxHomekiller.py

示例2: entropy

def entropy(domain):
  sume = 0
  chars = Counter(domain)
  N = len(domain)
  for n in chars.values():
    sume += - n / N * Math.log(n / N) / Math.log(2)
  return sume
开发者ID:GratefulTony,项目名称:app-malicious-domains,代码行数:7,代码来源:pymodule.py

示例3: move

	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()
开发者ID:Ooya,项目名称:Robot-Sapiens,代码行数:33,代码来源:TheBigOne.py

示例4: process

def process(input, position):
    size = len(input)
    output = copy.deepcopy(input)
    fft = DoubleFFT_1D(size)
    fft.realForward(output)
    for j in range(size/2):
        output[j]= Math.sqrt(Math.pow(output[2*j],2)+Math.pow(output[2*j+1],2));
    return output[:len(input)/2]
开发者ID:evaimg,项目名称:Icy-App,代码行数:8,代码来源:Jython_FFT_half.py

示例5: update_distances

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
开发者ID:peyotll,项目名称:warbot,代码行数:8,代码来源:SamMaxExplore.py

示例6: miseAJourMouvement

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)
开发者ID:peyotll,项目名称:warbot,代码行数:9,代码来源:BPVExplore.py

示例7: gemm

    def gemm(self, n):

        import time
        #from no.uib.cipr.matrix.nni import BLAS,LAPACK;
        from jarray import array, zeros
        from java.lang import Math, System
        import no.uib.cipr.matrix as matrix

        if n < 100:
            r = 100
        else:
            r = 10

        t = time.time()

        #A = zeros(n*n,'d')
        #B = zeros(n*n,'d')
        #C = zeros(n*n,'d')

        pin = range(n*n)

        #for i in pin:
        #    A[i] = Math.random();
        #    B[i] = Math.random();
        #    C[i] = Math.random();

        A = matrix.Matrices.random(n,n);
        B = matrix.Matrices.random(n,n);
        C = matrix.Matrices.random(n,n);


        alpha = Math.random()
        beta = Math.random()

        print "Random numbers time: "+str((time.time() - t))

        for i in range(10):
            #BLAS.gemm(BLAS.ColMajor, BLAS.NoTrans, BLAS.NoTrans, n, n, n, alpha, A, n, B, n, beta, C, n)
            A.multAdd(alpha,B, C)
            C.scale(beta);
            #E=D.mult(C, C.copy())

        t = time.time()

        for i in range(r):
            #BLAS.gemm(BLAS.ColMajor, BLAS.NoTrans, BLAS.NoTrans, n, n, n, alpha, A, n, B, n, beta, C, n)
            #D=A.mult(B, B.copy()); E=D.mult(C, C.copy());
            A.multAdd(alpha,B, C)
            C.scale(beta);

        s = (time.time() - t)
        print s
        f = 2 * (n + 1) * n * n
        mfs = (f / (s * 1000000.0)) * r

        print str(mfs)
开发者ID:gidiko,项目名称:gridapp,代码行数:56,代码来源:examples.py

示例8: arcTo

def arcTo(self, cx, cy, p2x, p2y):
	"""Adds a segment from the current position to p2x, p2y by drawing part of a circle centered on 'cx,cy'"""
	p1x, p1y = self.nodes[-1].position2()
	angle1 = Math.atan2(-(p1y-cy), p1x-cx)
	angle2 = Math.atan2(-(p2y-cy), p2x-cx)
	if (angle2-angle1>Math.PI):
		angle2-=Math.PI*2
	if (angle2-angle1<-Math.PI):
		angle2+=Math.PI*2
	self.arc(Math.sqrt( (p1x-cx)*(p1x-cx)+(p1y-cy)*(p1y-cy)), cx,cy, angle1, angle2, join=1)
	return self
开发者ID:EQ4,项目名称:Field,代码行数:11,代码来源:NewCachedLines.py

示例9: getHalfCircle

	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
开发者ID:Ooya,项目名称:Robot-Sapiens,代码行数:12,代码来源:TheBigOne.py

示例10: longJumps

def longJumps(t, mindist):
  for nd in t.getRoot().getSubtreeNodes():
    if nd.parent is None:
      continue
    d = Math.sqrt(Math.pow(nd.x - nd.parent.x, 2) + Math.pow(nd.y - nd.parent.y, 2))
    if d > mindist:
      print nd.x, nd.y
      p = array([nd.x, nd.y], 'f')
      aff = t.affineTransform
      aff.transform(p, 0, p, 0, 1)
      cal = t.layerSet.getCalibration()
      print "Off:", p[0] * cal.pixelWidth, p[1] * cal.pixelHeight, (nd.layer.getParent().indexOf(nd.layer) + 1)
开发者ID:acardona,项目名称:Fiji-TrakEM2-scripts,代码行数:12,代码来源:long_jumps.py

示例11: getCircle

	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
开发者ID:Ooya,项目名称:Robot-Sapiens,代码行数:13,代码来源:TheBigOne.py

示例12: skitter

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
开发者ID:cns-iu,项目名称:nwb,代码行数:15,代码来源:Main-applet.py

示例13: gene

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())
开发者ID:Ooya,项目名称:Robot-Sapiens,代码行数:15,代码来源:BPVHomeKiller.py

示例14: render_shape_to_graphics

    def render_shape_to_graphics(self, shape):
        r = shape.getShapeRenderer()

        # Find the size that the shape will be rendered to at the specified scale and resolution.
        shapeSizeInPixels = r.getSizeInPixels(1.0, 96.0)

        # Rotating the shape may result in clipping as the image canvas is too small. Find the longest side
        # and make sure that the graphics canvas is large enough to compensate for this.
        maxSide = Math.max(shapeSizeInPixels.width, shapeSizeInPixels.height)

        image = BufferedImage(int(maxSide * 1.25), int(maxSide * 1.25), BufferedImage.TYPE_INT_ARGB)

        # Rendering to a graphics object means we can specify settings and transformations to be applied to
        # the shape that is rendered. In our case we will rotate the rendered shape.
        gr = image.getGraphics()

        # Clear the shape with the background color of the document.
        gr.setBackground(shape.getDocument().getPageColor())
        gr.clearRect(0, 0, image.getWidth(), image.getHeight())
        # Center the rotation using translation method below
        gr.translate(image.getWidth() / 8, image.getHeight() / 2)
        # Rotate the image by 45 degrees.
        gr.rotate(45 * Math.PI / 180)
        # Undo the translation.
        gr.translate(-image.getWidth() / 8, -image.getHeight() / 2)

        # Render the shape onto the graphics object.
        r.renderToSize(gr, 0, 0, shapeSizeInPixels.width, shapeSizeInPixels.height)

        ImageIO.write(image, "png", File(self.dataDir + "TestFile.RenderToGraphics.png"))

        gr.dispose()

        print "Shape rendered to Graphics successfully."
开发者ID:Aspose,项目名称:Aspose.Words-for-Java,代码行数:34,代码来源:RenderShapes.py

示例15: newElement

  def newElement(self):
    theta = Math.toRadians(self.angle)
    element = Element(self, complex(R0 * math.cos(theta), R0 * math.sin(theta)))

    self.angle = self.angle + self.forcedDivergence
    if self.angle > 360.0:
      self.angle = self.angle - 360.0

    return element
开发者ID:imclab,项目名称:tournesol,代码行数:9,代码来源:tournesol.py


注:本文中的java.lang.Math类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。