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


Python math.abs函数代码示例

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


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

示例1: sameCoords

 def sameCoords(self,point,absolute=True,tol=1e-12):
     if absolute:
         return (point.get_x()==self._x and point.get_y()==self._y)
     else:
         xequiv=math.abs((self.get_x()/point.get_x())-1.)<tol
         yequiv=math.abs((self.get_y()/point.get_y())-1.)<tol
         return xequiv and yequiv
开发者ID:GeoWill,项目名称:Raster,代码行数:7,代码来源:Points.py

示例2: findR

    def findR(self, Vtarget, theta, phi):
        """
        This function finds the radius at which the zero velocity potential equals 
        targetV in the direction (theta, phi).  The radius is given as a 
        fraction of a. NOTE: This function only works if the target potential 
        is less than the potential at the Roche lobe.
        """
        if( Vtarget > systemparams.VL1 ): 
            print("Attempted to find a point outside the Roche lobe in findR).")

        epsilonr = 1.0e-7 * systemparams.a
        r = 0.8 * systemparams.rL1
        for i in range(100):
            if i ==100:
                print("Too many iterations in findR.")
            Vplus  = self.V( r + epsilonr, theta, phi)
            Vminus = self.V( r - epsilonr, theta, phi)
            Vzero  = self.V( r,           theta, phi)
            slope = (Vplus - Vminus) / (2.0 * epsilonr)
            if slope == 0.0:
                slope = 100.0 * Vzero / systemparams.a
            deltar = (Vtarget - Vzero) / slope
            if( math.abs(deltar) > (0.05 * r) ): 
                deltar = (0.05 * r) * (deltar / math.abs(deltar))
            r = r + deltar 
            if( r >= systemparams.rL1 ):
                r = systemparams.rL1
            x = math.abs( (Vtarget - self.V(r, theta, phi)) / Vtarget )
            if( x <= 1.0e-6 ):
                break
            return r
开发者ID:akshayah3,项目名称:XRbinary,代码行数:31,代码来源:star2.py

示例3: estimate

    def estimate(self, xOther, yOther):
        goalx = xOther - self.x
        goaly = xOther - self.y
        # Manhattan distance
        d = math.abs(goalx) + math.abs(goaly)

        return (d)
开发者ID:pombredanne,项目名称:pynetgraph,代码行数:7,代码来源:graph.py

示例4: geo2tm

def geo2tm( dsttype, in_pt, out_pt ) :
	
	transform(GEO, dsttype, in_pt)
	delta_lon = in_pt.getX() - m_arLonCenter[dsttype]
	sin_phi = math.sin(in_pt.getY())
	cos_phi = math.cos(in_pt.getY())

	if (m_Ind[dsttype] != 0) :
		b = cos_phi * math.sin(delta_lon)

		if ((math.abs(math.abs(b) - 1.0)) < EPSLN) :
			pass
			#Log.d("infinite error")
			#System.out.println("infinite error")

	else :
		b = 0
		x = 0.5 * m_arMajor[dsttype] * m_arScaleFactor[dsttype] * math.log((1.0 + b) / (1.0 - b))
		con = math.acos(cos_phi * math.cos(delta_lon) / math.sqrt(1.0 - b * b))

		if (in_pt.getY() < 0) :
			con = con * -1
			y = m_arMajor[dsttype] * m_arScaleFactor[dsttype] * (con - m_arLatCenter[dsttype])
	
	al = cos_phi * delta_lon
	als = al * al
	c = m_Esp[dsttype] * cos_phi * cos_phi
	tq = math.tan(in_pt.getY())
	t = tq * tq
	con = 1.0 - m_Es[dsttype] * sin_phi * sin_phi
	n = m_arMajor[dsttype] / math.sqrt(con)
	ml = m_arMajor[dsttype] * mlfn(e0fn(m_Es[dsttype]), e1fn(m_Es[dsttype]), e2fn(m_Es[dsttype]), e3fn(m_Es[dsttype]), in_pt.getY())

	out_pt.setX( m_arScaleFactor[dsttype] * n * al * (1.0 + als / 6.0 * (1.0 - t + c + als / 20.0 * (5.0 - 18.0 * t + t * t + 72.0 * c - 58.0 * m_Esp[dsttype]))) + m_arFalseEasting[dsttype] )
	out_pt.setY( m_arScaleFactor[dsttype] * (ml - dst_m[dsttype] + n * tq * (als * (0.5 + als / 24.0 * (5.0 - t + 9.0 * c + 4.0 * c * c + als / 30.0 * (61.0 - 58.0 * t + t * t + 600.0 * c - 330.0 * m_Esp[dsttype]))))) + m_arFalseNorthing[dsttype] )
