Search in sources :

Example 1 with Point2f

use of com.robo4j.math.geometry.Point2f in project robo4j by Robo4J.

the class RaycastTest method testMisbehavingData.

@Disabled("08.09.17 we enable it when it works :)")
@Test
void testMisbehavingData() {
    ScanResultImpl scan = new ScanResultImpl(1.0f, new Predicate<Point2f>() {

        @Override
        public boolean test(Point2f t) {
            return t.getRange() >= 0.08;
        }
    });
    scan.addPoint(Point2f.fromPolar(2.2f, 35.5f));
    scan.addPoint(Point2f.fromPolar(2.2f, 34.5f));
    scan.addPoint(Point2f.fromPolar(2.3f, 33.5f));
    scan.addPoint(Point2f.fromPolar(2.0f, 32.5f));
    scan.addPoint(Point2f.fromPolar(1.9f, 31.5f));
    scan.addPoint(Point2f.fromPolar(1.8f, 30.5f));
    scan.addPoint(Point2f.fromPolar(3.7f, 29.5f));
    scan.addPoint(Point2f.fromPolar(3.8f, 28.5f));
    scan.addPoint(Point2f.fromPolar(2.3f, 27.5f));
    scan.addPoint(Point2f.fromPolar(3.3f, 26.5f));
    scan.addPoint(Point2f.fromPolar(4.2f, 25.5f));
    scan.addPoint(Point2f.fromPolar(3.9f, 24.5f));
    scan.addPoint(Point2f.fromPolar(3.1f, 23.5f));
    scan.addPoint(Point2f.fromPolar(3.7f, 22.5f));
    scan.addPoint(Point2f.fromPolar(3.6f, 21.5f));
    scan.addPoint(Point2f.fromPolar(3.4f, 20.5f));
    scan.addPoint(Point2f.fromPolar(3.3f, 19.5f));
    scan.addPoint(Point2f.fromPolar(3.1f, 18.5f));
    scan.addPoint(Point2f.fromPolar(3.0f, 17.5f));
    scan.addPoint(Point2f.fromPolar(2.8f, 16.5f));
    scan.addPoint(Point2f.fromPolar(2.8f, 15.5f));
    scan.addPoint(Point2f.fromPolar(2.8f, 14.5f));
    scan.addPoint(Point2f.fromPolar(2.8f, 13.5f));
    scan.addPoint(Point2f.fromPolar(2.8f, 12.5f));
    scan.addPoint(Point2f.fromPolar(2.8f, 11.5f));
    scan.addPoint(Point2f.fromPolar(2.9f, 10.5f));
    scan.addPoint(Point2f.fromPolar(2.9f, 9.5f));
    scan.addPoint(Point2f.fromPolar(2.9f, 8.5f));
    scan.addPoint(Point2f.fromPolar(2.9f, 7.5f));
    scan.addPoint(Point2f.fromPolar(2.9f, 6.5f));
    scan.addPoint(Point2f.fromPolar(2.8f, 5.5f));
    scan.addPoint(Point2f.fromPolar(2.7f, 4.5f));
    scan.addPoint(Point2f.fromPolar(2.7f, 3.5f));
    scan.addPoint(Point2f.fromPolar(2.6f, 2.5f));
    scan.addPoint(Point2f.fromPolar(2.6f, 1.5f));
    scan.addPoint(Point2f.fromPolar(2.5f, 0.5f));
    scan.addPoint(Point2f.fromPolar(2.4f, -0.5f));
    scan.addPoint(Point2f.fromPolar(2.4f, -1.5f));
    scan.addPoint(Point2f.fromPolar(2.4f, -2.5f));
    scan.addPoint(Point2f.fromPolar(2.5f, -3.5f));
    scan.addPoint(Point2f.fromPolar(2.5f, -4.5f));
    scan.addPoint(Point2f.fromPolar(3.0f, -5.5f));
    scan.addPoint(Point2f.fromPolar(3.2f, -6.5f));
    scan.addPoint(Point2f.fromPolar(3.2f, -7.5f));
    scan.addPoint(Point2f.fromPolar(3.4f, -8.5f));
    scan.addPoint(Point2f.fromPolar(3.4f, -9.5f));
    scan.addPoint(Point2f.fromPolar(3.5f, -10.5f));
    scan.addPoint(Point2f.fromPolar(3.4f, -11.5f));
    scan.addPoint(Point2f.fromPolar(3.5f, -12.5f));
    scan.addPoint(Point2f.fromPolar(3.4f, -13.5f));
    scan.addPoint(Point2f.fromPolar(3.4f, -14.5f));
    scan.addPoint(Point2f.fromPolar(3.4f, -15.5f));
    scan.addPoint(Point2f.fromPolar(3.3f, -16.5f));
    scan.addPoint(Point2f.fromPolar(3.3f, -17.5f));
    scan.addPoint(Point2f.fromPolar(3.2f, -18.5f));
    scan.addPoint(Point2f.fromPolar(3.2f, -19.5f));
    scan.addPoint(Point2f.fromPolar(3.2f, -20.5f));
    scan.addPoint(Point2f.fromPolar(3.2f, -21.5f));
    scan.addPoint(Point2f.fromPolar(3.1f, -22.5f));
    scan.addPoint(Point2f.fromPolar(3.1f, -23.5f));
    FeatureSet features = FeatureExtraction.getFeatures(scan.getPoints(), 1.0f);
    assertNotNull(features);
    // FIXME: Remove the next two lines when the test is properly fixed.
    assertNotEquals(DELTA, 0);
    assertNotNull(ORIGO);
    Point2f promisingPoint = Raycast.raycastFarthestPoint(scan.getPoints(), 0.4f, 0.3f, features);
    assertNotNull(promisingPoint);
// assertNotEquals(ORIGO.getX(), promisingPoint.getX(), DELTA);
// assertNotEquals(ORIGO.getY(), promisingPoint.getY(), DELTA);
}
Also used : Point2f(com.robo4j.math.geometry.Point2f) ScanResultImpl(com.robo4j.math.geometry.impl.ScanResultImpl) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with Point2f

