Below is one possible approach. The function returns true or false depending if the polygon has any angles below a certain size or is within a range around a target angle. Just keep in mind this is a very simple approach and assumes straight line digitizing. I do test for a circle, but do not test for curves or other possibilities that could trip up the function.
angleTarget = desired angle (ex. 90).
edgeVariance = allowable waffle of straight line (ex. 0.5 degree direction change allowed).
angleVariance = allowable deviation of desired angle (ex. 1 if 91 degrees is OK).
Brian
private static bool AngleWithinTolerance(IPolygon pPoly, double angletarget, double edgeVariance, double angleVariance)
{
GeometryEnvironment geometryEnvironment = new GeometryEnvironment();
IConstructAngle constructAngle = geometryEnvironment as IConstructAngle;
IPointCollection ptcol = (IPointCollection)pPoly;
double angle;
//No circles!
if (ptcol.PointCount < 3) return false;
//Check angle made by last point first point and second point in the collection.
angle = Math.Abs(constructAngle.ConstructThreePoint(ptcol.get_Point(ptcol.PointCount - 2), ptcol.get_Point(0), ptcol.get_Point(1)) * (180/3.14159250439667));
if (angle < edgeVariance || (angle < angletarget + angleVariance & angle > angletarget - angleVariance))
{
//Angle at index 0 is OK - check all other points in collection.
for (int x = 0; x != ptcol.PointCount - 2; x++)
{
angle = Math.Abs(constructAngle.ConstructThreePoint(ptcol.get_Point(x), ptcol.get_Point(x + 1), ptcol.get_Point(x + 2)) * (180 / 3.14159250439667));
if (angle > edgeVariance & (angle > angletarget + angleVariance || angle < angletarget - angleVariance))
{
return false;
}
}
}
else
{
return false;
}
//never failed.
return true;
}