Search in sources :

Example 26 with Point2D

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

the class ExtendableMap method setDistAndDirToRefLocation.

/**
	 * Defines the position of a location within the map. Using this method, one
	 * location should be selected as reference position (<code>dist=0</code>
	 * and <code>dir=0</code>) and all the other location should be placed
	 * relative to it.
	 * 
	 * @param loc
	 *            location name
	 * @param dist
	 *            distance to a reference position
	 * @param dir
	 *            bearing (compass direction) in which the location is seen from
	 *            the reference position
	 */
public void setDistAndDirToRefLocation(String loc, double dist, int dir) {
    Point2D coords = new Point2D(-Math.sin(dir * Math.PI / 180.0) * dist, Math.cos(dir * Math.PI / 180.0) * dist);
    links.addVertex(loc);
    locationPositions.put(loc, coords);
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D)

Example 27 with Point2D

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

the class MclCartesianPlot2D method checkDistanceOfPoses.

/**
	 * Calculate the maximum distance between all samples and compare it to {@code maxDistance}.
	 * If it is smaller or equals to {@code maxDistance} the mean is returned. {@code null} otherwise.
	 * @param samples the set of samples to be checked against.
	 * @param maxDistance the maxDistance that the cloud should have to return a mean.
	 * @return the mean of the samples or {@code null}.
	 */
public P checkDistanceOfPoses(Set<P> samples, double maxDistance) {
    double maxDistanceSamples = 0.0d;
    for (P first : samples) {
        for (P second : samples) {
            double distance = first.distanceTo(second);
            maxDistanceSamples = distance > maxDistanceSamples ? distance : maxDistanceSamples;
        }
    }
    if (maxDistanceSamples <= maxDistance) {
        double averageX = 0.0d;
        double averageY = 0.0d;
        double averageHeading = 0.0d;
        for (P sample : samples) {
            averageX += sample.getX() / samples.size();
            averageY += sample.getY() / samples.size();
            averageHeading += sample.getHeading() / samples.size();
        }
        return poseFactory.getPose(new Point2D(averageX, averageY), averageHeading);
    }
    return null;
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D)

Example 28 with Point2D

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

the class Ellipse2DTest method testRayCast.

@Test
public final void testRayCast() {
    // static tests
    assertEquals("Ray doesn't intersect.", Double.POSITIVE_INFINITY, testEllipse.rayCast(new Ray2D(0.0d, 0.0d, 0.0d, 2.0d)), 0.000005d);
    assertEquals("Ray intersects.", 2.0d, testEllipse.rayCast(new Ray2D(0.0d, 14.0d, 12.0d, 14.0d)), 0.000005d);
    // serial tests
    Ellipse2D randomEllipse;
    Point2D randomPointOnEllipse;
    Point2D randomPoint;
    double currentXRadius;
    double currentYRadius;
    double xvalue;
    double yvalue;
    double randomAngle;
    int sector;
    int counter = 1000;
    do {
        randomEllipse = new Ellipse2D(new Point2D(Util.generateRandomDoubleBetween(-500.0d, 500.0d), Util.generateRandomDoubleBetween(-500.0d, 500.0d)), Util.generateRandomDoubleBetween(0.0d, 200.0d), Util.generateRandomDoubleBetween(0.0d, 200.0d));
        currentXRadius = randomEllipse.getHorizontalLength();
        currentYRadius = randomEllipse.getVerticalLength();
        xvalue = Util.generateRandomDoubleBetween(0.0d, currentXRadius);
        yvalue = (currentYRadius * Math.sqrt(currentXRadius * currentXRadius - xvalue * xvalue)) / currentXRadius;
        sector = Util.randomNumberBetween(1, 4);
        switch(sector) {
            case 2:
                {
                    yvalue = -yvalue;
                    randomPoint = new Point2D(Util.generateRandomDoubleBetween(randomEllipse.getCenter().getX() + xvalue, 1000.0d), Util.generateRandomDoubleBetween(-1000.0d, randomEllipse.getCenter().getY() + yvalue));
                    break;
                }
            case 3:
                {
                    xvalue = -xvalue;
                    yvalue = -yvalue;
                    randomPoint = new Point2D(Util.generateRandomDoubleBetween(-1000.0d, randomEllipse.getCenter().getX() + xvalue), Util.generateRandomDoubleBetween(-1000.0d, randomEllipse.getCenter().getY() + yvalue));
                    break;
                }
            case 4:
                {
                    xvalue = -xvalue;
                    randomPoint = new Point2D(Util.generateRandomDoubleBetween(-1000.0d, randomEllipse.getCenter().getX() + xvalue), Util.generateRandomDoubleBetween(randomEllipse.getCenter().getY() + yvalue, 1000.0d));
                    break;
                }
            default:
                {
                    randomPoint = new Point2D(Util.generateRandomDoubleBetween(randomEllipse.getCenter().getX() + xvalue, 1000.0d), Util.generateRandomDoubleBetween(randomEllipse.getCenter().getY() + yvalue, 1000.0d));
                    break;
                }
        }
        randomPointOnEllipse = new Point2D(randomEllipse.getCenter().getX() + xvalue, randomEllipse.getCenter().getY() + yvalue);
        randomAngle = Util.generateRandomDoubleBetween(-Math.PI / 2, Math.PI / 2);
        randomEllipse = (Ellipse2D) (randomEllipse.transform(TransformMatrix2D.rotate(randomAngle)));
        randomPoint = TransformMatrix2D.rotate(randomAngle).multiply(randomPoint);
        randomPointOnEllipse = TransformMatrix2D.rotate(randomAngle).multiply(randomPointOnEllipse);
        // System.out.printf("RayCast No. %d: Ellipse at (%.2f,%.2f), radii: (%.2f,%.2f). Rotation angle: %.2f, original angle: %.2f, point on ellipse: (%.2f,%.2f), outside point: (%.2f,%.2f), distance: %.2f.\n", 1000-counter, randomEllipse.getCenter().getX(), randomEllipse.getCenter().getY(), randomEllipse.getHorizontalLength(), randomEllipse.getVerticalLength(), randomEllipse.getAngle(), randomAngle, randomPointOnEllipse.getX(), randomPointOnEllipse.getY(), randomPoint.getX(), randomPoint.getY(), randomPoint.distance(randomPointOnEllipse));
        assertEquals("Serial rayCast test for Circle2D.", randomPoint.distance(randomPointOnEllipse), randomEllipse.rayCast(new Ray2D(randomPoint, randomPoint.vec(randomPointOnEllipse))), 0.000005d);
        counter -= 1;
    } while (counter > 0);
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) Ray2D(aima.core.util.math.geom.shapes.Ray2D) Ellipse2D(aima.core.util.math.geom.shapes.Ellipse2D) Test(org.junit.Test)

