def getSoundSource(self): ''' A, B, C trois points du systeme pondéré { (A,a), (B,b), (C,c) }. Pour tout point M du plan défini par A, B, C : aMA + bMB + cMC = (a+b+c)MG Avec G le barycentre des points A, B, C. On obtient ses coordonnées : axA + bxB + cxC xG = --------------- a + b + c ayA + byB + cyC yG = --------------- a + b + c azA + bzB + czC zG = --------------- a + b + c Bon, ici la coordonnée en z ne nous sert pas puisqu'on travaille dans le plan. On peut généraliser ce calcul pour n points. ''' xG, yG, weightSum = 0.0, 0.0, 0.0 # weightSum = a+b+c = sum of the weight of each point for frog in self.frogs: if frog.state == 'singing' : pos = frog.getLocation() weight = frog.voicePower xG += weight*pos.x # calculating the numerators, for the x coordinate yG += weight*pos.y # for the y one weightSum += weight # denominator (same for every coord) xG /= weightSum yG /= weightSum return breve.vector(xG, yG, 0.01) # simulation coordinates
def getSoundLevel(self, location): ''' location : position in the simulation (location.x & location.y) ''' SPL = 0 for frog in self.frogs: if frog.state == 'singing' : #pos = self.worldToImage(frog.getLocation()) pos = frog.getLocation() dist = (location.x - pos.x)**2 + (location.y - pos.y)**2 if dist <= 0: sndLvl = frog.voicePower else: sndLvl = frog.voicePower - 10*log10(dist) SPL += 10**(sndLvl/10) # SPL = 10^(SPL1/10) + 10^(SPL2/10) + ... if SPL == 0 : return 0 level = 10 * log10(SPL) # I = 10 * log( SPL) dB return level