Search in sources :

Example 6 with Point2D

use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.

the class Line2DTest method setUp.

@Before
public void setUp() throws Exception {
    testLine = new Line2D(2.0d, 3.0d, 4.0d, 5.0d);
    testLine2 = new Line2D(6.0d, 4.0d, 6.0d, -3.0d);
    testLine3 = new Line2D(6.0d, -3.0d, 2.0d, 2.0d);
    testLine4 = new Line2D(3.0d, 4.0d, 6.0d, 4.0d);
    zeroPoint = new Point2D(0.0d, 0.0d);
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) Line2D(aima.core.util.math.geom.shapes.Line2D) Before(org.junit.Before)

Example 7 with Point2D

use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.

the class Polyline2DTest method testRandomPoint.

@Test
public final void testRandomPoint() {
    Point2D randomPoint = testPolylineOpen.randomPoint();
    for (int i = 0; i < 1000; i++) {
        randomPoint = testPolylineOpen.randomPoint();
        assertTrue("Random point on polyline.", testPolylineOpen.isInsideBorder(randomPoint));
    }
    for (int i = 0; i < 1000; i++) {
        randomPoint = testPolylineClosed.randomPoint();
        assertTrue("Random point in polygon.", testPolylineClosed.isInsideBorder(testPolylineClosed.randomPoint()));
    }
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) Test(org.junit.Test)

Example 8 with Point2D

use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.

the class MapAgentView method paintTrack.

/** The track of the agent is visualized with red lines. */
private void paintTrack(java.awt.Graphics2D g2, Agent a) {
    Map map = getMapEnv().getMap();
    Point2D lastPt = null;
    g2.setColor(Color.red);
    for (String loc : getTrack(a)) {
        Point2D pt = map.getPosition(loc);
        if (pt != null && lastPt != null) {
            g2.drawLine(x(pt), y(pt), x(lastPt), y(lastPt));
        }
        lastPt = pt;
    }
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) Map(aima.core.environment.map.Map)

Example 9 with Point2D

use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.

the class ExtendedMapAgentView method paintLoc.

/** Displays a map location. */
protected void paintLoc(Graphics2D g2, String loc) {
    Map map = getMapEnv().getMap();
    Point2D pt = map.getPosition(loc);
    if (pt != null) {
        int x = x(pt);
        int y = y(pt);
        String info = "";
        List<String> track = new ArrayList<String>();
        if (!env.getAgents().isEmpty())
            // show details only for track of first agent...
            track = getTrack(env.getAgents().get(0));
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < track.size(); i++) if (track.get(i).equals(loc))
            list.add(i + 1);
        if (!list.isEmpty())
            info = list.toString();
        //			}
        if (scenario != null && scenario.getInitAgentLocation().equals(loc)) {
            g2.setColor(Color.red);
            g2.fillOval(x - 7, y - 7, 14, 14);
        }
        if (getAgentLocs().contains(loc)) {
            g2.setColor(Color.red);
            g2.fillOval(x - 4, y - 4, 8, 8);
        }
        // else
        if (destinations != null && destinations.contains(loc))
            g2.setColor(Color.green);
        else if (track.contains(loc))
            g2.setColor(Color.black);
        else
            g2.setColor(Color.gray);
        g2.drawString(loc + info, x, y);
    }
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) ArrayList(java.util.ArrayList) Map(aima.core.environment.map.Map)

Example 10 with Point2D

use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.

the class MapAgentView method paintMap.

/**
	 * Represents roads by lines and locations by name-labeled points.
	 */
protected void paintMap(java.awt.Graphics2D g2) {
    Map envMap = getMapEnv().getMap();
    for (String l1 : envMap.getLocations()) {
        Point2D pt1 = envMap.getPosition(l1);
        List<String> linkedLocs = envMap.getPossibleNextLocations(l1);
        for (String l2 : linkedLocs) {
            Point2D pt2 = envMap.getPosition(l2);
            g2.setColor(Color.lightGray);
            g2.drawLine(x(pt1), y(pt1), x(pt2), y(pt2));
        }
    }
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) Map(aima.core.environment.map.Map)

Aggregations

Point2D (aima.core.util.math.geom.shapes.Point2D)32 Map (aima.core.environment.map.Map)7 ArrayList (java.util.ArrayList)6 IGeometric2D (aima.core.util.math.geom.shapes.IGeometric2D)5 Before (org.junit.Before)5 Circle2D (aima.core.util.math.geom.shapes.Circle2D)4 Ellipse2D (aima.core.util.math.geom.shapes.Ellipse2D)4 Polyline2D (aima.core.util.math.geom.shapes.Polyline2D)4 Test (org.junit.Test)4 Line2D (aima.core.util.math.geom.shapes.Line2D)3 Ray2D (aima.core.util.math.geom.shapes.Ray2D)3 MapNode (aimax.osm.data.entities.MapNode)3 Agent (aima.core.agent.Agent)2 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)2 Circle (javafx.scene.shape.Circle)2 Line (javafx.scene.shape.Line)2 Text (javafx.scene.text.Text)2 aima.core.environment.map (aima.core.environment.map)1 MapAgent (aima.core.environment.map.MapAgent)1 MapEnvironment (aima.core.environment.map.MapEnvironment)1