I'm trying to write a genetic algorithm with curvature as one of the optimization parameters. I want to calculate curvature based on the control points of a bezier curve. I have a minimum radius of curvature that I want to be optimized for. I've been referencing this paper: https://arxiv.org/pdf/1503.01524.pdf
In the paper there is a function that takes the side lengths of a triangle to get the implied radius of curvature, which I have implemented. Here is my current code:
// Computes the curvature implied by 3 control points of a bezier curve
float curvature(float4 p0, float4 p1, float4 p2) {
// Get the triangle side lengths
float a = distance(p0, p1);
float b = distance(p1, p2);
float c = distance(p2, p0);
// Do the curvature calculation
float num = a * b * c;
float denom = (a + b + c) * (b + c - a) * (a - b + c) * (a + b - c);
return num / sqrt(denom);
}
The results of this function seem to be incorrect. I run this function for every point in the path, save the last two and then get the minimum radius out of all of them. When I graph the path, there seems to be a major discrepancy between this function's calculation and what I can see visually. Whats the right method to do this?
EDIT: I was looking to calculate the radius of curvature between three control points, not at a given point in the curve, apologies if this was unclear.