本文整理汇总了Python中Physics类的典型用法代码示例。如果您正苦于以下问题:Python Physics类的具体用法?Python Physics怎么用?Python Physics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Physics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
def draw(self, screen):
#~ pos = Physics.to_pygame(self.body.position)
#~ screen.blit(self.image, (pos[0], pos[1]-self.height)) # Draw at bottom left
self.v1 = Physics.to_pygame(Vec2d(self.p1[0], self.p1[1]))
self.v2 = Physics.to_pygame(Vec2d(self.p2[0], self.p2[1]))
pygame.draw.line(screen, self.color, self.v1, self.v2, 20)
示例2: __set_g
def __set_g(self, g):
self.__g = array(g)
self.gnorm = Physics.norm(g)
self.gnormalized = Physics.normalize(g)
# angular coordinates (azimuth and colatitude) of the g versor
self.gtheta = math.acos(self.gnormalized[2])
self.gphi = Physics.atan2(g[1], g[0])
示例3: __set_k
def __set_k(self, k):
self.__k = array(k)
self.knorm=Physics.norm(k)
self.knormalized = Physics.normalize(k)
# Calculates wavelength and energy of the photon
if self.knorm==0.:
self.__e, self.__lam=0., '+inf'
else:
self.__lam=2.*pi/self.knorm
self.__e=Booklet.hc/self.__lam
示例4: sigma
def sigma(self, keV, OFFSET=0., order=1, distribution="gaussian"):
"""Replacement for Physics.sigma function."""
tB = self.keV2Bragg(keV, order)
Q = self.mat_facs[order]*Physics.angular_factor(tB)
Dtheta = self.getDelta(tB, OFFSET)
if distribution=="hat":
weight=Physics.hat(Dtheta, Physics.eta2fwhm(self.eta))
elif distribution=="gaussian":
weight=Physics.gaussian(Dtheta, self.eta)
else: return 0.
return Q*weight/math.cos(tB)
示例5: deleteAllObjects
def deleteAllObjects(self):
"""Delete all objects: characters, rigid bodies, snapshots, etc."""
if self._followedCharacter is not None :
self._followedCharacter = None
self._cameraFollowCharacter = False
self._cameraObservable.notifyObservers()
self._characters = []
self._controllerList.clear()
import Physics
Physics.world().destroyAllObjects()
self.deleteAllSnapshots()
示例6: addCharacter
def addCharacter(self, character):
"""Adds a character to the application and the world"""
import Physics
if PyUtils.sameObjectInList(character, self._characters) :
raise KeyError ('Cannot add the same character twice to application.')
Physics.world().addArticulatedFigure( character )
self._characters.append( character )
if self._followedCharacter is None :
self._followedCharacter = character
self._cameraFollowCharacter = True
self._cameraObservable.notifyObservers()
self._characterObservable.notifyObservers()
示例7: g_needed
def g_needed(self, order=1):
###############################################
local_xtal_g = self.change_the_g(self.xtal.g)
#lgn=Physics.normalize(local_xtal_g)
local_xtal_gphi = Physics.atan2(local_xtal_g[1], local_xtal_g[0])
###############################################
"""Calculates the reciprocal lattice vector that a photon needs to be
scattered by a known crystal with planes oriented in a particular
direction that is already known"""
#When the energy is too low the returned value is None.
if self.photon.knorm < self.xtal.gnorm*order: return None
# For the calculation see the notes of 09/07/2004 modified the 12/07/04
A = (self.photon.k[0]*math.cos(local_xtal_gphi)+self.photon.k[1]*math.sin(local_xtal_gphi))
B = self.photon.k[2]
C = self.xtal.gnorm/2.
#A = (self.photon.k[0]*math.cos(self.xtal.gphi)+self.photon.k[1]*math.sin(self.xtal.gphi))
#B = self.photon.k[2]
#C = self.xtal.gnorm/2.
if abs(A)<=EPSILON:
# B can't be 0 together with A unless gnorm=0, so this function should be almost safe
# The result can be otained with the calculation in the else block
# but this is faster and common (is the case of paraxial photons).
if abs(C/B)>1.: return None
else:
theta=math.acos(-C/B)
else:
A2B2=A**2+B**2
BC=B*C
# Two solutions, but only one satisfies the Laue equation
Mean=-BC/A2B2
try:
Delta=A*math.sqrt(A2B2-C**2)/A2B2
except ValueError:
return None
cosp, cosm = Mean+Delta, Mean-Delta
thp, thm = math.acos(cosp), math.acos(cosm)
sinp, sinm = math.sin(thp), math.sin(thm)
checkp = abs(A*sinp + B*cosp + C)
checkm = abs(A*sinm + B*cosm + C)
# Da ricontrollare
if checkp<checkm:
theta=thp
else:
theta=thm
return Physics.spherical2cartesian(self.xtal.gnorm, local_xtal_gphi, theta)
示例8: sigma
def sigma(self, G=False, order=1, distribution="gaussian"):
"""Interface to the sigma function from Physics."""
tB = self.xtal.keV2Bragg(self.photon.e)
ang_fac = Physics.angular_factor(tB)
Q = self.xtal.mat_facs[order]*ang_fac
if G is None: G=self.g_needed(order)
Dtheta = Physics.anglebetween(G, self.xtal.g)
if distribution=="hat":
weight=Physics.hat(Dtheta, Physics.eta2fwhm(self.xtal.eta))
elif distribution=="gaussian":
weight=Physics.gaussian(Dtheta, self.xtal.eta)
else: return 0.
cosine = abs(self.photon.k[2]/self.photon.knorm)
return Q*weight/cosine
示例9: load
def load(self):
assert not self._loaded, "Cannot load scenario twice!"
self._loaded = True
# Create the rigid bodies for the main staircase
orientation = PyUtils.angleAxisToQuaternion( (self._angle,(0,1,0)) )
size = MathLib.Vector3d( self._staircaseWidth, self._riserHeight, self._threadDepth )
pos = PyUtils.toPoint3d( self._position ) + MathLib.Vector3d( 0, -self._riserHeight/2.0, 0 )
delta = MathLib.Vector3d(size)
delta.x = 0
delta = orientation.rotate( delta )
for i in range(self._stepCount):
box = PyUtils.RigidBody.createBox( size, pos = pos + delta * (i+1), locked = True, orientation=orientation )
Physics.world().addRigidBody(box)
# Create the rigid bodies for both ramps
rampHeights = ( self._leftRampHeight, self._rightRampHeight )
deltaRamp = MathLib.Vector3d(self._staircaseWidth/2.0,0,0)
deltaRamp = orientation.rotate( deltaRamp )
deltaRamps = (deltaRamp, deltaRamp * -1)
for deltaRamp, rampHeight in zip( deltaRamps, rampHeights ):
if rampHeight is None: continue
deltaRamp.y = rampHeight/2.0
box = PyUtils.RigidBody.createBox( (0.02,rampHeight,0.02), pos = pos + deltaRamp + delta , locked = True, orientation=orientation )
Physics.world().addRigidBody(box)
box = PyUtils.RigidBody.createBox( (0.02,rampHeight,0.02), pos = pos + deltaRamp + (delta * self._stepCount) , locked = True, orientation=orientation )
Physics.world().addRigidBody(box)
deltaRamp.y = rampHeight
rampOrientation = orientation * PyUtils.angleAxisToQuaternion( (math.atan2(self._riserHeight, self._threadDepth), (-1,0,0)) )
rampLen = self._stepCount * math.sqrt( self._riserHeight*self._riserHeight + self._threadDepth*self._threadDepth )
box = PyUtils.RigidBody.createBox( (0.04,0.02,rampLen), pos = pos + deltaRamp + (delta * ((self._stepCount+1) * 0.5)) , locked = True, orientation=rampOrientation )
Physics.world().addRigidBody(box)
示例10: __set_g
def __set_g(self, g):
self.__g = array(g)
self.gnorm = Physics.norm(g)
self.gnormalized = Physics.normalize(g)
# angular coordinates of the reciprocal lattice vector g
# gtheta is the polar angle (the angle between z axis and g vector)
# gphi is the azimuthal angle (in the plane xy, from the x axis)
self.gtheta = math.acos(self.gnormalized[2])
self.gphi = Physics.atan2(g[1], g[0])
示例11: local_eranges
def local_eranges(self, Emin=1., Emax=1000., sphi=0., stheta=pi, deltasource=0):
l = math.sqrt(self.photon.r[0]**2 + self.photon.r[1]**2)
#stheta = stheta - self.divergence_stheta(l, deltasource)
sphi = self.divergence_sphi(self.photon.r)
local_xtal_g = self.change_the_g(self.xtal.g)
lgn=Physics.normalize(local_xtal_g)
local_xtal_gphi = Physics.atan2(local_xtal_g[1], local_xtal_g[0])
local_xtal_gtheta = math.acos(lgn[2])
order, reached_max_order = 0,False
factor = 2.5
Darwin_Width = Physics.darwinwidth(self.xtal.Z, self.xtal.hkl, self.photon.e)
if self.xtal.structure == "mosaic":
Deltatheta = 1.0 * (self.xtal.fwhm/60/180*pi)
else:
Deltatheta = Darwin_Width + (self.xtal.dim[2] * self.xtal.curvature) / factor
Delta_curvature = self.xtal.curvature * self.xtal.dim[0]
thetamin, thetamax = local_xtal_gtheta-Deltatheta/2, local_xtal_gtheta+Deltatheta/2
constant=-Booklet.hc/(2.*self.xtal.d_hkl)
eranges=[]
while not reached_max_order:
order+=1
cosdeltaphi=math.cos(sphi-local_xtal_gphi)
sinstheta=math.sin(stheta)
cosstheta=math.cos(stheta)
sinthetamin=math.sin(thetamin)
costhetamin=math.cos(thetamin)
sinthetamax=math.sin(thetamax)
costhetamax=math.cos(thetamax)
Eminim_= constant*order/(cosdeltaphi*sinstheta*sinthetamin+cosstheta*costhetamin)
Emaxim_= constant*order/(cosdeltaphi*sinstheta*sinthetamax+cosstheta*costhetamax)
if Emaxim_ >= Emax:
if Eminim_>=Emax: return eranges
else:
reached_max_order=True
Emaxim_=Emax
if Eminim_ <= Emin:
if Emaxim_ <= Emin: pass
else:
Eminim_=Emin
eranges.append((Eminim_, Emaxim_))
else: eranges.append((Eminim_, Emaxim_))
return eranges
示例12: generator
def generator(self, Emin=1., Emax=1000., Exp=False, sphi=0., stheta=pi, deltasource=0):
'''Generates randomly a photon going onto the xtal.
Exp is the powerlaw spectral index -2.1 for Crab '''
# Defines the crystal angles using the angular coordinate of the
# reciprocal lattice vector g. The same crystal angles (with -sign)
# will be also appplied to the generated photon.
l = math.sqrt(self.photon.r[0]**2 + self.photon.r[1]**2)
#print "divergenza",self.photon.r[0], self.photon.r[1], l, self.divergence_stheta(l, deltasource)
#print "stheta", stheta
#stheta = stheta - self.divergence_stheta(l, deltasource)
#sphi = self.divergence_sphi(self.photon.r)
#print "stheta", stheta
# Set the photon intensity equal to 1. This function generate a probability
# for the photon, then it will be multplied by the requested intensity set
# in the macro
if self.photon.i !=1: self.photon.i=1.
# wavevector definition from source angular parameters
# stheta = pi and sphi = 0 means on-axis source while
# off-axis source is simply obtained by changing stheta.
# the k value is related to the energy from the relation k = 2 pi/lambda
# is the erandom function that make the k from module 1 to the correct module
# indeed erandom set the energy and follow that automatically k is set.
# Now photon.k has module 1, erandom will give the right normalization.
self.photon.k=Physics.makenormalvec(sphi, stheta)
# Energy calculation (powerlaw if Exp is False)
self.erandom((Emin, Emax), Exp=Exp)
示例13: extinction_factor
def extinction_factor(self, keV, theta_0, order=1):
"""Wrapper for Physics.extinction_factor function"""
if self.microthick==0.:
return 1.
else:
# This part can be speed up by using Xtal facilities!!!
return Physics.extinction_factor(keV, self.Z, self.hkls[order], self.microthick, theta_0)
示例14: __init__
def __init__(self, size, cam, tilePics,itemList,tileCracks,weaponPics,armorPics,over, unit=32, lighting = True,special=True):
self.size = size
self.unit = unit
self.rows = self.size[1] // self.unit
self.columns = self.size[0] // self.unit
self.cam = cam
self.tilePics = tilePics
self.startLighting = False
self.itemList = itemList
self.special = special
self.entities = []
self.physics = Physics.physics(self)
self.AIOn = True
self.tileCracks = tileCracks
self.weaponPics = weaponPics
self.spawners = []
self.charList = CharacterList.characterList(armorPics)
self.over = over
self.armorPics = armorPics
self.towns = []
self.tileList = TileList.tileList()
if lighting == True:
self.lighting = Lighting.lighting(self)
self.baseLightLevel = 255
else:
self.lighting = False
self.resetTiles()
self.resetMetadata()
'''if lighting == True:
示例15: gettB
def gettB(self, OFFSET=0.):
"""Calculates Bragg angle for an X-ray source with a certain offset.
NOTE: Assumes source azimuthal angle equal to zero!!!"""
if OFFSET==0.:
return math.pi/2-self.gtheta
else:
stheta=math.pi*(1.-OFFSET/60./180.)
return Physics.anglebetween((math.sin(stheta),0.,math.cos(stheta)), self.gnormalized)-math.pi/2.