AutoStereogramDemo.AutoStereogramBuilder.AddPolygon C# (CSharp) Method

AddPolygon() public method

public AddPolygon ( Point3D points ) : void
points Point3D
return void
        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)));
        }

Usage Example

Example #1
0
        private static void CreatePipe(AutoStereogramBuilder asb, List <Circle3D> circles, Vector3D firstDirection = null)
        {
            List <Point3D> prevPoints = null;
            Vector3D       v1 = null, v2 = null;

            if (firstDirection == null)
            {
                firstDirection = circles[1].Center - circles[0].Center;
            }

            for (int n = 0; n < circles.Count; n++)
            {
                if (n == 0)
                {
                    GetSomeOrthonormalizedVectors(firstDirection, out v1, out v2);
                }
                else
                {
                    GetNextOrthonormalizedVectors((n == 1 ? firstDirection : circles[n - 1].Center - circles[n - 2].Center).Normalize(),
                                                  (circles[n].Center - circles[n - 1].Center).Normalize(), v1, v2, out v1, out v2);
                }

                List <Point3D> points = GetCirclePoints(circles[n].Center, circles[n].Radius, v1, v2);

                if (prevPoints != null)
                {
                    for (int m = 0; m < points.Count; m++)
                    {
                        Point3D p1 = points[m], p2 = prevPoints[m], p3 = points[(m + 1) % points.Count], p4 = prevPoints[(m + 1) % points.Count];

                        asb.AddPolygon(new Point3D[] { p1, p2, p3 });
                        asb.AddPolygon(new Point3D[] { p2, p3, p4 });
                    }
                }

                prevPoints = points;
            }
        }
All Usage Examples Of AutoStereogramDemo.AutoStereogramBuilder::AddPolygon