Commit 5bf93e39 authored by Julian Zobel's avatar Julian Zobel
Browse files

Random attraction generator now also gives a randomly generated radius to all...

Random attraction generator now also gives a randomly generated radius to all APs. APs cannot have overlapping Radii
parent 914db13b
......@@ -39,10 +39,11 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* position randomly within the world dimensions.
*
* v1.1: statically available attraction points [JZ]
* v1.2: added a minimum distance between attraction points [JZ]
* v1.2: added a minimum distance between attraction points [JZ]
* v1.21: added a random radius to attraction points. Minimum is 10 meters, default maximum 100 meters. APs cannot have overlapping radii.
*
* @author Christoph Muenker, Julian Zobel
* @version 1.2, 11 2018
* @version 1.21, 12 2018
*/
public class RandomAttractionGenerator implements IAttractionGenerator {
......@@ -56,6 +57,8 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
private double minimumDistance = 50;
private double maximumRadius = 100;
@XMLConfigurableConstructor({"numberOfAttractionPoints"})
public RandomAttractionGenerator(int numberOfAttractionPoints) {
this.rand = Randoms.getRandom(RandomAttractionGenerator.class);
......@@ -89,15 +92,21 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
create: for (int i = 0; i < numberOfAttractionPoints; i++) {
PositionVector posVec = createPosVec();
AttractionPoint aPoint = new AttractionPointImpl("AP-"+i, posVec);
// set the radius of this attraction point
// minimum radius is 10 meters
aPoint.setRadius(Math.max(10, rand.nextDouble() * maximumRadius));
for (AttractionPoint ap : result) {
if(posVec.distanceTo(ap) < minimumDistance) {
// if this point is closer than the given minimum distance to another point, or the radii of the points would overlap,
// then discard this attraction point and create a new one
if(aPoint.distanceTo(ap) < minimumDistance || (aPoint.distanceTo(ap) - aPoint.getRadius() - ap.getRadius()) < 0) {
i--;
continue create;
}
}
AttractionPoint aPoint = new AttractionPointImpl("AP"+i, posVec);
result.add(aPoint);
}
......@@ -118,4 +127,12 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
public void setMinimumDistance(double distance) {
this.minimumDistance = distance;
}
/**
* Set a maximum radius that an attraction point can have. Minimum is 10 meters.
* @param radius
*/
public void setMaximumRadius(double radius) {
this.maximumRadius = radius;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment