Calculate curvature for 3 Points (x,y)

后端 未结 4 1246
礼貌的吻别
礼貌的吻别 2021-01-13 12:22

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);
Po         


        
4条回答
  •  無奈伤痛
    2021-01-13 13:02

    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).

提交回复
热议问题