For example, you can create an array of angles between each 2 segments, angles[1, n], angles[i] = get_angle(points[i], points[i - 1]) - get_angle(points[i + 1], points[i])
Then to create an array of the differencies between each angle and the previous one, d_angles[1, n], d_angles[i] = angles[i] - angles[i-1]
Then you can sum absolute values of all d_angles, s = sum(abs(all d_angles)).
Then you can concede, that normal deviation for a line is, for example, da = 5 degrees a point, and
And then if s < n * da, then it's a line.
And if (s > pi * 2 - k) and (s < pi * 2 + k), where k = 10 degrees (for example), then it's a circle.
If it's not a circle and not a line, we can assume it's a different kind of shape.
P.S. You need to include angle which includes points[n]<->points[1] segment if only the length of this segment significantly less then the lenght of the whole line.
P.P.S. If points[n] realy close to points[1], the sum of d_angles will be close to a multiply of 2 * pi, so every random shape with even amount of self crossings will be declared as a circle.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
For example, you can create an array of angles between each 2 segments, angles[1, n], angles[i] = get_angle(points[i], points[i - 1]) - get_angle(points[i + 1], points[i])
Then to create an array of the differencies between each angle and the previous one, d_angles[1, n], d_angles[i] = angles[i] - angles[i-1]
Then you can sum absolute values of all d_angles, s = sum(abs(all d_angles)).
Then you can concede, that normal deviation for a line is, for example, da = 5 degrees a point, and
And then if s < n * da, then it's a line.
And if (s > pi * 2 - k) and (s < pi * 2 + k), where k = 10 degrees (for example), then it's a circle.
If it's not a circle and not a line, we can assume it's a different kind of shape.
P.S. You need to include angle which includes points[n]<->points[1] segment if only the length of this segment significantly less then the lenght of the whole line.
P.P.S. If points[n] realy close to points[1], the sum of d_angles will be close to a multiply of 2 * pi, so every random shape with even amount of self crossings will be declared as a circle.