Search in sources :

Example 16 with Point2D

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

the class CspViewCtrl method visualize.

protected void visualize(VAR var) {
    Point2D pos = getPosition(var);
    String label = var.getName();
    VAL value = null;
    Color fillColor = null;
    if (assignment != null)
        value = assignment.getValue(var);
    if (value != null) {
        label += " = " + value;
        fillColor = colorMapping.get(value);
    }
    Circle circle = new Circle(pos.getX(), pos.getY(), 20);
    circle.setStroke(Color.BLACK);
    circle.setFill(fillColor != null ? fillColor : Color.WHITE);
    Text t1 = new Text(pos.getX() + 25, pos.getY(), label);
    t1.setTextOrigin(VPos.CENTER);
    Text t2 = new Text(pos.getX(), pos.getY() + 40, csp.getDomain(var).toString());
    pane.getChildren().addAll(circle, t1, t2);
}
Also used : Circle(javafx.scene.shape.Circle) Point2D(aima.core.util.math.geom.shapes.Point2D) Color(javafx.scene.paint.Color) Text(javafx.scene.text.Text)

Example 17 with Point2D

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

the class CspViewCtrl method visualize.

protected void visualize(Constraint<VAR, VAL> constraint) {
    List<VAR> scope = constraint.getScope();
    if (scope.size() == 2) {
        // we show only binary constraints...
        Point2D pos0 = getPosition(scope.get(0));
        Point2D pos1 = getPosition(scope.get(1));
        Line line = new Line(pos0.getX(), pos0.getY(), pos1.getX(), pos1.getY());
        pane.getChildren().add(line);
    //g2.drawLine(pos0[0] + 20, pos0[1] + 20, pos1[0] + 20, pos1[1] + 20);
    }
}
Also used : Line(javafx.scene.shape.Line) Point2D(aima.core.util.math.geom.shapes.Point2D)

Example 18 with Point2D

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

the class MapEnvironmentViewCtrl method update.

protected void update() {
    envStateView.getChildren().clear();
    if (env != null) {
        double scale = adjustTransform();
        Map map = env.getMap();
        // print connections
        for (String loc1 : map.getLocations()) {
            Point2D pt1 = map.getPosition(loc1);
            for (String loc2 : map.getPossibleNextLocations(loc1)) {
                Point2D pt2 = map.getPosition(loc2);
                Shape line = new Line(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY());
                line.setStroke(Color.LIGHTGRAY);
                envStateView.getChildren().add(line);
            }
        }
        // print track of first agent
        if (!env.getAgents().isEmpty()) {
            String aLoc = env.getAgentLocation(env.getAgents().get(0));
            if (track.isEmpty() || !Objects.equals(track.get(track.size() - 1), aLoc))
                track.add(aLoc);
            for (int i = 1; i < track.size(); i++) {
                Point2D pt1 = map.getPosition(track.get(i - 1));
                Point2D pt2 = map.getPosition(track.get(i));
                Shape line = new Line(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY());
                line.setStroke(Color.RED);
                line.setStrokeWidth(2);
                envStateView.getChildren().add(line);
            }
        }
        // print locations
        for (String loc : map.getLocations()) {
            Point2D point = map.getPosition(loc);
            Text text = new Text(point.getX() + 10 / scale, point.getY(), loc);
            text.setFont(new Font(12.0 / scale));
            envStateView.getChildren().add(text);
            envStateView.getChildren().add(new Circle(point.getX(), point.getY(), 2 / scale));
        }
        // print agent locations
        for (Agent agent : env.getAgents()) {
            String loc = env.getAgentLocation(agent);
            if (loc != null) {
                Point2D pt = map.getPosition(loc);
                envStateView.getChildren().add(new Circle(pt.getX(), pt.getY(), 8 / scale, Color.RED));
            }
        }
        // print goal
        if (goal != null) {
            Point2D pt = map.getPosition(goal);
            envStateView.getChildren().add(new Circle(pt.getX(), pt.getY(), 6 / scale, Color.GREEN));
        }
    }
}
Also used : Line(javafx.scene.shape.Line) Circle(javafx.scene.shape.Circle) Agent(aima.core.agent.Agent) Shape(javafx.scene.shape.Shape) Point2D(aima.core.util.math.geom.shapes.Point2D) Text(javafx.scene.text.Text) Map(aima.core.environment.map.Map) Font(javafx.scene.text.Font)

Example 19 with Point2D

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

the class MapFunctions method getSLD.

public static double getSLD(String loc1, String loc2, Map map) {
    double result = 0.0;
    Point2D pt1 = map.getPosition(loc1);
    Point2D pt2 = map.getPosition(loc2);
    if (pt1 != null && pt2 != null)
        result = pt1.distance(pt2);
    return result;
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D)

Example 20 with Point2D

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

the class SimplePose method applyMovement.

@Override
public SimplePose applyMovement(SimpleMove move) {
    final double headingNew = heading + move.getFirstRotation();
    Point2D positionNew = position.add(Vector2D.calculateFromPolar(move.getForward(), -headingNew));
    return new SimplePose(positionNew, headingNew + move.getLastRotation());
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D)

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