public StringBuilder drawSphereSlice(Scientrace.Object3d drawnObject3d, double lateral_circles, double meridians, Scientrace.Sphere sphere, double from_radians, double to_radians, Scientrace.UnitVector sliceAlongDirection) { System.Text.StringBuilder retx3d = new System.Text.StringBuilder(1024); //"<!-- DOUBLECONVEXLENS GRID start -->"); double pi2 = Math.PI * 2; NonzeroVector orthoBaseVec1 = null; NonzeroVector orthoBaseVec2 = null; sliceAlongDirection.fillOrtogonalVectors(ref orthoBaseVec1, ref orthoBaseVec2); for (double iSphereCircle = 2 * lateral_circles; iSphereCircle > 0; iSphereCircle--) // the rings/parallels along the sliceAlongDirection axis { double lateral_radians = (to_radians * (iSphereCircle / (2 * lateral_circles))); double circle2DRadius = sphere.radius * Math.Sin(lateral_radians); double circle2DDistance = sphere.radius * Math.Cos(lateral_radians); retx3d.Append(this.drawCircle(sphere.loc + (sliceAlongDirection * circle2DDistance).toLocation(), circle2DRadius, sliceAlongDirection)); for (double iSphereMerid = 0.5; iSphereMerid < 2 * meridians; iSphereMerid++) // meridians connect the rings/circles on the spherical surface { Scientrace.Location tNodeLoc = sphere.getSphericalLoc( orthoBaseVec1, orthoBaseVec2, sliceAlongDirection, to_radians * (iSphereCircle / (2 * lateral_circles)), // lat_angle = theta pi2 * (iSphereMerid / (2 * meridians)) // mer_angle = phi ); if (!tNodeLoc.isValid()) { throw new NullReferenceException("Cannot calculate base gridpoint at @ " + drawnObject3d.tag); } Scientrace.Location tLatConnectLoc = sphere.getSphericalLoc( orthoBaseVec1, orthoBaseVec2, sliceAlongDirection, to_radians * ((iSphereCircle - 1) / (2 * lateral_circles)), // lat_angle = theta pi2 * ((iSphereMerid) / (2 * meridians)) // mer_angle = phi ); if (!tLatConnectLoc.isValid()) { throw new NullReferenceException("Cannot calculate lateral gridpoint at @ " + drawnObject3d.tag); } Scientrace.X3DGridPoint tGridPoint = new Scientrace.X3DGridPoint(0, tNodeLoc, null, tLatConnectLoc); retx3d.AppendLine(tGridPoint.exportX3DnosphereRGB(this.primaryRGB)); } } // end for iSphereCircle / iSphereMerid return(retx3d); }
public static string x3D_Sphere(Scientrace.Location aLoc, double radius, string sphere_colour, double sphere_colour_intensity) { if ((aLoc == null) || !aLoc.isValid()) { throw new Exception("NULLS OR NANS DETECTED"); } if (radius <= 0) { return(""); // no sphere with no radius } string transpstr = (sphere_colour_intensity < 1) ? " transparency='" + (1 - Math.Sqrt(sphere_colour_intensity)) + "'" : ""; /*Sqrt for visibility */ return(@"<!--X3DSphere --> <Transform scale='" + radius + " " + radius + " " + radius + @"' translation='" + aLoc.trico() + @"'> <Shape><Sphere /> <Appearance><Material emissiveColor='" + sphere_colour + @"'" + transpstr + @" /></Appearance> </Shape></Transform><!-- End X3DSphere -->"); }