Class to help converting from Image/Canvas coords <-> absolute coords.
Exemplo n.º 1
0
 public static void DrawFilledCircle( Circle c, Graphics g, ImageSpace i, Brush b )
 {
     Rectangle? rect = Rect( c, i );
     if( rect == null )
         return;
     g.FillEllipse( b, rect.Value );
 }
Exemplo n.º 2
0
        public static void GenImage()
        {
            int size = 1000;
            Bitmap image = new Bitmap( size, size );
            ImageSpace i = new ImageSpace( size, size );
            double b = 1.1;
            i.XMin = -b; i.XMax = b;
            i.YMin = -b; i.YMax = b;

            Vector3D cen = HoneycombPaper.CellCenBall;
            cen = H3Models.BallToUHS( cen );
            Sphere[] simplex = Simplex( ref cen );

            Sphere inSphere = InSphere( simplex );

            using( Graphics g = Graphics.FromImage( image ) )
            foreach( int[] reflections in AllCells() )
            {
                Sphere clone = inSphere.Clone();
                foreach( int r in reflections )
                    clone.Reflect( simplex[r] );

                Sphere ball = new Sphere();
                Circle3D inSphereIdealBall = ball.Intersection( clone );
                Circle3D inSphereIdealUHS = H3Models.BallToUHS( inSphereIdealBall );
                Circle inSphereIdeal = new Circle { Center = inSphereIdealUHS.Center, Radius = inSphereIdealUHS.Radius };

                using( Brush brush = new SolidBrush( Color.Blue ) )
                    DrawUtils.DrawFilledCircle( inSphereIdeal, g, i, brush );
            }

            image.Save( "threefifty.png", ImageFormat.Png );
        }
Exemplo n.º 3
0
 public static void DrawCircle( Circle c, Graphics g, ImageSpace i, Pen p )
 {
     Rectangle? rect = Rect( c, i );
     if( rect == null )
         return;
     g.DrawEllipse( p, rect.Value );
 }
Exemplo n.º 4
0
 static public void DrawTriangle(Mesh.Triangle triangle, Graphics g, ImageSpace i)
 {
     using (Pen pen = new Pen(Color.Black, 1.0f))
     {
         g.DrawLine(pen, VecToPoint(triangle.a, i), VecToPoint(triangle.b, i));
         g.DrawLine(pen, VecToPoint(triangle.b, i), VecToPoint(triangle.c, i));
         g.DrawLine(pen, VecToPoint(triangle.c, i), VecToPoint(triangle.a, i));
     }
 }
Exemplo n.º 5
0
 public static void DrawTriangle( Mesh.Triangle triangle, Graphics g, ImageSpace i )
 {
     using( Pen pen = new Pen( Color.Black, 1.0f ) )
     {
         g.DrawLine( pen, VecToPoint( triangle.a, i ), VecToPoint( triangle.b, i ) );
         g.DrawLine( pen, VecToPoint( triangle.b, i ), VecToPoint( triangle.c, i ) );
         g.DrawLine( pen, VecToPoint( triangle.c, i ), VecToPoint( triangle.a, i ) );
     }
 }
Exemplo n.º 6
0
        static public void DrawFilledCircle(Circle c, Graphics g, ImageSpace i, Brush b)
        {
            Rectangle?rect = Rect(c, i);

            if (rect == null)
            {
                return;
            }
            g.FillEllipse(b, rect.Value);
        }
Exemplo n.º 7
0
        static public void DrawCircle(Circle c, Graphics g, ImageSpace i, Pen p)
        {
            Rectangle?rect = Rect(c, i);

            if (rect == null)
            {
                return;
            }
            g.DrawEllipse(p, rect.Value);
        }
Exemplo n.º 8
0
        private static Rectangle? Rect( Circle c, ImageSpace i )
        {
            if( double.IsInfinity( c.Radius ) )
                return null;

            Vector3D upperLeft = i.Pixel( new Vector3D( c.Center.X - c.Radius, c.Center.Y + c.Radius, 0 ) );
            double width = i.Width( c.Radius * 2 );
            double height = i.Height( c.Radius * 2 );
            Rectangle rect = new Rectangle( (int)upperLeft.X, (int)upperLeft.Y, (int)width, (int)height );
            return rect;
        }
Exemplo n.º 9
0
        static private Rectangle?Rect(Circle c, ImageSpace i)
        {
            if (double.IsInfinity(c.Radius))
            {
                return(null);
            }

            Vector3D  upperLeft = i.Pixel(new Vector3D(c.Center.X - c.Radius, c.Center.Y + c.Radius, 0));
            double    width     = i.Width(c.Radius * 2);
            double    height    = i.Height(c.Radius * 2);
            Rectangle rect      = new Rectangle((int)upperLeft.X, (int)upperLeft.Y, (int)width, (int)height);

            return(rect);
        }
