Esempio n. 1
0
        /// <summary>
        /// Tests if this AreaOfImpact collides with another cirle. Used for robot collision detection.
        /// </summary>
        /// <returns>Returns true if the circles collide; false otherwise.</returns>
		public bool collide(Circle2D otherCircle2D)
		{
			double dx = otherCircle2D.Position.X - Position.X;
			double dy = otherCircle2D.Position.Y - Position.Y;
			dx*=dx;
			dy*=dy;
			double rad_sum = otherCircle2D.Radius+Radius;
			rad_sum*=rad_sum;
			if ((dx+dy)<rad_sum)
				return true;
			return false;
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a new Circle2D object by copying another AreaOfImpact.
 /// </summary>
 public Circle2D(Circle2D otherCircle2D)
 {
     Position = otherCircle2D.Position;
     Radius   = otherCircle2D.Radius;
 }
Esempio n. 3
0
        /// <summary>
        /// Initialize the robot.
        /// </summary>
        public void init(int id, double locationX, double locationY, double heading, AgentBrain agentBrain, Environment environment, float sensorNoise, float effectorNoise, float headingNoise, float timeStep)
        {
            this.ID = id;
            Radius = defaultRobotSize();
            Location = new Point2D(locationX, locationY);
            AreaOfImpact = new Circle2D(Location, Radius);
            OldLocation = new Point2D(Location);

            Heading = heading;
            Velocity = 0.0;
            HasCollided = false;
            this.Timestep = timeStep;
            this.CurrentEnvironment = environment;
            this.Brain = agentBrain;
            this.SensorNoise = sensorNoise;
            this.EffectorNoise = effectorNoise;
            this.HeadingNoise = headingNoise;
            populateSensors();
            if (environment.seed != -1)
                rng = environment.rng;
            else
                rng = environment.rng;
            this.Trajectory = new List<int>();
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new Circle2D object by copying another AreaOfImpact.
        /// </summary>
		public Circle2D(Circle2D otherCircle2D)
		{
			Position=otherCircle2D.Position;
			Radius=otherCircle2D.Radius;
		}
Esempio n. 5
0
        /// <summary>
        /// Calculates the nearest intersection of the line segment with a given AreaOfImpact. (The line segment is interpreted as a ray going from its first endpoint to its second one.
        /// </summary>
        /// <param name="C">Circle that is supposed to intersect with the line segment.</param>
        /// <param name="found">**Output parameter**, will return false if no intersection exists.</param>
		public double nearestIntersection(Circle2D circle,out bool found)
		{
			double dx,dy;
			
			dx=Endpoint2.X-Endpoint1.X;
			dy=Endpoint2.Y-Endpoint1.Y;

			double px=Endpoint1.X-circle.Position.X;
			double py=Endpoint1.Y-circle.Position.Y;
			
			double a= dx*dx + dy*dy;
			double b= 2*px*dx+2*py*dy;
			double c= px*px + py*py - circle.Radius*circle.Radius;
			
			double det = b*b-4.0*a*c;
			
			if(det<0.0)
			{
				found=false;
				return -1.0;
			}
				
			double sqrt_det = Math.Sqrt(det);
			double t1 = (-b+sqrt_det)/(2*a);
			double t2 = (-b-sqrt_det)/(2*a);
			
			found=false;
			double t=0.0;
			if(t2<0)
			{
				if(t1>0)
				{
					found=true;
					t=t1;
				}
			}
			else
			{
				found=true;
				t=t2;
			}
			if(!found)
				return -1.0;
				
			return t*Math.Sqrt(dx*dx+dy*dy);
			
		}