Example 29 with Point2D

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

the class Polyline2DTest method setUp.

@Before
public void setUp() throws Exception {
    testPolylineOpen = new Polyline2D(testVertices, false);
    testPolylineClosed = new Polyline2D(testVertices, true);
    zeroPoint = new Point2D(0.0d, 0.0d);
}
Also used : Polyline2D(aima.core.util.math.geom.shapes.Polyline2D) Point2D(aima.core.util.math.geom.shapes.Point2D) Before(org.junit.Before)

Example 30 with Point2D

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

the class OsmAgentController method initAgents.

/** Creates new agents and adds them to the current environment. */
protected void initAgents(MessageLogger logger) {
    List<MapNode> markers = map.getOsmMap().getMarkers();
    if (markers.size() < 2) {
        logger.log("Error: Please set two markers with mouse-left.");
        return;
    }
    String[] locs = new String[markers.size()];
    for (int i = 0; i < markers.size(); i++) {
        MapNode node = markers.get(i);
        Point2D pt = new Point2D(node.getLon(), node.getLat());
        locs[i] = map.getNearestLocation(pt);
    }
    MapAgentFrame.SelectionState state = frame.getSelection();
    heuristic = createHeuristic(state.getIndex(MapAgentFrame.HEURISTIC_SEL), locs[1]);
    search = SearchFactory.getInstance().createSearch(state.getIndex(MapAgentFrame.SEARCH_SEL), state.getIndex(MapAgentFrame.Q_SEARCH_IMPL_SEL), heuristic);
    Agent agent = null;
    switch(state.getIndex(MapAgentFrame.AGENT_SEL)) {
        case 0:
            agent = new SimpleMapAgent(map, env, search, new String[] { locs[1] });
            break;
        case 1:
            Problem<String, MoveToAction> p = new BidirectionalMapProblem(map, null, locs[1]);
            OnlineSearchProblem<String, MoveToAction> osp = new GeneralProblem<>(null, p::getActions, null, p::testGoal, p::getStepCosts);
            agent = new LRTAStarAgent<>(osp, MapFunctions.createPerceptToStateFunction(), s -> heuristic.applyAsDouble(new Node<>(s)));
            break;
    }
    env.addAgent(agent, locs[0]);
}
Also used : DecimalFormat(java.text.DecimalFormat) MessageLogger(aima.gui.swing.framework.MessageLogger) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) LRTAStarAgent(aima.core.search.online.LRTAStarAgent) MapAdapter(aimax.osm.routing.MapAdapter) SearchForActions(aima.core.search.framework.SearchForActions) MapAgentFrame(aima.gui.swing.applications.agent.map.MapAgentFrame) ArrayList(java.util.ArrayList) Point2D(aima.core.util.math.geom.shapes.Point2D) AgentAppController(aima.gui.swing.framework.AgentAppController) List(java.util.List) Node(aima.core.search.framework.Node) OnlineSearchProblem(aima.core.search.framework.problem.OnlineSearchProblem) MapWayAttFilter(aimax.osm.data.MapWayAttFilter) ToDoubleFunction(java.util.function.ToDoubleFunction) MapNode(aimax.osm.data.entities.MapNode) Agent(aima.core.agent.Agent) SimulationThread(aima.gui.swing.framework.SimulationThread) aima.core.environment.map(aima.core.environment.map) Problem(aima.core.search.framework.problem.Problem) SearchFactory(aima.gui.util.SearchFactory) LRTAStarAgent(aima.core.search.online.LRTAStarAgent) Agent(aima.core.agent.Agent) MapNode(aimax.osm.data.entities.MapNode) aima.core.environment.map(aima.core.environment.map) Point2D(aima.core.util.math.geom.shapes.Point2D) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) MapAgentFrame(aima.gui.swing.applications.agent.map.MapAgentFrame)

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