开发者ID:hongry18,项目名称:python-geo-converter,代码行数:35,代码来源:GeoConverter.py

示例5: r8_aint

def r8_aint ( x ):

#****************************************************************************80
#
## R8_AINT truncates an R8 argument to an integer.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license. 
#
#  Modified:
#
#    24 July 2014
#
#  Author:
#
#    John Burkardt.
#
#  Parameters:
#
#    Input, real X, the argument.
#
#    Output, real VALUE, the truncated version of X.
#
  from math import abs
  from math import floor

  if ( x < 0.0 ):
    value = - floor ( abs ( x ) )
  else:
    value =   floor ( abs ( x ) )

  return value
开发者ID:johannesgerer,项目名称:jburkardt-py,代码行数:33,代码来源:r8_aint.py

示例6: heuristicMD

 def heuristicMD(self, node):
     """
     Heuristic function being used. Calculates the manhattan distance between node and end.
     @param node. The current node being searched
     @returns Integer. The manhattan distance.
     """
     return abs(node.x - self.endNode.x) + abs(node.y - self.endNode.y)
开发者ID:hakloev,项目名称:TDT4136-ai-intro,代码行数:7,代码来源:astar1.py

示例7: getCoord

 def getCoord(self,position):
     x,y = position
     dx,dy = self.position
     dist = sqrt( abs(x - dx)**2  + abs(y - dy)**2 )
     if dist%int(dist) > 0:
         dist = int(dist) + 1
     self.currentStep = dist
开发者ID:HqWisen,项目名称:HashCode2016,代码行数:7,代码来源:drone.py

示例8: SpreadValueAcrossAllComponents

    def SpreadValueAcrossAllComponents(self, val):

        temp = val/3
        for i in range(len(self.components)):
            if (self.components[i] < 0):
                self.components[i] -= abs(temp)
            else:
                self.components[i] += abs(temp)
开发者ID:Davenport-Physics,项目名称:CS-Volume,代码行数:8,代码来源:vector.py

示例9: getDistance

	def getDistance(self, l1, l2):
		dx = math.abs(l1.x - l2.x)
		dy = math.abs(l1.y - l2.y)
		if dx > self.width / 2:
			dx = self.width - dx
		if dy > self.height / 2:
			dy = self.height - dy
		return dx + dy
开发者ID:chmullig,项目名称:Halite,代码行数:8,代码来源:hlt.py

示例10: getDistance

	def getDistance(self, l1, l2):
		dx = math.abs(l1.x - l2.x)
		dy = math.abs(l1.y - l2.y)
		if dx > self.map_width / 2:
			dx = self.map_width - dx
		if dy > self.map_height / 2:
			dy = self.map_height - dy
		return math.sqrt((dx*dx) + (dy*dy))
开发者ID:bwignall,项目名称:Halite,代码行数:8,代码来源:hlt.py

示例11: parse_hole_coordinates

def parse_hole_coordinates(hole_vertices):
    hole_vertices.gsub!(/[\[\],]/, ' ')
    hole_vertices = hole_vertices.split(" ").to_a
    hole_vertices.map! { |e| e.to_i }

    x = math.abs(hole_vertices[0] - hole_vertices[2])
    y = math.abs(hole_vertices[1] - hole_vertices[3])

    return x, y
开发者ID:StevenDunn,项目名称:CodeEval,代码行数:9,代码来源:bp.py

