public Triangle(Point A, Point B, Point C) { this.A = A; this.B = B; this.C = C; a = new Section(new Vector(B, C)); b = new Section(new Vector(C, A)); c = new Section(new Vector(A, B)); }
private bool UpdateTriangles(Triangle tRight, Triangle tLeft, Section commonSection, List<Triangle> tmpResult, Graphics g = null, Pen linePen = null, Pen pointPen = null, Pen newLinePen = null, int formHeight = 0, int delay = 0) { //меняем общее ребро у двух треугольников Point leftExcessPoint = TriangulationBuilder.GetExcessPoint(tLeft, commonSection); Point rightExcessPoint = TriangulationBuilder.GetExcessPoint(tRight, commonSection); if (commonSection.CountAnglesSum(leftExcessPoint) + commonSection.CountAnglesSum(rightExcessPoint) < 180) { Point up = commonSection.A; Point down = commonSection.B; if (new Vector(down, rightExcessPoint).GetVectorMultiplication(new Vector(down, leftExcessPoint)) < 0) { up = commonSection.B; down = commonSection.A; } tmpResult.Remove(tLeft); tmpResult.Remove(tRight); Triangle toAddFirst = new Triangle(leftExcessPoint, down, rightExcessPoint); Triangle toAddSecond = new Triangle(rightExcessPoint, up, leftExcessPoint); tmpResult.Add(toAddFirst); tmpResult.Add(toAddSecond); if (g != null && linePen != null && newLinePen != null && formHeight != -1 && delay != -1) { g.DrawLine(new Pen(Color.White, 2), (int)commonSection.A.X, formHeight - (int)commonSection.A.Y, (int)commonSection.B.X, formHeight - (int)commonSection.B.Y); g.DrawLine(newLinePen, (int)leftExcessPoint.X, formHeight - (int)leftExcessPoint.Y, (int)rightExcessPoint.X, formHeight - (int)rightExcessPoint.Y); Thread.Sleep(delay); g.DrawLine(new Pen(Color.White, 2), (int)leftExcessPoint.X, formHeight - (int)leftExcessPoint.Y, (int)rightExcessPoint.X, formHeight - (int)rightExcessPoint.Y); g.DrawLine(linePen, (int)leftExcessPoint.X, formHeight - (int)leftExcessPoint.Y, (int)rightExcessPoint.X, formHeight - (int)rightExcessPoint.Y); toAddFirst.Paint(g, linePen, pointPen, formHeight); toAddSecond.Paint(g, linePen, pointPen, formHeight); } return true; } return false; }
private static Point GetExcessPoint(Triangle t, Section s) { //ищем точку из треугольника, не лежащую на ребре Point excessPoint; if (!t.A.Equals(s.A) && !t.A.Equals(s.B)) excessPoint = t.A; else if (!t.B.Equals(s.A) && !t.B.Equals(s.B)) excessPoint = t.B; else excessPoint = t.C; return excessPoint; }