public void AreaBasedRemeshing() { if (!this.available) { return; } for (int i = this.Polygon.VertexCount; i < this.Polygon.PointCount; i++) { if (this.Polygon.isOnEdge(this.Polygon.GetPoint(i)) || this.Polygon.isVertex(this.Polygon.GetPoint(i))) { continue; } double[] d = this.GetValue(i); Line2D line1 = null; Line2D line2 = null; Point2D point = null; try { line1 = new Line2D(0.5 * d[3], 0.5 * d[4], 0.5 * d[5] - d[7] * d[1]); line2 = new Line2D(0.5 * d[4], 0.5 * d[2], 0.5 * d[6] - d[7] * d[0]); } catch (ArgumentException) { return; } point = line1.Intersects(line2); if (point.isRegular && this.isRegular(i, point) && this.Polygon.Contains(point)) { Polygon2DEditor polygonEditor = new Polygon2DEditor(this.Polygon); polygonEditor.SetPoint(point.X, point.Y, i); } } }
/// <summary> /// Get the intersect point of the two lines. /// </summary> /// <param name="line">the other line.</param> /// <returns>the point.</returns> public Point2D Intersects(Line2D line) { if (this.GetPosition(line) != Position.Intersect) { //throw (new ArgumentException("The two lines cannot Intersects!")); return new Point2D(double.PositiveInfinity, double.PositiveInfinity); } Vector v1 = null; Vector v2 = null; if (Math.Abs(this.A) > Math.Abs(line.A)) { v1 = new Vector(this.vector); v2 = new Vector(line.vector); } else { v1 = new Vector(line.vector); v2 = new Vector(this.vector); } Vector v3 = new Vector(v1); v1 = Vector.Multiply(v2[0] / v1[0], v1); v1 = Vector.Subtract(v1, v2); v1 = Vector.Multiply(1/v1[1], v1); Point2D point = new Point2D(new Line2D(v3).GetX(-v1[2]), -v1[2]); if (!this.Contains(point) || !line.Contains(point)) { throw (new ArgumentException()); } return point; }
public Line2D(Line2D line) : this(line.A, line.B, line.C) { }
/// <summary> /// Discribe the position of the two lines. /// </summary> /// <param name="line">the other line.</param> /// <returns>the position.</returns> public Position GetPosition(Line2D line) { if (this.A == 0 && line.A == 0) { if (this.B * line.C != this.C * line.B) { return Position.Parallel; } else { return Position.Superposition; } } if (this.B == 0 && line.B == 0) { if (this.A * line.C != this.C * line.A) { return Position.Parallel; } else { return Position.Superposition; } } Vector v1 = null; Vector v2 = null; if (Math.Abs(this.A) > Math.Abs(line.A)) { v1 = new Vector(this.vector); v2 = new Vector(line.vector); } else { v1 = new Vector(line.vector); v2 = new Vector(this.vector); } v1 = Vector.Multiply(v2[0] / v1[0], v1); v1 = Vector.Subtract(v1,v2); if (Math.Abs(v1[1]) < Line2D.ZeroTolerance && Math.Abs(v1[2]) < Line2D.ZeroTolerance) { return Position.Superposition; } else if (Math.Abs(v1[1]) < Line2D.ZeroTolerance) { return Position.Parallel; } else { return Position.Intersect; } }