示例12: horizontal_update_ball

 def horizontal_update_ball(self, ball_pos):
     """ Update horizontal ball position """
     global speed_factor
     updated_ball_pos = ball_pos
     if (updated_ball_pos[0] <= self.PAD_WIDTH + self.BALL_RADIUS):
         # The ball is at the left edge.
         # For bouncing: Change direction of movement, before update
         self.global_ball_vel[0]= - self.global_ball_vel[0]
         # Calculation without making use of geometric distance formula: 
         # Does the ball hit the paddle?
         #
         # If at the moment where the ball touches the gutter,
         # and if the vertical distance is as big as or bigger as the 
         # "sum of ball radius and half of the paddle", 
         # the ball would not touch the paddle when passing by...
         #
         if  (math.abs(updated_ball_pos[1]-self.paddle1_pos) >= (self.HALF_PAD_HEIGHT+self.BALL_RADIUS)):
             self.score2 += 1
             self.ball_init(True)
         else:
             # Requirement 11 "To moderately increase the difficulty of your game,
             # increase the velocity of the ball by 10% each time
             # it strikes a paddle"
             self.speed_factor *= 1.1 
     else:
         if (updated_ball_pos[0] >= self.WIDTH - self.PAD_WIDTH - self.BALL_RADIUS):
             # The ball is at the right edge.
             # For bouncing: Change direction of movement, before update
             self.global_ball_vel[0]= - self.global_ball_vel[0]
             # Calculation without making use of geometric distance formula: 
             # Does the ball hit the paddle?
             #
             # If at the moment where the ball touches the gutter,
             # and if the vertical distance is as big as or bigger as the 
             # "sum of ball radius and half of the paddle", 
             # the ball would not touch the paddle when passing by...
             #
             if  (math.abs(updated_ball_pos[1]-self.paddle2_pos) >= (self.HALF_PAD_HEIGHT+self.BALL_RADIUS)):
                 self.score1 += 1
                 self.ball_init(False)
             else:
                 # Requirement 11 "To moderately increase the difficulty of your game,
                 # increase the velocity of the ball by 10% each time
                 # it strikes a paddle"
                 self.speed_factor *= 1.1 
         else:
             # Ball is not too much right or left
             # Just update horizontal position
             pass
     # update anyhow 
     # by this the ball gets out of the limits,
     # so that out-of-limits is not detected with next cycle
     # and we must not check the direction of the ball velocity
     updated_ball_pos[0] +=self.global_ball_vel[0]
     return updated_ball_pos
开发者ID:hemmerling,项目名称:python-coursera2012,代码行数:55,代码来源:pong.py

示例13: pmv_hoppe_iso

def pmv_hoppe_iso( t, rh, wind, mtrad, iclo):
	eta = 0.01; # Mechanical efficiency
	age = 35.0; # Age
	mbody = 75.0; # Weigth in kg
	ht = 1.75; # Heigth in m
	tcl = 30.005
	MAX_LOOP = 200
	MAX_LOOP_HALF = MAX_LOOP / 2
	tcl_eps = 0.05
	eps = 0.97
	sigm = 5.67e-8
	adu = 0.203 * math.pow(mbody, 0.425) * math.pow(ht, 0.725)
	metbf = 3.19 * math.pow(mbody, (3.0/4.0)) * (1.0 + 0.004* (30.0- age)+0.018 * ((ht * 100.0/ math.pow(mbody, (1.0/3.0))) - 42.1)) 
	metbm = 3.45 * math.pow(mbody, (3.0/4.0)) * (1.0 + 0.004* (30.0- age)+0.010 * ((ht * 100.0/ math.pow(mbody, (1.0/3.0))) - 43.4)) 
	vpa = (rh / 100) * 6.105 * math.pow(2.718281828, ( 17.27*t / ( 237.7 + t ) ))
	fcl = 1.0 + iclo * 0.15
	metb = metabolism(t)
	metf = metbf + metb
	metm = metbm + metb
	metb = (metf+metm)/2.0
	h = metb * (1.0 - eta)
	aef = 0.71 * fcl * adu
	p1 = 35.7 - 0.032 * (metb / (adu * 1.16))* (1 - eta)
	tcl1 = tcl
	for x in range(0, MAX_LOOP_HALF):
		if x < MAX_LOOP_HALF:
			hc = 12.06 * math.sqrtf(wind)
			abhc = 0.0
		else:
			hc = 2.38 * math.pow(fabsf(tcl1 - t), 4.0)
			abhc = 0.6 * fabsf(math.pow((tcl1 - t), -0.75))
		
		tcl2 = p1 - 0.155 * iclo * (3.94 * 0.00000001* fcl *(math.pow((tcl1 + 273.2),4.0)- math.pow((mtrad+ 273.2), 4.0))+fcl * hc* (tcl1 - t))
		diff = math.abs(tcl1 - tcl2)
		if diff < tcl_eps:
			break
		abtcl = -0.155 * iclo * (4.0 * 3.94* 0.00000001* fcl *math.pow((tcl1+ 273.2),3.0) + fcl * hc- fcl *(tcl1 - t)* abhc)- 1.0
		tcl1 = tcl1 - (tcl2 - tcl1) / abtcl
		difhc = (12.06 * math.sqrt(wind)) - (2.38 * (math.pow(math.abs(t - tcl1), 0.25)))
		if difhc > 0.0 and i == MAX_LOOP_HALF:
			break
	tsk = 35.7 - (0.028 * h / adu)
	esw = 0.42 * adu * (h / adu - 58.08)
	if esw  < 0.0: 
		esw= 0.0
	rsum = aef * eps * sigm * (math.pow((tcl1 + 273.2), 4.0) - math.pow((mtrad + 273.2),4.0))
	csum = adu * fcl * hc * (tcl1 - t)
	erel = 0.0023 * metb * (44.0 - 0.75 * vpa)
	eres = 0.0014 * metb * (34.0 - t)
	ed = 0.406 * adu * (1.92 * tsk - 25.3- 0.75 * vpa)
	load = (h - ed - erel - eres - esw - rsum - csum) / adu
	ts = (0.303 * math.expf(-0.036 * (metb / adu)) + 0.028)
	pmv= ts * load
	return pmv
