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);
}
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);
}
}
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));
}
}
}
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;
}
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());
}
Aggregations