AutoStereogramDemo.AutoStereogramBuilder.AddCylinder C# (CSharp) Метод

AddCylinder() публичный Метод

public AddCylinder ( Point3D p1, Point3D p2, double radius ) : void
p1 Point3D
p2 Point3D
radius double
Результат void
        public void AddCylinder(Point3D p1, Point3D p2, double radius)
        {
            Vector3D v1 = (p1 - p2).GetSomeOrtVector().Normalize() * Math.Sqrt(2);
            Vector3D v2 = Vector3D.CrossProduct(v1, p1 - p2).Normalize() * Math.Sqrt(2);
            Point3D[] points = new Point3D[] { p1 - v1 * radius, p1 + v1 * radius, p1 - v2 * radius, p1 + v2 * radius,
             p2 - v1 * radius, p2 + v1 * radius, p2 - v2 * radius, p2 + v2 * radius };

            AddRayTracedObject(points,
             (int xProj, int yProj, double eyeXPos, out double x, out double z) => GetCylinderRayIntersection(p1, p2, radius, xProj, yProj, eyeXPos, out x, out z));
        }

Usage Example

Пример #1
0
        private static void CreateFigures()
        {
            var asb = new AutoStereogramBuilder(1024, 768, 3);

            asb.AddHorizontalPlane(2);

            Vector3D v1 = new Vector3D {
                X = 1, Y = 0, Z = 0
            };

            for (int n = 0; n < 4; n++)
            {
                Vector3D v2 = new Vector3D {
                    X = 0, Y = Math.Cos(n * Math.PI / 8), Z = -Math.Sin(n * Math.PI / 8)
                };
                Vector3D v3 = new Vector3D {
                    X = 0, Y = Math.Sin(n * Math.PI / 8), Z = Math.Cos(n * Math.PI / 8)
                };

                // hexagonal prism

                Point3D[] prismUpperPoints = new Point3D[6], prismLowerPoints = new Point3D[6];

                for (int m = 0; m < 6; m++)
                {
                    prismUpperPoints[m] = new Point3D {
                        X = -0.2 + n * 0.25, Y = -0.2, Z = 1.7
                    } +v1 *Math.Sin(m / 3.0 *Math.PI) * 0.1 + v2 * Math.Cos(m / 3.0 * Math.PI) * 0.1 - v3 * 0.05;

                    prismLowerPoints[m] = new Point3D {
                        X = -0.2 + n * 0.25, Y = -0.2, Z = 1.7
                    } +v1 *Math.Sin(m / 3.0 *Math.PI) * 0.1 + v2 * Math.Cos(m / 3.0 * Math.PI) * 0.1 + v3 * 0.05;
                }

                asb.AddPolygon(prismUpperPoints);
                asb.AddPolygon(prismLowerPoints);

                for (int m = 0; m < 6; m++)
                {
                    asb.AddPolygon(new Point3D[] { prismLowerPoints[m], prismUpperPoints[m], prismUpperPoints[(m + 1) % 6], prismLowerPoints[(m + 1) % 6] });
                }

                // cylinder

                asb.AddCylinder(new Point3D {
                    X = -0.2 + n * 0.25, Y = 0.1, Z = 1.7
                } -v3 * 0.1, new Point3D {
                    X = -0.2 + n * 0.25, Y = 0.1, Z = 1.7
                } +v3 * 0.1, 0.08);

                // octahedron

                Point3D octahedronCenter = new Point3D {
                    X = -0.2 + n * 0.25, Y = 0.4, Z = 1.7
                };
                Point3D   octahedronUpperPoint = octahedronCenter - v3 * 0.1 * Math.Sqrt(2), octahedronLowerPoint = octahedronCenter + v3 * 0.1 * Math.Sqrt(2);
                Point3D[] octahedronMiddlePoints = new Point3D[] { octahedronCenter + v1 * 0.1 + v2 * 0.1, octahedronCenter - v1 * 0.1 + v2 * 0.1,
                                                                   octahedronCenter - v1 * 0.1 - v2 * 0.1, octahedronCenter + v1 * 0.1 - v2 * 0.1 };

                for (int m = 0; m < 4; m++)
                {
                    asb.AddPolygon(new Point3D[] { octahedronUpperPoint, octahedronMiddlePoints[m], octahedronMiddlePoints[(m + 1) % 4] });
                    asb.AddPolygon(new Point3D[] { octahedronLowerPoint, octahedronMiddlePoints[m], octahedronMiddlePoints[(m + 1) % 4] });
                }
            }

            asb.GenerateBitmap().Save(GetPathAtAssemblyLocation("output\\figures.gif"), ImageFormat.Gif);
        }