private bool check_inside(point1 buf, Equation eq, int b = 0) { float kkk = kk; if (b == 0) { kkk = 1; } double res = buf.x1 * eq.x1 + buf.x2 * eq.x2; if (buf.x1 < 0 || buf.x2 < 0) { return(false); } if (Sign.less == eq.zn) { if (res <= eq.xb * kkk) { return(true); } } if (Sign.more == eq.zn) { if (res >= eq.xb * kkk) { return(true); } } return(false); }
private point1 Intersection(Equation obj1, Equation obj2) { point1 ret = new point1(); double A1, A2, B1, B2, C1, C2; A1 = obj1.x1; B1 = obj1.x2; C1 = -obj1.xb; A2 = obj2.x1; B2 = obj2.x2; C2 = -obj2.xb; ret.x1 = (-((C1 * B2 - C2 * B1) / (A1 * B2 - A2 * B1))); ret.x2 = (-((A1 * C2 - A2 * C1) / (A1 * B2 - A2 * B1))); return(ret); }
int k = 5; // for zooming private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Pen pen = new Pen(Color.FromArgb(200, 0, 0, 0)); Brush aBrush = (Brush)Brushes.LightGray; Graphics g = e.Graphics; int x0 = drawpic.Right / 2, y0 = drawpic.Bottom / 2; int xmax = drawpic.Right, ymax = drawpic.Bottom; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // e.Graphics.ScaleTransform(1+(zoom)/15, 1+(zoom)/15); // (1+(zoom)/15) // old zooming by scaling e.Graphics.TranslateTransform((hScrollBar1.Maximum / 2 - dx), (vScrollBar1.Maximum / 2 - dy) / 2); // new zooming by changing width of 1 e.Graphics.TranslateTransform(1 + (zoom) / 10, 1 + (zoom) / 10); g.DrawLine(System.Drawing.Pens.Red, drawpic.Right / 2, -500, // draw y drawpic.Right / 2, 900); g.DrawLine(System.Drawing.Pens.Red, -900, drawpic.Bottom / 2, // daw x 1800, drawpic.Bottom / 2); for (int i = 1; i < ymax; i++) { point1 buf = new point1(); for (int x = 0; x <= xmax; x++) { for (int w = 0; w < N; w++) // inside ? { buf.x1 = x; buf.x2 = i; if (check_inside(buf, lines[w], 1)) { buf.inside = true; } else { buf.inside = false; break; } } if (buf.inside) { g.FillRectangle(aBrush, (float)buf.x1 + x0, (-(float)buf.x2) + y0, 1, 1); } } } for (int i = 0; i < N; i++) { int x = -x0, y = getposy(x, lines[i]); int xe = xmax, ye = getposy(xe, lines[i]); g.DrawLine(pen, x0 + x * (1 + (zoom) / k), y0 + y * (1 + (zoom) / k), x0 + xe * (1 + (zoom) / k), y0 + ye * (1 + (zoom) / k)); } Font drawFont = new Font("Arial", 5); aBrush = (Brush)Brushes.Green; pen.Color = Color.Green; pen.Width = 1; g.DrawLine(pen, x0, y0, x0 + (float)XX1 * (1 + (zoom) / k), y0 - (float)XX2 * (1 + (zoom) / k)); }
this = InkBezierSegment(point1, point2, point3);
public void Calculate() { point1 buf = new point1(); double max = 0, min = 0; read_equation(); XX1 = Convert.ToDouble(X1.Text); XX2 = Convert.ToDouble(X2.Text); result_text.Visible = true; result_text.Text = ""; points.Clear(); result_text.Text += "Точки, которые не входят в" + " ОДЗ:\n"; for (int i = 0; i < N; i++) { for (int q = i + 1; q < N; q++) { if (is_empty(lines[i]) || is_empty(lines[q])) // empty { continue; } if (lines[i].x1 * lines[q].x2 - lines[q].x1 * lines[i].x2 == 0)// parallel ? { continue; } buf = Intersection(lines[i], lines[q]); for (int w = 0; w < N; w++) // inside ? { if (check_inside(buf, lines[w])) { buf.inside = true; } else { buf.inside = false; result_text.Text += "(" + Math.Round(buf.x1, 3) + "; " + Math.Round(buf.x2, 3) + ") - пересечения " + (i + 1) + " и " + (q + 1) + " ограничения\n"; break; } } if (buf.inside) { buf.i = i; buf.q = q; points.Add(new point1(buf.x1, buf.x2, true)); if (Func(buf) > max) { max = Func(buf); maxp.x1 = buf.x1; maxp.x2 = buf.x2; if (min == 0) { min = max; } } if (Func(buf) < min) { min = Func(buf); minp.x1 = buf.x1; minp.x2 = buf.x2; } } } } int ki = 0; result_text.Text += "\nТочки, входящие в ОДЗ:\n"; for (int a = 0; a < 2; a++) { for (int r = 0; r < N; r++) { if (a == 0) { buf.x1 = 0; buf.x2 = lines[r].xb / lines[r].x2; } else { buf.x2 = 0; buf.x1 = lines[r].xb / lines[r].x1; } for (int w = 0; w < N; w++) // inside ? { if (check_inside(buf, lines[w])) { buf.inside = true; } else { buf.inside = false; break; } } if (buf.inside) { ki++; points.Add(buf); buf.inside = false; char aa; if (a == 0) { aa = 'y'; } else { aa = 'x'; } if (Func(buf) >= max) { max = Func(buf); maxp.x1 = buf.x1; maxp.x2 = buf.x2; if (min == 0) { min = max; } } if (Func(buf) <= min) { min = Func(buf); minp.x1 = buf.x1; minp.x2 = buf.x2; } result_text.Text += "(" + Math.Round(buf.x1, 3) + "; " + Math.Round(buf.x2, 3) + ") - пересечение " + (r + 1) + " и " + aa + " ограничения, F";//+ "; \n"; result_text.Text += "(" + Math.Round(buf.x1, 3) + "; " + Math.Round(buf.x2, 3) + ") = " + Math.Round(Func(buf), 3) + ";\n"; } } } for (int t = 0; t < points.Count - ki; t++) { result_text.Text += "(" + Math.Round(points[t].x1, 3) + "; " + Math.Round(points[t].x2, 3) + ") - пересечение " + (points[t].i + 1) + " и " + (points[t].q + 1) + " ограничения, F"; result_text.Text += "(" + Math.Round(points[t].x1, 3) + "; " + Math.Round(points[t].x2, 3) + ") = " + Math.Round(Func(points[t]), 3) + ";\n"; } result_text.Text += "\nТочки экстримкма функции:"; result_text.Text += "\nMax (" + Math.Round(maxp.x1, 3).ToString() + ";" + Math.Round(maxp.x2, 3).ToString() + ") = " + Math.Round(max, 3).ToString() + ";\nMin (" + Math.Round(minp.x1, 3).ToString() + "; " + Math.Round(minp.x2, 3).ToString() + ") =" + Math.Round(min, 3).ToString() + ";\n"; drawpic.Invalidate(); if (i++ == 0) { drawpic.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint); } }
private double Func(point1 buf) { return(buf.x1 * XX1 + buf.x2 * XX2); }
=> sink.AddBezier(new BezierSegment(point1, point2, point3));
DrawLine(point1, point2, color, lineWidth, opacity, 1.0f, layerDepth);
if (!IsCounterClockwise(point1, point2, point3)) {
private void start_Click(object sender, EventArgs e) { point1 buf = new point1(); double max = 0, min = 0; read_equation(); XX1 = Convert.ToDouble(X1.Text); XX2 = Convert.ToDouble(X2.Text); result_text.Visible = true; result_text.Text = ""; points.Clear(); result_text.Text += "Tочки які не входять в ОДЗ:\n"; for (int i = 0; i < N; i++) { for (int q = i + 1; q < N; q++) { if (is_empty(lines[i]) || is_empty(lines[q])) // empty { continue; } if (lines[i].x1 * lines[q].x2 - lines[q].x1 * lines[i].x2 == 0)// parallel ? { continue; } buf = Intersection(lines[i], lines[q]); for (int w = 0; w < N; w++) // inside ? { if (check_inside(buf, lines[w])) { buf.inside = true; } else { buf.inside = false; result_text.Text += "(" + Math.Round(buf.x1, 3) + "; " + Math.Round(buf.x2, 3) + ") - перетин " + (i + 1) + " і " + (q + 1) + " обемеження\n"; break; } } if (buf.inside) { buf.i = i; buf.q = q; points.Add(new point1(buf.x1, buf.x2, true)); if (Func(buf) > max) { max = Func(buf); maxp.x1 = buf.x1; maxp.x2 = buf.x2; if (min == 0) { min = max; } } if (Func(buf) < min) { min = Func(buf); minp.x1 = buf.x1; minp.x2 = buf.x2; } } } } int ki = 0; result_text.Text += "\nTочки які входять в ОДЗ:\n"; for (int a = 0; a < 2; a++) { for (int r = 0; r < N; r++) { if (a == 0) { buf.x1 = 0; buf.x2 = lines[r].xb / lines[r].x2; } else { buf.x2 = 0; buf.x1 = lines[r].xb / lines[r].x1; } for (int w = 0; w < N; w++) // inside ? { if (check_inside(buf, lines[w])) { buf.inside = true; } else { buf.inside = false; break; } } if (buf.inside) { ki++; points.Add(buf); buf.inside = false; char aa; if (a == 0) { aa = 'y'; } else { aa = 'x'; } if (Func(buf) >= max) { max = Func(buf); maxp.x1 = buf.x1; maxp.x2 = buf.x2; if (min == 0) { min = max; } } if (Func(buf) <= min) { min = Func(buf); minp.x1 = buf.x1; minp.x2 = buf.x2; } result_text.Text += "(" + Math.Round(buf.x1, 3) + "; " + Math.Round(buf.x2, 3) + ") - перетин " + (r + 1) + " і " + aa + " обемеження, F";//+ "; \n"; result_text.Text += "(" + Math.Round(buf.x1, 3) + "; " + Math.Round(buf.x2, 3) + ") = " + Math.Round(Func(buf), 3) + ";\n"; } } } for (int t = 0; t < points.Count - ki; t++) { result_text.Text += "(" + Math.Round(points[t].x1, 3) + "; " + Math.Round(points[t].x2, 3) + ") - перетин " + (points[t].i + 1) + " і " + (points[t].q + 1) + " обемеження, F"; result_text.Text += "(" + Math.Round(points[t].x1, 3) + "; " + Math.Round(points[t].x2, 3) + ") = " + Math.Round(Func(points[t]), 3) + ";\n"; } result_text.Text += "\nТочки екстремуму функції:"; result_text.Text += "\nMax (" + Math.Round(maxp.x1, 3).ToString() + ";" + Math.Round(maxp.x2, 3).ToString() + ") = " + Math.Round(max, 3).ToString() + ";\nMin (" + Math.Round(minp.x1, 3).ToString() + "; " + Math.Round(minp.x2, 3).ToString() + ") =" + Math.Round(min, 3).ToString() + ";\n"; if (min == Double.MaxValue && max == Double.MinValue) { MessageBox.Show("No solution. All posible points are ouside definition area!"); } else { MessageBox.Show("max (" + maxp.x1.ToString() + ";" + maxp.x2.ToString() + ") = " + max.ToString() + ";\nmin (" + minp.x1.ToString() + "; " + minp.x2.ToString() + ") =" + min.ToString() + ";\n"); } drawpic.Invalidate(); if (i++ == 0) { drawpic.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint); } }
// Set's the two diagonal Points of the Rectangle public Rectangle(Point point1, Point point2) => SetPoints(point1, point2);
this = QuadraticBezierSegment(point1, point2);