示例#1
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(...)
        public Scientrace.PlaneBorderEnclosedVolume parseXTruncatedPyramid(XElement xTruncatedPyramid)
        {
            // Replaced with below: Scientrace.MaterialProperties materialprops = this.getXMaterial(xToppedPyramid.Element("Material"));
            Scientrace.MaterialProperties materialprops = this.getXMaterialForObject(xTruncatedPyramid);

            if ((xTruncatedPyramid.Name.ToString() != "TruncatedPyramid") && (xTruncatedPyramid.Name.ToString() != "ToppedPyramid"))
            {
                throw new XMLException("TruncatedPyramid does not match its name: " + xTruncatedPyramid.Name.ToString());
            }

            List <Scientrace.Location> front_corners = new List <Scientrace.Location>();

            Scientrace.Vector loc_sum = new Scientrace.Vector(0, 0, 0);
            foreach (XElement xFrontCorner in xTruncatedPyramid.Elements("Corner"))
            {
                Scientrace.Location loc = this.X.getXLocation(xFrontCorner);
                front_corners.Add(loc);
                loc_sum = loc_sum + loc;
            }
            Scientrace.Vector   loc_avg     = loc_sum / front_corners.Count;
            Scientrace.Location virtual_top = this.X.getXLocation(xTruncatedPyramid, "VirtualTop");
            // parsing topping plane data:
            XElement xTopPlane = xTruncatedPyramid.Element("TopPlane");

            if (xTopPlane == null)
            {
                throw new XMLException("TopPlane element not found... " + xTruncatedPyramid.ToString());
            }
            Scientrace.Location      topPlaneLoc    = this.X.getXLocation(xTopPlane, "Location");
            Scientrace.NonzeroVector topPlaneNormal = this.X.getXNzVectorByName(xTopPlane, "Normal");
            if (topPlaneNormal.dotProduct((topPlaneLoc - loc_avg)) > 0)
            {
                topPlaneNormal = topPlaneNormal.negative();
            }
            Scientrace.PlaneBorder topping_plane = new Scientrace.PlaneBorder(topPlaneLoc, topPlaneNormal);

            Scientrace.PlaneBorderEnclosedVolume tRetTruncatedPyramid = Scientrace.PlaneBorderEnclosedVolume.createTruncatedPyramid(this.parentcollection, materialprops,
                                                                                                                                    front_corners, virtual_top, topping_plane);
            return(tRetTruncatedPyramid);
        }