use of com.robo4j.math.geometry.Point2f in project robo4j by Robo4J.
the class FeatureExtraction method segment.
/**
* Calculates the segments in the scan, using the Borg and Aldon adaptive
* break algorithm.
*
* @param Point2fs
* the Point2fs to segment.
* @param angularResolution
* of the scan in radians.
*
* @return the Point2fs broken up into segments.
*/
public static List<List<Point2f>> segment(List<Point2f> Point2fs, float angularResolution) {
List<List<Point2f>> segments = new ArrayList<List<Point2f>>(10);
Iterator<Point2f> iterator = Point2fs.iterator();
List<Point2f> currentSegment = new ArrayList<Point2f>();
segments.add(currentSegment);
Point2f lastPoint2D = iterator.next();
currentSegment.add(lastPoint2D);
while (iterator.hasNext()) {
Point2f nextPoint2D = iterator.next();
float delta = nextPoint2D.distance(lastPoint2D);
double maxRange = segmentMaxRange(lastPoint2D.getRange(), angularResolution);
if (delta > maxRange) {
currentSegment = new ArrayList<Point2f>();
segments.add(currentSegment);
}
currentSegment.add(nextPoint2D);
lastPoint2D = nextPoint2D;
}
return segments;
}
use of com.robo4j.math.geometry.Point2f in project robo4j by Robo4J.
the class FeatureExtraction method calculateSamplePoint2DDeltaAngles.
public static float[] calculateSamplePoint2DDeltaAngles(List<Point2f> Point2fs) {
if (Point2fs.size() < 5) {
return null;
}
float[] alphas = new float[Point2fs.size()];
for (int i = 0; i < Point2fs.size(); i++) {
if (i == 0 || i == Point2fs.size() - 1) {
alphas[i] = 0;
continue;
}
int kb = calculateKB(Point2fs, i);
int kf = calculateKF(Point2fs, i);
Point2f before = Point2fs.get(i - kb);
Point2f center = Point2fs.get(i);
Point2f following = Point2fs.get(i + kf);
alphas[i] = calculateVectorAngle(before, center, following);
}
return alphas;
}
use of com.robo4j.math.geometry.Point2f in project robo4j by Robo4J.
the class FeatureExtraction method calculateSimpleVectorAngles.
public static float[] calculateSimpleVectorAngles(List<Point2f> Point2fs) {
if (Point2fs.size() < 5) {
return null;
}
float[] alphas = new float[Point2fs.size()];
for (int i = 0; i < Point2fs.size(); i++) {
Point2f before = i == 0 ? Point2fs.get(0) : Point2fs.get(i - 1);
Point2f center = Point2fs.get(i);
Point2f following = i == Point2fs.size() - 1 ? Point2fs.get(i) : Point2fs.get(i + 1);
alphas[i] = calculateVectorAngle(before, center, following);
}
return alphas;
}
use of com.robo4j.math.geometry.Point2f in project robo4j by Robo4J.
the class Raycast method raycastSingle.
/**
* Casts a single ray at the specified angle, and returns the distance at
* which it hit something, or {@link Float#MAX_VALUE} if it did not hit
* anything.
*
* @param points
* the points to check against.
* @param corners
* the points known to be corners.
* @param rayAlpha
* the angle to emit the ray at.
* @param defaultNoGoRadius
* the radius around a known point to avoid.
* @return the distance at which the ray hit something.
*/
public static float raycastSingle(List<Point2f> points, List<CurvaturePoint2f> corners, float rayAlpha, float defaultNoGoRadius) {
float minIntersectionRange = Float.MAX_VALUE;
float currentNoGoRadius = defaultNoGoRadius;
for (Point2f p : points) {
CurvaturePoint2f cornerPoint = getMatchingCornerPoint(corners, p);
if (cornerPoint != null) {
currentNoGoRadius = calculateNoGoRadius(cornerPoint, defaultNoGoRadius);
} else {
currentNoGoRadius = defaultNoGoRadius;
}
float tangentDistance = calculateTangentDistance(rayAlpha, p);
// Fast rejection
if (Math.abs(tangentDistance) >= currentNoGoRadius) {
continue;
}
float intersectionRange = calculateIntersectionRange(rayAlpha, currentNoGoRadius, tangentDistance, p);
if (!Float.isNaN(intersectionRange)) {
minIntersectionRange = Math.min(minIntersectionRange, intersectionRange);
}
}
return minIntersectionRange;
}
Aggregations