예제 #1
0
	def genRandomPoint(self):
		
		"""Returns random coordinate inside domain.

		:returns: array -- coordinate
		"""
		
		xmin,xmax,ymin,ymax=self.getExtend()
		poly=self.verticesCoordsToList()
		
		outside=True
		while outside:
	
			xrand=(xmax - xmin) * np.random.random() + xmin
			yrand=(ymax - ymin) * np.random.random() + ymin
		
			if self.typ=='poly':
				if rwe.checkInsidePoly([xrand,yrand],poly):
					return np.array([xrand,yrand])
			if self.typ=='circle':
				if rwe.checkInsideCircle([xrand,yrand],self.edges[0].vcenter.x,0.999*self.edges[0].radius,tol=0.)<0:
					return np.array([xrand,yrand])
			else:
				print "Warning, can not generate random points for geometry of typ = ", self.typ
				return False,False
예제 #2
0
    def genRandomPoint(self):
        """Returns random coordinate inside domain.

		:returns: array -- coordinate
		"""

        xmin, xmax, ymin, ymax = self.getExtend()
        poly = self.verticesCoordsToList()

        outside = True
        while outside:

            xrand = (xmax - xmin) * np.random.random() + xmin
            yrand = (ymax - ymin) * np.random.random() + ymin

            if self.typ == 'poly':
                if rwe.checkInsidePoly([xrand, yrand], poly):
                    return np.array([xrand, yrand])
            if self.typ == 'circle':
                if rwe.checkInsideCircle([xrand, yrand],
                                         self.edges[0].vcenter.x,
                                         0.999 * self.edges[0].radius,
                                         tol=0.) < 0:
                    return np.array([xrand, yrand])
            else:
                print "Warning, can not generate random points for geometry of typ = ", self.typ
                return False, False
예제 #3
0
    def inArc(self, x, debug=False):
        """Checks if points x lies on arc
		
		:param x: coordinate.
		:type x: array
		:param debug: Debugging flag.
		:type debug: bool
		
		"""

        a = rwe.compute_angle(
            np.array([self.radius, 0]) - self.vcenter.x, x - self.vcenter.x)

        if debug:
            print
            print "Angle(x) = ", a
            print "arc.angle = ", self.angle
            print "arc.angle_offset = ", self.angle_offset

        if np.mod(
                a, 2 * np.pi
        ) < self.angle + self.angle_offset and self.angle_offset <= np.mod(
                a, 2 * pi):
            if debug:
                print True
            return True
        else:
            if debug:
                print False
            return False
예제 #4
0
	def inArc(self,x,debug=False):
		
		"""Checks if points x lies on arc
		
		:param x: coordinate.
		:type x: array
		:param debug: Debugging flag.
		:type debug: bool
		
		"""
		
		a=rwe.compute_angle(np.array([self.radius,0])-self.vcenter.x,x-self.vcenter.x)
		
		if debug:
			print 
			print "Angle(x) = " , a
			print "arc.angle = " , self.angle
			print "arc.angle_offset = " , self.angle_offset
			
			
		if np.mod(a,2*np.pi)<self.angle+self.angle_offset and self.angle_offset<=np.mod(a,2*pi):
			if debug:
				print True
			return True
		else:
			if debug:
				print False
			return False
예제 #5
0
	def draw(self,r=None,color=None,ann=False):
		
		"""Draw arc
		
		:param r: pyrw run, if None, picks last run of main pyrw.RWRW object. 
		:type r: pyrw.RWrun
		:param color: color of arc in matplotlib syntax, e.g. 'r' or (0.1,1,0.5)
		:type color: matplotlib color
		:param ann: Annotation Flag
		:type ann: bool
		
		"""
		
		if ann==None:
			ann=False
		
		if r==None:
			r=self.domain.RW.runs[-1]
		
		if not hasattr(r,'fig_traj'):
			r.fig_traj=plt.figure()
			r.ax_traj=r.fig_traj.add_subplot(111)
			r.fig_traj.show()
			
		xvec,yvec=rwe.create_arc_curve(self.vcenter,self.angle,self.angle_offset,self.radius)
		
		r.ax_traj.plot(xvec,yvec,color='r',linestyle='-')
		if ann:
			r.ax_traj.annotate('a'+str(self.Id), xytext=((self.vstart.x[0]+self.vend.x[0])/2., (self.vstart.x[1]+self.vend.x[1])/2.),xy=(self.vcenter.x[0]+0.5, self.vcenter.x[1]+0.5),)
		
		plt.draw()
예제 #6
0
	def computeAngle(self,debug=False):
		
		"""Computes both angle and angle_offset of arc
		
		:param debug: Debugging flag.
		:type debug: bool
		:returns: (float,float) -- angle, angle_offset
		
		"""
		
		self.angle_offset=rwe.angle_from_vertices(self.vcenter,vertex(self.domain,[self.radius,0.],-1),self.vstart)
		self.angle=rwe.direc_angle(self.vstart.x-self.vcenter.x,self.vend.x-self.vcenter.x)
	
		if debug:
			print "angle_offset = ", self.angle_offset
			print "angle = ", self.angle
		
		return self.angle,self.angle_offset
