/// <summary> /// Setup a circle we'll use to color neighbors. /// </summary> private void SetupNeighborCircle(Tile templateTriangle) { Polygon poly = m_tiles.First().Boundary; // Tetrahedral tiling. CircleNE circ = new CircleNE(); circ.Radius = m_shrink; circ.Reflect(poly.Segments[2]); circ.Reflect(templateTriangle.Boundary.Segments[1]); Mobius m = new Mobius(); m.Isometry(Geometry.Spherical, 0, -circ.CenterNE); circ.Transform(m); m_neighborCircle = new CircleNE(); m_neighborCircle.Radius = 1.0 / circ.Radius; m_originalNeighborCircle = m_neighborCircle.Clone(); System.Func <Vector3D, Vector3D> pointTransform = v => { v *= m_neighborCircle.Radius; v = new Vector3D(v.Y, v.X); v.RotateXY(-Math.PI / 2); return(v); }; m_neighborToStandardDisk = CalcMobius(pointTransform); }
/// <summary> /// Slices a polygon by a circle with some thickness. /// Input circle may be a line. /// </summary> /// <remarks>The input polygon might get reversed</remarks> public static void SlicePolygon(Polygon p, CircleNE c, Geometry g, double thickness, out List <Polygon> output) { // Setup the two slicing circles. CircleNE c1 = c.Clone(), c2 = c.Clone(); Mobius m = new Mobius(); Vector3D pointOnCircle = c.IsLine ? c.P1 : c.Center + new Vector3D(c.Radius, 0); m.Hyperbolic2(g, c1.CenterNE, pointOnCircle, thickness / 2); c1.Transform(m); m.Hyperbolic2(g, c2.CenterNE, pointOnCircle, -thickness / 2); c2.Transform(m); SlicePolygonHelper(p, c1, c2, out output); }
/// <summary> /// Slices a polygon by a circle with some thickness. /// Input circle may be a line. /// </summary> /// <remarks>The input polygon might get reversed</remarks> public static void SlicePolygon(Polygon p, CircleNE c, Geometry g, double thickness, out List <Polygon> output) { output = new List <Polygon>(); // Setup the two slicing circles. CircleNE c1 = c.Clone(), c2 = c.Clone(); Mobius m = new Mobius(); Vector3D pointOnCircle = c.IsLine ? c.P1 : c.Center + new Vector3D(c.Radius, 0); m.Hyperbolic2(g, c1.CenterNE, pointOnCircle, thickness / 2); c1.Transform(m); m.Hyperbolic2(g, c2.CenterNE, pointOnCircle, -thickness / 2); c2.Transform(m); // ZZZ - alter Clip method to work on Polygons and use that. // Slice it up. List <Polygon> sliced1, sliced2; Slicer.SlicePolygon(p, c1, out sliced1); Slicer.SlicePolygon(p, c2, out sliced2); // Keep the ones we want. foreach (Polygon newPoly in sliced1) { bool outside = !c1.IsPointInsideNE(newPoly.CentroidApprox); if (outside) { output.Add(newPoly); } } foreach (Polygon newPoly in sliced2) { bool inside = c2.IsPointInsideNE(newPoly.CentroidApprox); if (inside) { output.Add(newPoly); } } }