public static void GenEuclidean() { Shapeways mesh = new Shapeways(); HashSet <H3.Cell.Edge> completed = new HashSet <H3.Cell.Edge>(new H3.Cell.EdgeEqualityComparer()); int count = 2; for (int i = -count; i < count; i++) { for (int j = -count; j < count; j++) { for (int k = -count; k < count; k++) { // Offset double io = i + 0.5; double jo = j + 0.5; double ko = k + 0.5; Vector3D p = new Vector3D(io, jo, ko); // Add a sphere for this point. Sphere s = new Sphere() { Center = p, Radius = 0.05 }; mesh.AddSphere(s.Center, s.Radius); // Do every edge emanating from this point. AddEuclideanEdge(mesh, completed, p, new Vector3D(io + 1, jo, ko)); AddEuclideanEdge(mesh, completed, p, new Vector3D(io - 1, jo, ko)); AddEuclideanEdge(mesh, completed, p, new Vector3D(io, jo + 1, ko)); AddEuclideanEdge(mesh, completed, p, new Vector3D(io, jo - 1, ko)); AddEuclideanEdge(mesh, completed, p, new Vector3D(io, jo, ko + 1)); AddEuclideanEdge(mesh, completed, p, new Vector3D(io, jo, ko - 1)); } } } STL.SaveMeshToSTL(mesh.Mesh, "434.stl"); //PovRay.WriteEdges( new PovRay.Parameters() { AngularThickness = .05 }, Geometry.Euclidean, completed.ToArray(), "434.pov", append: false ); }
/// <summary> /// A helper for adding a sphere. center should be passed in the ball model. /// The approach is similar to how we do the bananas below. /// </summary> public static void AddSphere( Shapeways mesh, Vector3D center, H3.Settings settings ) { Vector3D centerUHS = H3Models.BallToUHS( center ); // Find the Mobius we need. // We'll do this in two steps. // (1) Find a mobius taking center to (0,0,h). // (2) Deal with scaling to a height of 1. Vector3D flattened = centerUHS; flattened.Z = 0; Mobius m1 = new Mobius( flattened, Complex.One, Infinity.InfinityVector ); Vector3D centerUHS_transformed = m1.ApplyToQuaternion( centerUHS ); double scale = 1.0 / centerUHS_transformed.Z; Mobius m2 = new Mobius( scale, Complex.Zero, Complex.Zero, Complex.One ); Mobius m = m2 * m1; // Compose them (multiply in reverse order). // Add the sphere at the Ball origin. // It will *always* be generated with the same radius. Shapeways tempMesh = new Shapeways(); tempMesh.AddSphere( new Vector3D(), H3Models.Ball.SizeFunc( new Vector3D(), settings.AngularThickness ) ); // Unwind the transforms. for( int i=0; i<tempMesh.Mesh.Triangles.Count; i++ ) { tempMesh.Mesh.Triangles[i] = new Mesh.Triangle( H3Models.BallToUHS( tempMesh.Mesh.Triangles[i].a ), H3Models.BallToUHS( tempMesh.Mesh.Triangles[i].b ), H3Models.BallToUHS( tempMesh.Mesh.Triangles[i].c ) ); } Banana.TakePointsBack( tempMesh.Mesh, m.Inverse(), settings ); mesh.Mesh.Triangles.AddRange( tempMesh.Mesh.Triangles ); }