ToPixelx() public static method

public static ToPixelx ( double value ) : double
value double
return double
Example #1
0
        private void button_dibujar_Click(object sender, RoutedEventArgs e)
        {
            Rectangle rec_punt_mig = new Rectangle();
            Rectangle linia_mx     = new Rectangle();
            Rectangle linia_Mx     = new Rectangle();
            Rectangle linia_my     = new Rectangle();
            Rectangle linia_My     = new Rectangle();

            i     = 0;
            v     = 1;
            min_x = 0;
            min_y = 0;
            max_x = 0;
            max_y = 0;
            while (v >= 1 && i < array_1.Count)
            {
                calibrating = true;
                i           = 2;
                while (i < array_1.Count)
                {
                    x = array_1[i];
                    y = array_2[i];
                    if (i == 2)
                    {
                        min_x = x;
                        max_y = y;
                    }

                    if (x > max_x)
                    {
                        max_x = x;
                    }
                    if (x < min_x)
                    {
                        min_x = x;
                    }
                    if (y > max_y)
                    {
                        max_y = y;
                    }
                    if (y < min_y)
                    {
                        min_y = y;
                    }

                    i++;
                }

                escalarx = 1;
                escalary = 1;
                dx       = max_x - min_x;
                dy       = max_y - min_y;
                if (dy < dx) //multiplicaremos los valores de y por un numero mayor de 1
                {
                    escalary = (dx / dy);
                }

                if (dx < dy)//multiplicaremos los valores de x por un numero mayor de 1
                {
                    escalarx = (dy / dx);
                }
                i = 2;
                while (i < array_1.Count)
                {
                    x = array_1[i] * escalarx * zoom;
                    y = array_2[i] * escalary * zoom;

                    Rectangle rec_coordenades = new Rectangle();
                    rec_coordenades.Width  = 4;
                    rec_coordenades.Height = 4;
                    rec_coordenades.Fill   = new SolidColorBrush(Colors.Red);
                    cal.Children.Add(rec_coordenades);

                    //cambiar los 5000 por 30000
                    Canvas.SetTop(rec_coordenades, 315 - ((315 * y) / 6000));
                    Canvas.SetLeft(rec_coordenades, 295.264 + ((295.264 * x) / 6000));

                    i++;
                }
            }
            v++;

            if (i >= array_1.Count)
            {
                rec_punt_mig.Width  = 4;
                rec_punt_mig.Height = 4;
                rec_punt_mig.Fill   = new SolidColorBrush(Colors.Blue);
                cal.Children.Add(rec_punt_mig);
                rec_punt_mig.Opacity = 0;

                linia_My.Width  = 631;//550;
                linia_My.Height = 1;
                linia_My.Fill   = new SolidColorBrush(Colors.Pink);
                cal.Children.Add(linia_My);
                linia_My.Opacity = 0;

                linia_my.Width  = 631;//550;
                linia_my.Height = 1;
                linia_my.Fill   = new SolidColorBrush(Colors.Pink);
                cal.Children.Add(linia_my);
                linia_my.Opacity = 0;

                linia_mx.Width  = 1;
                linia_mx.Height = 592.527393939;//750;
                linia_mx.Fill   = new SolidColorBrush(Colors.Pink);
                cal.Children.Add(linia_mx);
                linia_mx.Opacity = 0;

                linia_Mx.Width  = 1;
                linia_Mx.Height = 592.527393939;//750;
                linia_Mx.Fill   = new SolidColorBrush(Colors.Pink);
                cal.Children.Add(linia_Mx);
                linia_Mx.Opacity = 0;

                textBlock1.Text = Convert.ToString(0);
                textBlock3.Text = Convert.ToString(0);
                textBlock2.Text = Convert.ToString(0);
                textBlock4.Text = Convert.ToString(0);

                count = (array_1.Count - 2);
                int distancia_vector = 2;
                total1   = 0;
                puntmigx = 0;
                total2   = 0;
                puntmigy = 0;
                while (distancia_vector < array_1.Count)
                {
                    total1 += array_1[distancia_vector];
                    total2 += array_2[distancia_vector];
                    distancia_vector++;
                }
                puntmigx = total1 / count;
                puntmigy = total2 / count;

                textBlock1.Text = Convert.ToString(puntmigx);
                textBlock3.Text = Convert.ToString(dx);
                textBlock2.Text = Convert.ToString(puntmigy);
                textBlock4.Text = Convert.ToString(dy);

                rec_punt_mig.Opacity = 1;
                linia_My.Opacity     = 1;
                linia_my.Opacity     = 1;
                linia_mx.Opacity     = 1;
                linia_Mx.Opacity     = 1;
                Canvas.SetTop(rec_punt_mig, Conversion.ToPixely(puntmigy * escalary * zoom));
                Canvas.SetLeft(rec_punt_mig, Conversion.ToPixelx(puntmigx * escalarx * zoom));
                Canvas.SetTop(linia_My, Conversion.ToPixely(max_y * escalary * zoom));
                Canvas.SetTop(linia_my, 317 - ((315 * min_y * escalary * zoom) / 6000));
                Canvas.SetLeft(linia_mx, Conversion.ToPixelx(min_x * escalarx * zoom));
                Canvas.SetLeft(linia_Mx, 297.264 + ((295.264 * max_x * escalarx * zoom) / 6000));
            }
        }