Esempio n. 1
0
        private static Color RandColor(Random rand)
        {
            double   hue = rand.NextDouble() * 360;
            double   sat = RandDouble(rand, .2, 1.0);
            double   lum = RandDouble(rand, .2, 1.0);
            Vector3D rgb = ColorUtil.CHSL2RGB(new Vector3D(hue, sat, lum));

            return(ColorUtil.FromRGB(rgb));
        }
Esempio n. 2
0
        public static void Test()
        {
            HoneycombDef def     = new HoneycombDef(5, 3, 4);
            Simplex      simplex = new Simplex();

            simplex.Facets = SimplexCalcs.Mirrors(def.P, def.Q, def.R);

            // Simplices will be the "cells"
            H3.Cell.Facet[] simplexFacets = simplex.Facets.Select(m => new H3.Cell.Facet(m)).ToArray();
            H3.Cell         startingCell  = new H3.Cell(simplexFacets);
            startingCell.AuxPoints = SimplexCalcs.VertsBall(def.P, def.Q, def.R);
            startingCell.Center    = HoneycombPaper.InteriorPointBall;

            var cells = CalcCells(simplex.Facets, new H3.Cell[] { startingCell });

            // Get all the cell centers
            HashSet <Vector3D> centers = new HashSet <Vector3D>();

            foreach (var cell in cells)
            {
                Vector3D cellCen = cell.AuxPoints[0];
                centers.Add(cellCen);
            }

            // Colors.
            Dictionary <double, Color> colors = new Dictionary <double, Color>(new DoubleEqualityComparer());

            System.Random rand = new System.Random(0);

            // Get all the in-spheres
            double inRad = startingCell.AuxPoints[1].Abs();
            //inRad *= 1.16;
            List <Sphere> inSpheres = new List <Sphere>();

            foreach (Vector3D c in centers)
            {
                Vector3D p = c;
                //SphericalModels.GnomonicToStereo( c );
                Geometry g = Geometry.Hyperbolic;

                Vector3D cen;
                double   rad;
                H3Models.Ball.DupinCyclideSphere(p, inRad, g, out cen, out rad);
                Sphere i = new Sphere(cen, rad);

                Color color;
                if (!colors.TryGetValue(c.Abs(), out color))
                {
                    Vector3D rgb = ColorUtil.CHSL2RGB(new Vector3D(rand.NextDouble() * 360, .5, .5));
                    rgb            *= 255;
                    color           = Color.FromArgb(255, (int)rgb.X, (int)rgb.Y, (int)rgb.Z);
                    colors[c.Abs()] = color;
                }
                i.Color = color;

                inSpheres.Add(i);
            }

            // Project sphere to unit sphere.
            List <Circle3D> circlesOnUnitSphere = new List <Circle3D>();

            foreach (Sphere i in inSpheres)
            {
                if (i.Center.IsOrigin || i.Center.DNE || Infinity.IsInfinite(i.Center))
                {
                    continue;
                }

                Sphere   orthogonal = new Sphere(new Vector3D(), RadiusOrthogonal(i));
                Circle3D c          = orthogonal.Intersection(i);

                // We need to scale this based on the size of the orthogonal sphere.
                c.Center /= orthogonal.Radius;
                c.Radius /= orthogonal.Radius;
                c.Color   = i.Color;
                circlesOnUnitSphere.Add(c);
            }
            Circle3D unit = new Circle3D();

            //circlesOnUnitSphere.Add( unit );

            ProjectAndSave(circlesOnUnitSphere);
        }