private void UpdateCircumcircle() { var p0 = this.Vertices[0]; var p1 = this.Vertices[1]; var p2 = this.Vertices[2]; var dA = p0.X * p0.X + p0.Y * p0.Y; var dB = p1.X * p1.X + p1.Y * p1.Y; var dC = p2.X * p2.X + p2.Y * p2.Y; var aux1 = dA * (p2.Y - p1.Y) + dB * (p0.Y - p2.Y) + dC * (p1.Y - p0.Y); var aux2 = -(dA * (p2.X - p1.X) + dB * (p0.X - p2.X) + dC * (p1.X - p0.X)); var div = 2 * (p0.X * (p2.Y - p1.Y) + p1.X * (p0.Y - p2.Y) + p2.X * (p1.Y - p0.Y)); if (Math.Abs(div) < Settings.Tolerance) { throw new Exception("Divisor too small"); } var center = new DelaunayPoint(aux1 / div, aux2 / div); this.Circumcenter = center; this.RadiusSquared = (center.X - p0.X) * (center.X - p0.X) + (center.Y - p0.Y) * (center.Y - p0.Y); }
/// <summary> /// Initializes a new instance of the <see cref="DelaunayTriangle" /> class. /// </summary> /// <param name="point1">Point A.</param> /// <param name="point2">Point B.</param> /// <param name="point3">Point C.</param> public DelaunayTriangle(DelaunayPoint point1, DelaunayPoint point2, DelaunayPoint point3) { this.Vertices = new List <DelaunayPoint>(); if (!IsCounterClockwise(point1, point2, point3)) { this.Vertices.Add(point1); this.Vertices.Add(point3); this.Vertices.Add(point2); } else { this.Vertices.Add(point1); this.Vertices.Add(point2); this.Vertices.Add(point3); } this.Vertices[0].AdjacentTriangles.Add(this); this.Vertices[1].AdjacentTriangles.Add(this); this.Vertices[2].AdjacentTriangles.Add(this); this.UpdateCircumcircle(); }
/// <summary> /// Initializes a new instance of the <see cref="DelaunayEdge" /> class. /// </summary> /// <param name="startPoint">Start point.</param> /// <param name="endPoint">End point.</param> public DelaunayEdge(DelaunayPoint startPoint, DelaunayPoint endPoint) : base(startPoint, endPoint) { }