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