예제 #1
0
        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 -->");
        }
예제 #2
0
        public static PlaneBorder createBetween3LocationsPointingTo(Scientrace.Location baseLoc, Scientrace.Location loc2, Scientrace.Location loc3, Scientrace.Location pointingToLoc)
        {
            Vector        v1        = (loc2 - baseLoc).tryToUnitVector();
            Vector        v2        = (loc3 - baseLoc).tryToUnitVector();
            NonzeroVector tryNormal = v1.crossProduct(v2).tryToNonzeroVector();
            //Console.WriteLine("V1: "+v1.trico()+" v2:"+v2.trico()+" trynormal:"+tryNormal.trico());
            PlaneBorder tryBorder = new PlaneBorder(baseLoc, tryNormal);

            if (tryBorder.contains(pointingToLoc))
            {
                return(tryBorder);
            }
            tryBorder = new PlaneBorder(baseLoc, tryNormal.negative());
            if (tryBorder.contains(pointingToLoc))
            {
                return(tryBorder);
            }
            throw new Exception("Couldn't create PlaneBorder containing " + pointingToLoc.trico());
        }         //end createBetween3LocationsPoitningTo(...)
예제 #3
0
 public string getX3DTranslationTag(Scientrace.Location loc)
 {
     return("<Transform translation='" + loc.trico() + "'>");
 }
예제 #4
0
        public Scientrace.Object3d constructFresnelLens(XElement xel)
        {
            /* due to the complex structure of the fresnelLens (a collection)
             * the generic getShadowObject3dBase method cannot be used */
            ShadowScientrace.ShadowObject3d shadowO3D =
                new ShadowScientrace.ShadowObject3d(typeof(Scientrace.FresnelLens), this.parentcollection,
                                                    this.parentcollection.materialproperties);
            shadowO3D.arguments.Add("double_convex", this.X.getXBool(xel, "DoubleConvex", false));

            //base parameters
            // Both
            // Some settings when FocalVector is present
            if ((xel.Element("FocalVector") != null) || xel.Element("FocalLocation") != null)
            {
                //LensPlanoCenter must be defined. Absense will not be tolerated combined with FocalLocation or FocalVector
                Scientrace.Location planoCenter = this.X.getXLocation(xel, "LensPlanoCenter");

                Scientrace.NonzeroVector focalVec;
                if (xel.Element("FocalLocation") != null)
                {
                    // the relative nonzerovector based on two locations must be checked after comparing both, which implies manual error checking/throwing.
                    Scientrace.Vector focalLoc = this.X.getXVectorByName(xel, "FocalLocation");
                    try {
                        focalVec = (focalLoc - planoCenter).tryToNonzeroVector();
                    } catch (Exception e) {
                        Console.WriteLine("ERROR: focal vector ({FocalLocation: " + focalLoc.trico() + "} - {LensPlanoCenter:" + planoCenter.trico() + "}) cannot be zero.");
                        throw(e);
                    }
                }
                else
                {
                    focalVec = this.X.getXNzVectorByName(xel, "FocalVector");
                }
                shadowO3D.arguments.Add("orientation_from_sphere_center", focalVec.toUnitVector());
                shadowO3D.arguments.Add("focal_length", focalVec.length);
            }
            else
            {
                //possible options:
                //or
                shadowO3D.arguments.Add("lens_sphere_radius", this.X.getXNullDouble(xel, "LensSphereRadius"));
                //or
                shadowO3D.arguments.Add("focal_length", this.X.getXNullDouble(xel, "FocalLength"));
                shadowO3D.arguments.Add("orientation_from_sphere_center", this.X.getXNzVectorByName(xel, "OpticalAxis").toUnitVector());
                shadowO3D.arguments.Add("lens_sphere_location", this.X.getXLocation(xel, "LensSphereCenter", null));
            }

            shadowO3D.arguments.Add("lens_plano_center", this.X.getXLocation(xel, "LensPlanoCenter", null));
            shadowO3D.arguments.Add("width_rings_count", this.X.getXNullDouble(xel, "WidthRings"));
            shadowO3D.arguments.Add("height_rings_count", this.X.getXNullDouble(xel, "HeightRings"));
            shadowO3D.arguments.Add("angle_rings_count", this.X.getXNullDouble(xel, "AngleRings"));
            shadowO3D.arguments.Add("var_rings_count", this.X.getXNullDouble(xel, "VarRings"));

            shadowO3D.arguments.Add("focus_wavelength", this.X.getXNullDouble(xel, "FocusWavelength"));


            shadowO3D.arguments.Add("lens_material", this.getXMaterial(xel));

            shadowO3D.arguments.Add("draw_3d_segment_linecount", this.X.getXNullInt(xel, "Draw3DLineCount"));

            //possible options:
            //or
            shadowO3D.arguments.Add("lens_sphere_radians_min", this.X.getXNullAngleByName(xel, "MinAngle"));
            shadowO3D.arguments.Add("lens_sphere_radians_max", this.X.getXNullAngleByName(xel, "MaxAngle"));
            //or
            shadowO3D.arguments.Add("lens_radius", this.X.getXNullDouble(xel, "Radius", (double?)0.5 * this.X.getXNullDouble(xel, "Diameter")));

            //base the constructor method on the parameters submitted by the user
            if (shadowO3D.hasArgument("var_rings_count"))     //various radius rings are also equal width
            {
                return(shadowO3D.factory("VarRings"));
            }
            if (shadowO3D.hasArgument("angle_rings_count"))
            {
                return(shadowO3D.factory("EqualAngleRings"));
            }
            if (shadowO3D.hasArgument("width_rings_count"))
            {
                return(shadowO3D.factory("EqualWidthRings"));
            }
            if (shadowO3D.hasArgument("height_rings_count"))
            {
                return(shadowO3D.factory("EqualHeightRings"));
            }
            throw new Exception("Factory method not set/known");
        }                                                                 //end constructFresnelLens
예제 #5
0
 public static string get_RGB_Line_XML(Scientrace.Location loc1, Scientrace.Location loc2, string colourRGBstring)
 {
     if (loc1 == null || loc2 == null)
     {
         return("");
     }
     return(@"<!--RGBA_Line--><Shape><LineSet vertexCount='2'><Coordinate point='" + loc2.trico() + " \t" + loc1.trico() + @"' />" +
            "<Color color='" + colourRGBstring + " \t" + colourRGBstring + @"' /></LineSet></Shape>");
 }