It is quite easy to calculate but most of the time there is 2 solutions. So I choose to use curve intersection of RhinoCommon to make the calculations.
360deg_angle_polygon.gh (1.7 MB)
/// <summary>
/// Return points which have a 360° sum angle with the polygon points
/// </summary>
/// <param name="polyline">A closed polyline</param>
/// <returns>The line</returns>
public List<Point3d> GetFlatCenterOfPolyline(Polyline polyline)
{
//Center of polygon
Point3d center = polyline.CenterPoint();
//Plane used to have a normal
Plane plane = Plane.Unset;
PlaneFitResult plfit = Plane.FitPlaneToPoints(polyline, out plane);
//Calculation of a typical length
BoundingBox bb = polyline.BoundingBox;
double length = bb.Diagonal.Length / 4;
Line line = new Line(center + plane.ZAxis * length, center - plane.ZAxis * length);
//For many points on a line calculate the angles sum
List<Point3d> points = new List<Point3d> ();
for (double d = 0; d < 1.0; d += 0.01)
{
points.Add(new Point3d(d, GetAngle(polyline, line.PointAt(d)), 0));
}
//The angle sum is a curve with the line parameter in abcisse (Y) and the angle sum in ordinate (Y)
Curve curve = Curve.CreateInterpolatedCurve(points, 3);
//A line at ordinate = 2 * PI
Line line2 = new Line(new Point3d(0, Math.PI * 2, 0.0), new Point3d(1, Math.PI * 2, 0.0));
//The intersection calculation
CurveIntersections ci = Rhino.Geometry.Intersect.Intersection.CurveLine(curve, line2, 0.0001, 0.0001);
List<Point3d> output = new List<Point3d> ();
for (int i = 0; i < ci.Count; i++)
{
output.Add(line.PointAt(ci[i].ParameterB));
}
return output;
}
/// <summary>
/// Calculate the angle sum from vector from the point to the polyline point
///Polyline must be closed
/// </summary>
/// <param name="polyline"></param>
/// <param name="point"></param>
/// <returns></returns>
public double GetAngle(Polyline polyline, Point3d point)
{
double angle = 0.0;
for (int i = 0; i < (polyline.Count - 1);i++)
{
Vector3d v1 = polyline[i] - point;
Vector3d v2 = polyline[i + 1] - point;
angle += Vector3d.VectorAngle(v1, v2);
}
return angle;
}
``