public void AddPolygon(Point3D[] points)
{
if (points.Length < 3)
throw new ArgumentException("points.Length < 3");
Point3D innerPoint = new Point3D { X = points.Average(p => p.X), Y = points.Average(p => p.Y), Z = points.Average(p => p.Z) };
Vector3D ortVec = Vector3D.CrossProduct(innerPoint - points[0], points[1] - points[0]);
Plane plane = new Plane(ortVec, points[0]);
Plane[] ortPlanes = new Plane[points.Length];
for (int n = 0; n < points.Length; n++)
{
ortPlanes[n] = new Plane(Vector3D.CrossProduct(points[(n + 1) % points.Length] - points[n], ortVec), points[n]);
ortPlanes[n].Normalize();
}
AddRayTracedObject(points, (int xProj, int yProj, double eyeXPos, out double x, out double z) =>
GetPlaneRayIntersection(xProj, yProj, eyeXPos, plane.A, plane.B, plane.C, plane.D, out x, out z, (x1, y1, z1) => ortPlanes.All(p => p.A * x1 + p.B * y1 + p.C * z1 + p.D > -1e-8)));
}