public double getDistance() { // Retrieve the environment Environment env = Environment.Instance; double maxDistance = -1; // Create the range segment this.range = new Segment(); range.Start.X = env.AgentPosition.X; range.Start.Y = env.AgentPosition.Y; range.End.X = env.AgentPosition.X; range.End.Y = env.AgentPosition.Y + length; range = range.Rotate(env.AgentAngle + angleOffset); // Go through the list of segments, not neat O(n) but execution // fast enough for this simulation purpose foreach (Segment s in env.Segments) { Point p; if ((p = range.Intersects(s)) != null) { double v = p.Distance(range.Start); if (v < maxDistance || maxDistance == -1) { maxDistance = v; } } } return(maxDistance); }
public double getDistance() { // Retrieve the environment Environment env = Environment.Instance; double maxDistance = -1; // Create the range segment this.range = new Segment(); range.Start.X = env.AgentPosition.X; range.Start.Y = env.AgentPosition.Y; range.End.X = env.AgentPosition.X; range.End.Y = env.AgentPosition.Y + length; range = range.Rotate(env.AgentAngle + angleOffset); // Go through the list of segments, not neat O(n) but execution // fast enough for this simulation purpose foreach (Segment s in env.Segments) { Point p; if ((p = range.Intersects(s)) != null) { double v = p.Distance(range.Start); if (v < maxDistance || maxDistance == -1) { maxDistance = v; } } } return maxDistance; }
public void straight(int speed) { Environment env = Environment.Instance; Segment nextPos = new Segment(); nextPos.Start.X = env.AgentPosition.X; nextPos.Start.Y = env.AgentPosition.Y; nextPos.End.X = env.AgentPosition.X; //nextPos.End.Y = env.AgentPosition.Y + (longDistance > 0 ? Math.Min(longDistance, 1) : 1); nextPos.End.Y = env.AgentPosition.Y + 1; nextPos = nextPos.Rotate(env.AgentAngle); env.AgentPosition = nextPos.End; }
public Point CurrentPosition(double distance, double angle) { Point p; if (previous == null) { p = new Point(distance, 0); } else { // Touched a wall Segment s = new Segment(); s.Start = previous.Coord; s.End = s.Start; s.End.X += distance; p = new Point(s.Rotate(angle).End); } return(p); }
public Point CurrentPosition(double distance, double angle) { Point p; if (previous == null) { p = new Point(distance, 0); } else { // Touched a wall Segment s = new Segment(); s.Start = previous.Coord; s.End = s.Start; s.End.X += distance; p = new Point(s.Rotate(angle).End); } return p; }