/// <summary> /// Tests whether a triangular ring would be eroded completely by the given /// buffer distance. /// This is a precise test. It uses the fact that the inner buffer of a /// triangle converges on the inCentre of the triangle (the point /// equidistant from all sides). If the buffer distance is greater than the /// distance of the inCentre from a side, the triangle will be eroded completely. /// This test is important, since it removes a problematic case where /// the buffer distance is slightly larger than the inCentre distance. /// In this case the triangle buffer curve "inverts" with incorrect topology, /// producing an incorrect hole in the buffer. /// </summary> /// <param name="triangleCoord"></param> /// <param name="bufferDistance"></param> /// <returns></returns> private static bool IsTriangleErodedCompletely(Coordinate[] triangleCoord, double bufferDistance) { var tri = new Triangle(triangleCoord[0], triangleCoord[1], triangleCoord[2]); var inCentre = tri.InCentre(); var distToCentre = CGAlgorithms.DistancePointLine(inCentre, tri.P0, tri.P1); return distToCentre < Math.Abs(bufferDistance); }
public static IGeometry Incentre(IGeometry g) { Coordinate[] pts = TrianglePts(g); Triangle t = new Triangle(pts[0], pts[1], pts[2]); Coordinate cc = t.InCentre(); IGeometryFactory geomFact = FunctionsUtil.GetFactoryOrDefault(g); return geomFact.CreatePoint(cc); }
private static void CheckArea3D(String wkt, double expectedValue) { var g = Reader.Read(wkt); var pt = g.Coordinates; var t = new Triangle(pt[0], pt[1], pt[2]); var area3D = t.Area3D(); // Console.WriteLine("area3D = " + area3D); Assert.AreEqual(expectedValue, area3D, Tolerance); }
private static void CheckInterpolateZ(String wkt, Coordinate p, double expectedValue) { var g = Reader.Read(wkt); var pt = g.Coordinates; var t = new Triangle(pt[0], pt[1], pt[2]); var z = t.InterpolateZ(p); //Console.WriteLine("Z = " + z); Assert.AreEqual(expectedValue, z, Tolerance); }
public static IGeometry AngleBisectors(IGeometry g) { Coordinate[] pts = TrianglePts(g); Triangle t = new Triangle(pts[0], pts[1], pts[2]); Coordinate cc = t.InCentre(); IGeometryFactory geomFact = FunctionsUtil.GetFactoryOrDefault(g); ILineString[] line = new ILineString[3]; line[0] = geomFact.CreateLineString(new[] { pts[0], cc }); line[1] = geomFact.CreateLineString(new[] { pts[1], cc }); line[2] = geomFact.CreateLineString(new[] { pts[2], cc }); return geomFact.CreateMultiLineString(line); }
private static void CheckArea(String wkt, double expectedValue) { var g = Reader.Read(wkt); var pt = g.Coordinates; var t = new Triangle(pt[0], pt[1], pt[2]); var signedArea = t.SignedArea(); //Console.WriteLine("signed area = " + signedArea); Assert.AreEqual(expectedValue, signedArea, Tolerance); var area = t.Area(); Assert.AreEqual(Math.Abs(expectedValue), area, Tolerance); }
private static void CheckAcute(String wkt, bool expectedValue) { var g = Reader.Read(wkt); var pt = g.Coordinates; var t = new Triangle(pt[0], pt[1], pt[2]); var isAcute = t.IsAcute(); //Console.WriteLine("isAcute = " + isAcute); Assert.AreEqual(expectedValue, isAcute); }