use of com.robo4j.math.geometry.Point2f in project robo4j by Robo4J.

the class FeatureExtraction method calculateKB.

public static int calculateKB(List<Point2f> Point2fs, int Point2DIndex) {
    if (Point2DIndex < 1) {
        return 0;
    }
    float length = 0;
    float distance = 0;
    Point2f startPoint2D = Point2fs.get(Point2DIndex);
    int i = Point2DIndex;
    while (i > 0) {
        length += Point2fs.get(i - 1).distance(Point2fs.get(i));
        distance = Point2fs.get(i - 1).distance(startPoint2D);
        if ((length - Uk) >= distance) {
            break;
        }
        i--;
    }
    return Point2DIndex - i;
}
Also used : CurvaturePoint2f(com.robo4j.math.geometry.CurvaturePoint2f) Point2f(com.robo4j.math.geometry.Point2f)

Example 3 with Point2f

use of com.robo4j.math.geometry.Point2f in project robo4j by Robo4J.

the class FeatureExtraction method calculateKF.

public static int calculateKF(List<Point2f> Point2fs, int Point2DIndex) {
    if (Point2DIndex >= Point2fs.size() - 1) {
        return 0;
    }
    double length = 0;
    double distance = 0;
    Point2f startPoint2D = Point2fs.get(Point2DIndex);
    int i = Point2DIndex;
    while (i < Point2fs.size() - 1) {
        length += Point2fs.get(i + 1).distance(Point2fs.get(i));
        distance = Point2fs.get(i + 1).distance(startPoint2D);
        if ((length - Uk) >= distance) {
            break;
        }
        i++;
    }
    return i - Point2DIndex;
}
Also used : CurvaturePoint2f(com.robo4j.math.geometry.CurvaturePoint2f) Point2f(com.robo4j.math.geometry.Point2f)

Example 4 with Point2f

use of com.robo4j.math.geometry.Point2f in project robo4j by Robo4J.

the class FeatureExtraction method extractCorners.

private static Collection<? extends CurvaturePoint2f> extractCorners(List<Point2f> Point2fs, float[] deltaAngles) {
    List<CurvaturePoint2f> corners = new ArrayList<>();
    for (int i = 0; i < deltaAngles.length; i++) {
        if (Math.abs(deltaAngles[i]) > CURVATURE_THRESHOLD) {
            int maxIndex = i;
            float maxPhi = deltaAngles[i];
            float totalPhi = maxPhi;
            int last = Math.min(i + 4, deltaAngles.length);
            for (int k = i + 1; k < last; k++) {
                totalPhi += deltaAngles[k];
                if (deltaAngles[k] > maxPhi) {
                    maxPhi = deltaAngles[k];
                    maxIndex = k;
                }
                i = k;
            }
            if (Math.abs(totalPhi) > CORNER_THRESHOLD && Math.signum(totalPhi) == Math.signum(maxPhi) && maxIndex - 3 >= 0 && maxIndex + 4 < deltaAngles.length) {
                Point2f p = Point2fs.get(maxIndex);
                Point2f b = Point2fs.get(maxIndex - 3);
                Point2f f = Point2fs.get(maxIndex + 3);
                float cornerAlpha = calculateVectorAngle(b, p, f);
                if (cornerAlpha > CORNER_THRESHOLD) {
                    corners.add(CurvaturePoint2f.fromPoint(p, cornerAlpha));
                }
            }
        }
    }
    return corners;
}
Also used : CurvaturePoint2f(com.robo4j.math.geometry.CurvaturePoint2f) CurvaturePoint2f(com.robo4j.math.geometry.CurvaturePoint2f) Point2f(com.robo4j.math.geometry.Point2f) ArrayList(java.util.ArrayList)

Example 5 with Point2f

use of com.robo4j.math.geometry.Point2f in project robo4j by Robo4J.

the class FeatureExtraction method main.

public static final void main(String[] args) {
    Point2f b = Point2f.fromPolar(18, 18);
    Point2f center = Point2f.fromPolar(19, 19);
    Point2f f = Point2f.fromPolar(20, 20);
    float radians = calculateVectorAngle(b, center, f);
    System.out.println("Vec angle: " + Math.toDegrees(radians) + " radians: " + radians);
}
Also used : CurvaturePoint2f(com.robo4j.math.geometry.CurvaturePoint2f) Point2f(com.robo4j.math.geometry.Point2f)

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