Пример #1
0
	def __init__(self, pos,terrain=None, dbh=0, specie=None):
		Obstacle.__init__(self, pos, isSpherical=True, radius=dbh,terrain=terrain, color='#5C3317')
		self.z=0
		self.dbh=dbh
		self.specie=specie
		self.alpha=1
		self.rLim=0.01 #smaller than 1cm radius is not relevant.
		self.zlim=0.2 #roots deeper than this are discarded.
		if terrain:
			self.name="stump%d"%len(terrain.stumps)
			terrain.stumps.append(self)
		else: self.name="stump"
		#the new stuff! Exciting
		self.RPradius=dbh/2.+0.5   #50^2/10000 =>m2, =(50/100)=0.5^2 dvs 0.5m i grundradie
		self.radius=self.RPradius
		nRoots=int(round(1.822+(0.019*dbh*1000)))
		#let's put up the rooots!
		th=random.uniform(0,2*pi)
		dth=2*pi/float(nRoots)
		cart=getCartesian
		maxdist2=0
		self.roots=[]
		for i in range(nRoots):
			rootR=abs((-0.18943+2.96*dbh)/nRoots/2.) #radius of root
			#taper factor:
			tf=0.04+0.0206*random.normalvariate(0,1)# dm/dm root length.. thus unitless
			if tf<0.0194: tf=0.04
			if self.specie=='pine':
				rootL=abs(random.normalvariate(0.510, sqrt(0.671))) #length of root
			elif self.specie=='spruce':
				rootL=abs(random.normalvariate(0.480, sqrt(0.549))) #length of root
			elif self.specie=='leaf':
				rootL=abs(random.normalvariate(0.510, sqrt(0.658))) #length of root
			else:
				raise Exception('root did not recognize specie:%s'%self.specie)
			#finalR=rootR-rootL*tf
			finalR=rootR*(1-tf)
			alpha=asin(rootR/self.RPradius)#half angle between p1 and p4
			dr=rootR-finalR
			start=cart([self.RPradius-rootR, th],direction=pi/2., origin=self.pos)
			p1=cart([self.RPradius-rootR, th-alpha],direction=pi/2., origin=self.pos)
			comp=rootR/cos(th-pi/2) #to compensate for that the origin of the root is inside the root plate, -rootR above.
			p2=cart([-dr ,rootL+comp],origin=p1, direction=th, fromLocalCart=True)
			p3=cart([-dr-2*finalR,rootL+comp],origin=p1, direction=th, fromLocalCart=True)
			middle=cart([-dr-finalR,rootL],origin=p1, direction=th, fromLocalCart=True)
			p4=cart([-2*rootR,0],origin=p1, direction=th, fromLocalCart=True)
			if dr+finalR-rootR>rootR/100.: raise Exception('Root model does not work as planned. %f, %f, %f'%(rootR, finalR, dr))
			#self._makeRoot(pos=start, direction=th, nodes=[p1,p2,p3,p4], rin=rootR, rfin=finalR,length=rootL, visible=True)
			#self._branch(middle, finalR, th=th, zin=0) #makes a branch. May create more sub-branches
			self._branch(start, rootR, th=th, zin=0, first=True) #makes a branch. May create more sub-branches
			th+=dth
		if self.terrain:
			self.terrain.obstacles.remove(self)
			self.terrain.obstacles.append(self) # to get after the roots in the list.
Пример #2
0
    def __init__(self,
                 target_x,
                 target_y,
                 angular_speed=0.3,
                 linear_speed=0.2,
                 distance_from_mline_threshold=0.1,
                 distance_from_nearest_point_threshold=0.1):
        Obstacle.__init__(self, angular_speed, linear_speed)

        self.mline = MLine()  #stworzenie obiektu typu MLine
        self.mline.calculate_m_line(
            target_x, target_y)  #pomiędzy początkiem, a końcem trasy
        self.distance_from_mline_threshold = distance_from_mline_threshold
        self.distance_from_nearest_point_threshold = distance_from_nearest_point_threshold

        self.distance_from_start_to_target = self.mline.calculate_distance_from_line_start(
            target_x, target_y)
        self.closest_point = {'x': 0, 'y': 0}
        self.hit_point_distance_from_start = 0  #zmienna zapisująca poprzednie miniecię z prostą MLine