Exemplo n.º 10
0
        static public void DrawCircle(Circle c, Graphics g, ImageSpace i)
        {
            if (double.IsInfinity(c.Radius))
            {
                return;
            }

            Vector3D  upperLeft = i.Pixel(new Vector3D(c.Center.X - c.Radius, c.Center.Y + c.Radius, 0));
            double    width     = i.Width(c.Radius * 2);
            double    height    = i.Height(c.Radius * 2);
            Rectangle rect      = new Rectangle((int)upperLeft.X, (int)upperLeft.Y, (int)width, (int)height);

            using (Pen pen = new Pen(Color.Black, 1.0f))
                g.DrawEllipse(pen, rect);
        }
Exemplo n.º 11
0
        private void DrawMirrors( Bitmap image, Settings settings )
        {
            double b = settings.Bounds;
            ImageSpace i = new ImageSpace( settings.Width, settings.Height );
            i.XMin = -b; i.XMax = b;
            i.YMin = -b; i.YMax = b;

            float scale = 2;

            List<Sphere> toDraw = new List<Sphere>();
            toDraw.AddRange( settings.Mirrors );
            toDraw.Add( AlteredFacetForTrueApparent2DTilings( settings.Mirrors ) );

            using( Graphics g = Graphics.FromImage( image ) )
            using( Pen p = new Pen( Color.Red, scale * 3.0f ) )
            //using( Pen p2 = new Pen( Color.FromArgb( 255, 255, 214, 0 ), 3.0f ) )
            using( Pen p2 = new Pen( Color.Orange, scale * 3.0f ) )
            using( Pen p3 = new Pen( Color.Orange, scale * 3.0f ) )
            for( int m=0; m<toDraw.Count; m++ )
            {
                Sphere s = toDraw[m];
                Circle c = H3Models.UHS.IdealCircle( s );	// XXX - not correct
                if( c.IsLine )
                {
                    DrawUtils.DrawLine( -c.P2*25, c.P2*25, g, i, p );	// XXX - not general.
                }
                else
                {
                    Sphere temp = H3Models.BallToUHS( s );
                    DrawUtils.DrawCircle( new Circle { Center = temp.Center, Radius = temp.Radius }, g, i, m == 0 ? p2 : m == 4 ? p3 : p );
                }

                /* // iii
                Circle c = new Circle();
                c.Radius = Math.Sqrt( 2 );
                c.Center = new Vector3D( 1, Math.Sqrt( 2 ) );
                DrawUtils.DrawCircle( c, g, i, p );
                c.Center = new Vector3D( -1, Math.Sqrt( 2 ) );
                DrawUtils.DrawCircle( c, g, i, p );
                c.Center = new Vector3D( Math.Sqrt( 2 ) - 1, 0 );
                c.Radius = 2 - Math.Sqrt( 2 );
                DrawUtils.DrawCircle( c, g, i, p );

                DrawUtils.DrawLine( new Vector3D( -2, 0 ), new Vector3D( 2, 0 ), g, i, p );
                 */
            }
        }
Exemplo n.º 12
0
        static private Point VecToPoint(Vector3D vec, ImageSpace i)
        {
            Vector3D temp = i.Pixel(vec);

            return(new Point((int)temp.X, (int)temp.Y));
        }
Exemplo n.º 13
0
 private static Point VecToPoint( Vector3D vec, ImageSpace i )
 {
     Vector3D temp = i.Pixel( vec );
     return new Point( (int)temp.X, (int)temp.Y );
 }
Exemplo n.º 14
0
 public static void DrawLine( Vector3D p1, Vector3D p2, Graphics g, ImageSpace i, Pen p )
 {
     g.DrawLine( p, VecToPoint( p1, i ), VecToPoint( p2, i ) );
 }
Exemplo n.º 15
0
 public static void DrawCircle( Circle c, Graphics g, ImageSpace i )
 {
     using( Pen pen = new Pen( Color.Black, 1.0f ) )
         DrawCircle( c, g, i, pen );
 }
Exemplo n.º 16
0
 static public void DrawCircle(Circle c, Graphics g, ImageSpace i)
 {
     using (Pen pen = new Pen(Color.Black, 1.0f))
         DrawCircle(c, g, i, pen);
 }
Exemplo n.º 17
0
 static public void DrawLine(Vector3D p1, Vector3D p2, Graphics g, ImageSpace i, Pen p)
 {
     g.DrawLine(p, VecToPoint(p1, i), VecToPoint(p2, i));
 }