Search in sources :

Example 6 with Point2f

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;
}
Also used : CurvaturePoint2f(com.robo4j.math.geometry.CurvaturePoint2f) Point2f(com.robo4j.math.geometry.Point2f) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with Point2f

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;
}
Also used : CurvaturePoint2f(com.robo4j.math.geometry.CurvaturePoint2f) Point2f(com.robo4j.math.geometry.Point2f)

Example 8 with Point2f

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;
}
Also used : CurvaturePoint2f(com.robo4j.math.geometry.CurvaturePoint2f) Point2f(com.robo4j.math.geometry.Point2f)

Example 9 with Point2f

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;
}
Also used : CurvaturePoint2f(com.robo4j.math.geometry.CurvaturePoint2f) Point2f(com.robo4j.math.geometry.Point2f) CurvaturePoint2f(com.robo4j.math.geometry.CurvaturePoint2f)

Aggregations

Point2f (com.robo4j.math.geometry.Point2f)9 CurvaturePoint2f (com.robo4j.math.geometry.CurvaturePoint2f)8 ArrayList (java.util.ArrayList)2 ScanResultImpl (com.robo4j.math.geometry.impl.ScanResultImpl)1 List (java.util.List)1 Disabled (org.junit.jupiter.api.Disabled)1 Test (org.junit.jupiter.api.Test)1