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)?
- Curvature: https://en.wikipedia.org/wiki/Curvature
- Menger Curvature: https://en.wikipedia.org/wiki/Menger_curvature
From the wiki you referenced, the curvature is defined as
where A is the area enclosed by the triangle formed by the three points, x, y and z (p1, p2, p3 in your case) and |x-y| is the distance between points x and y.
Translate the formula to code and you're done!
As already pointed out by Eric Duminil in his answer, the computation is
I wasted some time with creating this interactive example that contains a
computeCurvature
method that does the whole computation at once: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 :
There's not much more to do. Warning :
area2
returns a signed double, depending on the orientation of your points (clockwise or anticlockwise).