Esempio n. 1
0
 public string test(float[] x, float[] y)
 {
     Library lib = new Library();
     return lib.result(x, y);
 }
Esempio n. 2
0
        /// Draws graph using input data.
        private void draw()
        {
            float x0 = pictureBox.Size.Height / 2;
            float y0 = pictureBox.Size.Width / 2;
            float scale = trackBar.Value * 10;

            float[] x = new float[4]
            {
                x0 + tryToConvert(pointAx.Text) * scale,
                x0 + tryToConvert(pointBx.Text) * scale,
                x0 + tryToConvert(pointCx.Text) * scale,
                x0 + tryToConvert(pointDx.Text) * scale
            };

            float[] y = new float[4]
            {
                y0 - tryToConvert(pointAy.Text) * scale,
                y0 - tryToConvert(pointBy.Text) * scale,
                y0 - tryToConvert(pointCy.Text) * scale,
                y0 - tryToConvert(pointDy.Text) * scale
            };

            if (error)
            {
                error = false;
                pictureBox.Image = initImage;
            }
            else
            {
                Bitmap image = new Bitmap(pictureBox.Size.Height, pictureBox.Size.Width);
                clear(image);
                Graphics graph = Graphics.FromImage(image);

                // draws axes
                float t = 0;
                graph.DrawLine(Pens.Black, x0, 0.0f, x0, pictureBox.Size.Height);
                graph.DrawLine(Pens.Black, 0.0f, y0, pictureBox.Size.Width, y0);

                while (t < pictureBox.Size.Height)
                {
                    graph.DrawEllipse(Pens.Green, t + x0 - 1.5f, y0 - 1.5f, 3.0f, 3.0f);
                    graph.DrawEllipse(Pens.Green, -t + x0 - 1.5f, y0 - 1.5f, 3.0f, 3.0f);
                    graph.DrawEllipse(Pens.Green, x0 - 1.5f, y0 - t - 1.5f, 3.0f, 3.0f);
                    graph.DrawEllipse(Pens.Green, x0 - 1.5f, y0 + t - 1.5f, 3.0f, 3.0f);
                    t += scale;
                }

                // draws graph
                graph.DrawLine(Pens.Red, x[0], y[0], x[1], y[1]);
                graph.DrawLine(Pens.Red, x[1], y[1], x[2], y[2]);
                graph.DrawLine(Pens.Red, x[2], y[2], x[3], y[3]);
                graph.DrawLine(Pens.Red, x[3], y[3], x[0], y[0]);
                graph.DrawEllipse(Pens.Red, x[0] - 2.0f, y[0] - 2.0f, 4.0f, 4.0f);
                graph.DrawEllipse(Pens.Red, x[1] - 2.0f, y[1] - 2.0f, 4.0f, 4.0f);
                graph.DrawEllipse(Pens.Red, x[2] - 2.0f, y[2] - 2.0f, 4.0f, 4.0f);
                graph.DrawEllipse(Pens.Red, x[3] - 2.0f, y[3] - 2.0f, 4.0f, 4.0f);

                pictureBox.CreateGraphics();
                pictureBox.Image = image;
                pictureBox.Refresh();

                // refreshes result
                Library lib = new Library();
                resultTextBox.Text = lib.result(x, y);
            }
        }