开发者ID:alfcrisci,项目名称:PorcellinoBot,代码行数:54,代码来源:pymeteosalute.py

示例14: Execute

	def Execute(COMMON, XOUT, PAR, WRK, DOF):
		x1 = DOF[1]+PAR[1]
		y1 = DOF[2]+PAR[2]
		x2 = DOF[4]+PAR[3]
		y2 = DOF[5]+PAR[4]
		x3 = DOF[7]+PAR[5]
		y3 = DOF[8]+PAR[6]
		x4 = DOF[10]+PAR[7]
		y4 = DOF[11]+PAR[8]
		
		d = (x2-x1)*(y4-y3)-(x4-x3)*(y2-y1)
		d1= (x3-x1)*(y4-y3)-(x4-x3)*(y3-y1)
		d2 = (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)
		
		if (math.abs(d)<1e-8):
			XOUT[1] =0.0
			XOUT[2] =0.0
			XOUT[3] =0.0
			res = return_result(COMMON, XOUT, WRK)
			return res
		
		t1 = d1/d
		t2 = d2/d

#check!	
		f1 = (x2-x1)*t1+(x4-x3)*t2- (x3-x1)
		f2 = (y2-y1)*t1+(y4-y3)*t2- (y3-y1)
		
		if (math.abs(f1)>1e-8 | math.abs(f2)>1e-5):
			print 'Wrong linear system calculation'
			
		if (t1>0.0):
			r1 = t1-1.0
		else:
			r1 = - t1
		
		if (t2>0.0):
			r2 = t2-1.0
		else:
			r2 = - t2
		
		r = r1 + r2

		if (r1<WRK[1]):
			WRK[1] = r1		
		if (r2<WRK[2]):
			WRK[2] = r2		
		
		XOUT[1] =r
		XOUT[2] =r1
		XOUT[3] =r2
	
		res = return_result(COMMON, XOUT, WRK)
		return res
开发者ID:MSTU,项目名称:grid,代码行数:54,代码来源:LINESINTERSECTION.py

示例15: update_center_and_radius

    def update_center_and_radius(self):

        n = len(self.members.keys())
        if ( n == 0 ):
            return
        R = 6371
        c_x = 0
        c_y = 0
        c_z = 0

        center = {}

        for user_id in self.members:
            location = self.members[user_id]["location"]
            latitude = math.radians(location["lat"])
            longitude = math.radians(location["long"])

            x = math.cos(latitude) * math.cos(longitude) * R
            y = math.cos(latitude) * math.sin(longitude) * R
            z = math.sin(latitude) * R

            c_x += x
            c_y += y
            c_z += z

        c_x /= n
        c_y /= n
        c_z /= n

        if ( ( math.fabs(c_x) < math.pow(10, -9) )
          and ( math.abs(c_y) < math.pow(10, -9) )
          and ( math.abs(c_z) < math.pow(10, -9) ) ):
            center["lat"] = 40.866667
            center["long"] = 34.566667
        else:
            hyp = math.sqrt(math.pow(c_x, 2) + math.pow(c_y, 2)) 
            center["lat"] = math.degrees(math.atan2(c_z, hyp))
            center["long"] = math.degrees(math.atan2(c_y, c_x))

        self.center = center

        radius = ChatRoom.MIN_RADIUS

        for user_id in self.members:
            location = self.members[user_id]["location"]
            distance = ChatRoom.distance(center, location)
            if ( distance > radius ):
                radius = distance + (ChatRoom.MIN_RADIUS / 3)

        self.radius = radius

        ChatRoom.assign_tags(self, None)
开发者ID:guilhermesgb,项目名称:aki-server,代码行数:52,代码来源:chat_rooms_public.py


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