public void DrawCurve(Graphics g) { if (p4 == null) { double x = p1.X; double y = p1.Y; Point2D oldPoint = p1; for (double i = 0; i < 1; i += t) { _line.DrawLine(g, oldPoint, new Point2D((int)x, (int)y)); oldPoint = new Point2D((int)x, (int)y); x = Math.Pow((1 - i), 2) * p1.X + 2 * i * (1 - i) * p2.X + Math.Pow(i, 2) * p3.X; y = Math.Pow((1 - i), 2) * p1.Y + 2 * i * (1 - i) * p2.Y + Math.Pow(i, 2) * p3.Y; } } else { double x = p1.X; double y = p1.Y; Point2D oldPoint = p1; for (double i = 0; i < 1; i += t) { _line.DrawLine(g, oldPoint, new Point2D((int)x, (int)y)); oldPoint = new Point2D((int)x, (int)y); double v = Math.Pow(-i, 3) + 3 * Math.Pow(i, 2); x = p1.X * (v - 3 * i + 1) + 3 * p2.X * i * (Math.Pow(i, 2) - 2 * i + 1) + 3 * p3.X * Math.Pow(i, 2) * (1 - i) + p4.X * Math.Pow(i, 3); y = p1.Y * (v - 3 * i + 1) + 3 * p2.Y * i * (Math.Pow(i, 2) - 2 * i + 1) + 3 * p3.Y * Math.Pow(i, 2) * (1 - i) + p4.Y * Math.Pow(i, 3); } } }
private void GoGraph(List <int> listOfPoints) { _myBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height); _g = Graphics.FromImage(_myBitmap); Graph gr = new Graph(10, pictureBox1.Width, pictureBox1.Height); gr.CreateA(_g); for (double x = -100; x < 100; x += 0.001) { Console.WriteLine("go x"); X = (int)(x * 10) + _width / 2; if (listOfPoints != null) { for (int i = 0; i < listOfPoints.Count; i += 3) { Y += (int)(listOfPoints[i] * Math.Pow(x, listOfPoints[i + 1])) + listOfPoints[i + 2]; } Y = _height / 2 - Y; _line.DrawLine(_g, _oldPoint, new Point2D(X, Y)); _oldPoint = new Point2D(X, Y); Y = 0; } } pictureBox1.Image = _myBitmap; }
private void button3_Click(object sender, EventArgs e) { _myBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height); _g = Graphics.FromImage(_myBitmap); WuLine wu = new WuLine(); Point2D p1 = new Point2D((double)numericUpDown1.Value, (double)numericUpDown2.Value); Point2D p2 = new Point2D((double)numericUpDown3.Value, (double)numericUpDown4.Value); wu.DrawLine(_g, p1, p2); pictureBox1.Image = _myBitmap; }
public void CreateA(Graphics g) { CreateAxis(g); int unitSegmentLine = UnitSegment / 2; for (int i = Height / 2 + unitSegmentLine; i < Height; i += UnitSegment) { _line.DrawLine(g, new Point2D(Width / 2 - unitSegmentLine / 2, i), new Point2D(Width / 2 + unitSegmentLine / 2, i)); } for (int i = Width / 2 + unitSegmentLine; i < Width; i += UnitSegment) { _line.DrawLine(g, new Point2D(i, Height / 2 - unitSegmentLine / 2), new Point2D(i, Height / 2 + unitSegmentLine / 2)); } for (int i = Height / 2 - unitSegmentLine; i >= 0; i -= UnitSegment) { _line.DrawLine(g, new Point2D(Width / 2 - unitSegmentLine / 2, i), new Point2D(Width / 2 + unitSegmentLine / 2, i)); } for (int i = Width / 2 - unitSegmentLine; i >= 0; i -= UnitSegment) { _line.DrawLine(g, new Point2D(i, Height / 2 - unitSegmentLine / 2), new Point2D(i, Height / 2 + unitSegmentLine / 2)); } }