javapointcurve

Calculate curvature for 3 Points (x,y)


I have a two dimensional euclidean space. Three points are given.

For example (p2 is the middle point):

Point2D p1 = new Point2D.Double(177, 289);
Point2D p2 = new Point2D.Double(178, 290);
Point2D p3 = new Point2D.Double(178, 291);

Now i want to calculate the curvature for these three points.

double curvature = calculateCurvature(p1, p2, p3);

How to do this? Ist there a existing method (no java external libraries)?


Solution

  • For the Menger Curvature, the formula is right there in the Wikipedia article :

    curvature = 4*triangleArea/(sideLength1*sideLength2*sideLength3)

    Which code did you try exactly?

    It shouldn't be too hard to calculate those 4 values given your 3 points.

    Here are some helpful methods :

    /**
     * Returns twice the signed area of the triangle a-b-c.
     * @param a first point
     * @param b second point
     * @param c third point
     * @return twice the signed area of the triangle a-b-c
     */
    public static double area2(Point2D a, Point2D b, Point2D c) {
        return (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x);
    }
    
    /**
     * Returns the Euclidean distance between this point and that point.
     * @param that the other point
     * @return the Euclidean distance between this point and that point
     */
    public double distanceTo(Point2D that) {
        double dx = this.x - that.x;
        double dy = this.y - that.y;
        return Math.sqrt(dx*dx + dy*dy);
    }
    

    There's not much more to do. Warning : area2 returns a signed double, depending on the orientation of your points (clockwise or anticlockwise).