예제 #7
0
    def computeAngle(self, debug=False):
        """Computes both angle and angle_offset of arc
		
		:param debug: Debugging flag.
		:type debug: bool
		:returns: (float,float) -- angle, angle_offset
		
		"""

        self.angle_offset = rwe.angle_from_vertices(
            self.vcenter, vertex(self.domain, [self.radius, 0.], -1),
            self.vstart)
        self.angle = rwe.direc_angle(self.vstart.x - self.vcenter.x,
                                     self.vend.x - self.vcenter.x)

        if debug:
            print "angle_offset = ", self.angle_offset
            print "angle = ", self.angle

        return self.angle, self.angle_offset
예제 #8
0
    def draw(self, r=None, color=None, ann=False):
        """Draw arc
		
		:param r: pyrw run, if None, picks last run of main pyrw.RWRW object. 
		:type r: pyrw.RWrun
		:param color: color of arc in matplotlib syntax, e.g. 'r' or (0.1,1,0.5)
		:type color: matplotlib color
		:param ann: Annotation Flag
		:type ann: bool
		
		"""

        if ann == None:
            ann = False

        if r == None:
            r = self.domain.RW.runs[-1]

        if not hasattr(r, 'fig_traj'):
            r.fig_traj = plt.figure()
            r.ax_traj = r.fig_traj.add_subplot(111)
            r.fig_traj.show()

        xvec, yvec = rwe.create_arc_curve(self.vcenter, self.angle,
                                          self.angle_offset, self.radius)

        r.ax_traj.plot(xvec, yvec, color='r', linestyle='-')
        if ann:
            r.ax_traj.annotate(
                'a' + str(self.Id),
                xytext=((self.vstart.x[0] + self.vend.x[0]) / 2.,
                        (self.vstart.x[1] + self.vend.x[1]) / 2.),
                xy=(self.vcenter.x[0] + 0.5, self.vcenter.x[1] + 0.5),
            )

        plt.draw()
예제 #9
0
파일: RWHC.py 프로젝트: colecalderon/PyRW
 def hitRW(self, x1, x2, r1):
     if rwe.dist(x1, x2) < r1:
         return True
     else:
         return False
예제 #10
0
import RWRW
import RWBC
from numpy import *
import RWessentials as rwe
import matplotlib.pyplot as plt
import RWmisc
import sys
import time

#Movement parameters
gammaVec = arange(0., 1., 0.2)
rVec = arange(1, 10, 2)
kappaVec = arange(1, 4, 2)

#Generate combinations
parmCombs = rwe.combinations([rVec, gammaVec, kappaVec])

#Initial positions
nInitPos = 1

#Runs
nRuns = 1

#Number of prey
NPrey = 10

#Bookkeeping array
RWs = []

#Domain radius
RDomain = 35
예제 #11
0
	def computeTrajLength(self):
		d=[]
		for i in range(len(self.traj)-1):
			d.append(rwe.dist(self.traj[i],self.traj[i+1]))
		self.L=sum(d)
		return self.L
예제 #12
0
파일: RWHC.py 프로젝트: alexblaessle/PyRW
	def hitRW(self,x1,x2,r1):
		if rwe.dist(x1,x2)<r1:
			return True
		else:
			return False
예제 #13
0
파일: RWBC.py 프로젝트: alexblaessle/PyRW
	def perp(self,x):
		xp = rwe.perp(x)
		return xp
예제 #14
0
 def computeTrajLength(self):
     d = []
     for i in range(len(self.traj) - 1):
         d.append(rwe.dist(self.traj[i], self.traj[i + 1]))
     self.L = sum(d)
     return self.L
예제 #15
0
 def circCheck(self, x, center, radius, tol=1E-30, debug=False):
     return rwe.checkInsideCircle(x, center, radius, tol=tol, debug=debug)
예제 #16
0
import RWRW
import RWBC
from numpy import *
import RWessentials as rwe
import matplotlib.pyplot as plt
import RWmisc
import sys
import time

#Movement parameters
gammaVec=arange(0.,1.,0.2)
rVec=arange(1,10,2)
kappaVec=arange(1,4,2)

#Generate combinations
parmCombs=rwe.combinations([rVec,gammaVec,kappaVec])

#Initial positions
nInitPos=1

#Runs
nRuns=1

#Number of prey
NPrey=10

#Bookkeeping array
RWs=[]

#Domain radius
RDomain=35
예제 #17
0
파일: RWBC.py 프로젝트: alexblaessle/PyRW
	def cross2d(self,x1,x2):
		return rwe.cross2d(x1,x2)
예제 #18
0
 def cross2d(self, x1, x2):
     return rwe.cross2d(x1, x2)
예제 #19
0
 def perp(self, x):
     xp = rwe.perp(x)
     return xp
예제 #20
0
파일: RWBC.py 프로젝트: alexblaessle/PyRW
	def circCheck(self,x,center,radius,tol=1E-30,debug=False):
                return rwe.checkInsideCircle(x,center,radius,tol=tol,debug=debug)