コード例 #1
0
        public string exportX3DLineSet(Scientrace.Vector a, Scientrace.Vector b, Scientrace.Vector c, Scientrace.Vector d)
        {
            return(@"<!-- Start Rectangle instance -->\n<Transform translation='" + this.parallelogram.plane.loc.trico() + @"'>
<Shape>
<!-- Coordinate rectangle sequence (matches coordIndex actually) 0 1 2 3 0 -->
<LineSet vertexCount='5'>
<Coordinate point='
" + a.trico() + ", " + b.trico() + ", " + c.trico() + ", " + d.trico() + ", " + a.trico() + "'/>" +
                   @"<ColorRGBA color='0 1 0 1, 0 1 0 1, 
						0 1 0 1, 0 1 0 1, 
						0 1 0 1, 0 1 0 1, 
						0 1 0 1, 0 1 0 1' />	
</LineSet>" +
                   @"      </Shape>\" +
                   @"    </Transform>\n<!-- End Rectangle instance -->");
        }
コード例 #2
0
        public string exportX3DFilledSurface(Scientrace.Vector a, Scientrace.Vector b, Scientrace.Vector c, Scientrace.Vector d)
        {
            return
                (@"    <Transform translation='" + this.parallelogram.plane.loc.trico() + @"'><Shape>
      <IndexedFaceSet DEF='" + this.tag + "' solid='" + (this.x3d_fill_both_sides?"false":"true") + @"' coordIndex='0 1 2 3' normalIndex='0 0 0 0'>
        <Coordinate point='" + a.trico() + ", " + b.trico() + ", " + c.trico() + ", " + d.trico() + @"'/>
        <Normal vector='" + this.getX3DNormal().trico() + @"'/>
      </IndexedFaceSet>
 " + this.getX3DAppearance() + @"
    </Shape></Transform>");
        }
コード例 #3
0
        }         // end func partialReflectRefract

        public void initCreatedRefractTrace(Trace refractTrace, UnitVector surfaceNormal, Scientrace.Object3d fromObject3d, Scientrace.Object3d toObject3d)
        {
            double oldrefindex = fromObject3d.materialproperties.refractiveindex(this);
            double newrefindex = toObject3d.materialproperties.refractiveindex(this);
            //for definitions on the parameters below, check fullInternalReflects function.

            UnitVector incoming_trace_direction = this.traceline.direction;

            if (incoming_trace_direction.dotProduct(surfaceNormal) > 0)
            {
                surfaceNormal = surfaceNormal.negative();
            }

            Scientrace.UnitVector nnorm = surfaceNormal.negative();
            Scientrace.Vector     incoming_normal_projection = nnorm * (incoming_trace_direction.dotProduct(nnorm));
            Vector L1 = incoming_trace_direction - incoming_normal_projection;
            double L2 = (oldrefindex / newrefindex) * L1.length;

            if (incoming_trace_direction == incoming_normal_projection)
            {
                //in case of normal incident light: do not refract.
                refractTrace.traceline.direction = incoming_trace_direction;
                return;
            }

            try {
                refractTrace.traceline.direction = ((nnorm * Math.Sqrt(1 - Math.Pow(L2, 2)))
                                                    + (L1.tryToUnitVector() * L2)).tryToUnitVector();
            } catch (ZeroNonzeroVectorException) {
                Console.WriteLine("WARNING: cannot define direction for refraction trace. Using surface normal instead. (L1: " + incoming_trace_direction.trico() + ", L2:" + incoming_normal_projection.trico() + ").");
                refractTrace.traceline.direction = nnorm;
            }             //end try/catch
        }
コード例 #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 ParallelVectorException(Scientrace.Vector vec1, Scientrace.Vector vec2, string str)
 {
     Console.WriteLine("Two vectors (" + vec1.trico() + " / " + vec2.trico() + ") are parallel which is not allowed. " + str);
 }