public List <ObjectLinePiece> slice(List <ObjectLinePiece> lps, PlaneBorder aPlaneBorder)
        {
            List <ObjectLinePiece> retSlices = new List <ObjectLinePiece>();

            foreach (ObjectLinePiece anObjectLinePiece in lps)
            {
                Line sectLine = anObjectLinePiece.lp.toLine();
                //Console.WriteLine("FOO"+aPlaneBorder.getNormal().dotProduct(sectLine.direction));
                if (Math.Abs(aPlaneBorder.getNormal().dotProduct(sectLine.direction)) < MainClass.SIGNIFICANTLY_SMALL)
                {
                    //Console.WriteLine("BAR");
                    retSlices.Add(anObjectLinePiece);
                    continue;             // line is within the plane, does not intersect. Continue for iLimitBorder loop
                }
                Scientrace.Location node = aPlaneBorder.lineThroughPlane(sectLine);
                if (node == null)
                {
                    Console.WriteLine("WARNING, NODE=null: " + aPlaneBorder.ToString() + " vs. " + sectLine.ToString());
                    continue;             // somehow the line didn't go through the plane in the end... strange..
                }
                // fill return-list
                retSlices.AddRange(this.toOLP(anObjectLinePiece.lp.sliceIfBetween(node), "0 0.2 0.5 1", anObjectLinePiece.o3d));
            }
            return(retSlices);
        }
예제 #2
0
 public bool isParallelTo(PlaneBorder anotherPlaneBorder)
 {
     Scientrace.UnitVector n1, n2;
     n1 = this.allowedDirNormal.toUnitVector();
     n2 = anotherPlaneBorder.allowedDirNormal.toUnitVector();
     //Console.WriteLine("DEBUG: Crossproduct "+n1.trico()+"/"+n2.trico()+": "+n1.crossProduct(n2).length);
     return(n1.crossProduct(n2).length == 0);
 }
예제 #3
0
        // Constructor: plane, sphereCenterLoc, sphereRadius
        protected PlanoConvexLens(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops,
			Scientrace.PlaneBorder lensPlane, Scientrace.Location sphereCenterLoc, double sphereRadius)
            : base(parent, mprops)
        {
            this.lensPlane = lensPlane;
            this.sphereCenterLoc = sphereCenterLoc;
            this.sphereRadius = sphereRadius;
            this.dummySphere = new Scientrace.Sphere(null, null, sphereCenterLoc, sphereRadius);
        }
예제 #4
0
 // Constructor: plane, sphereCenterLoc, sphereRadius
 protected PlanoConvexLens(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops,
                           Scientrace.PlaneBorder lensPlane, Scientrace.Location sphereCenterLoc, double sphereRadius)
     : base(parent, mprops)
 {
     this.lensPlane       = lensPlane;
     this.sphereCenterLoc = sphereCenterLoc;
     this.sphereRadius    = sphereRadius;
     this.dummySphere     = new Scientrace.Sphere(null, null, sphereCenterLoc, sphereRadius);
 }
예제 #5
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());
 }
 public bool contains(Scientrace.Location aLocation, PlaneBorder excludeBorder, double excludedMargin)
 {
     foreach (PlaneBorder aBorder in this.borders)       // iterate all borders
     {
         if (aBorder == excludeBorder)
         {
             continue;             // if a location is created AT a border, it's safer to exclude that border from checking due to floating point errors
         }
         if (!aBorder.containsExclude(aLocation, excludedMargin))
         {
             return(false); // location not within border? FALSE
         }
     }                      // end foreach borders
     return(true);          // all good? TRUE
 }
예제 #7
0
        public Intersection intersectsObject(Trace trace, Object3d o3dWithThisBorder)
        {
            PlaneBorder aBorder = this;

            if (trace.traceline.direction.dotProduct(aBorder.getNormal()) == 0)
            {
                return(Intersection.notIntersect(o3dWithThisBorder));        //trace is parallel to plane, will not intersect.
            }
            Scientrace.Location intersectLoc = aBorder.intersectsAt(trace.traceline);

            if (intersectLoc == null)
            {
                return(Intersection.notIntersect(o3dWithThisBorder));        //trace is parallel to plane, will not intersect.
            }
            return(new Intersection(true, o3dWithThisBorder, intersectLoc, new Scientrace.FlatShape2d(this.tPlane), null, this.contains(trace.traceline.startingpoint)));
        }
예제 #8
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(...)
예제 #9
0
        // Factory method: lensFlatCenterLoc, sphereRadius, lensDiameter
        public static Scientrace.PlanoConvexLens CreateWithLensDiameter(Scientrace.Object3dCollection parent, 
					Scientrace.MaterialProperties mprops,
					Scientrace.Location lensFlatCenterLoc, double lensDiameter,
					Scientrace.NonzeroVector sphereRadiusVec)
        {
            Scientrace.PlaneBorder aPlane = new PlaneBorder(lensFlatCenterLoc, sphereRadiusVec);
            double r /*sphere radius*/ = sphereRadiusVec.length;
            double x /*lens radius*/ = lensDiameter/2;
            double y /*distance lens center to sphere center*/ = Math.Sqrt((r*r)-(x*x));
            double t /*thickness*/ = r-y;

            //Console.WriteLine("sphereradius: "+r+" lens thickness: "+t+" y:"+y+" x:"+x);

            if (t<=0) {
                throw new Exception("This PlanoConvexLens cannot be created: "+sphereRadiusVec.trico()+"/"+lensDiameter);
                }
            Scientrace.Location sphereLoc = lensFlatCenterLoc - (sphereRadiusVec.normalizedVector()*y);
            //Console.WriteLine("sphereLoc: "+sphereLoc.trico()+" lensFlatCenterLoc: "+t+" lensFlatCenterLoc:"+lensFlatCenterLoc.trico());
            return new PlanoConvexLens(parent, mprops, aPlane, sphereLoc, r);
        }
예제 #10
0
        // Factory method: lensFlatCenterLoc, sphereRadius, lensDiameter
        static public Scientrace.PlanoConvexLens CreateWithLensDiameter(Scientrace.Object3dCollection parent,
                                                                        Scientrace.MaterialProperties mprops,
                                                                        Scientrace.Location lensFlatCenterLoc, double lensDiameter,
                                                                        Scientrace.NonzeroVector sphereRadiusVec)
        {
            Scientrace.PlaneBorder aPlane = new PlaneBorder(lensFlatCenterLoc, sphereRadiusVec);
            double r /*sphere radius*/    = sphereRadiusVec.length;
            double x /*lens radius*/      = lensDiameter / 2;
            double y /*distance lens center to sphere center*/ = Math.Sqrt((r * r) - (x * x));
            double t /*thickness*/ = r - y;

            //Console.WriteLine("sphereradius: "+r+" lens thickness: "+t+" y:"+y+" x:"+x);

            if (t <= 0)
            {
                throw new Exception("This PlanoConvexLens cannot be created: " + sphereRadiusVec.trico() + "/" + lensDiameter);
            }
            Scientrace.Location sphereLoc = lensFlatCenterLoc - (sphereRadiusVec.normalizedVector() * y);
            //Console.WriteLine("sphereLoc: "+sphereLoc.trico()+" lensFlatCenterLoc: "+t+" lensFlatCenterLoc:"+lensFlatCenterLoc.trico());
            return(new PlanoConvexLens(parent, mprops, aPlane, sphereLoc, r));
        }
예제 #11
0
        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);
        }
        public static PlaneBorderEnclosedVolume createTruncatedPyramid(
            Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops,
            List <Scientrace.Location> front_corners, Scientrace.Location pyramid_top_location, PlaneBorder topping_plane)
        {
            /*// DEBUG INFO:
             * Console.WriteLine("DEBUG: creating topped pyramid with front_corners: ");
             * foreach (Scientrace.Location aLoc in front_corners) {
             *      Console.Write("Location: "+aLoc.trico());
             *      }
             * Console.WriteLine("Top location: "+pyramid_top_location.trico());
             * Console.WriteLine("topping_plane: "+topping_plane);
             * // END DEBUG INFO */
            if (front_corners.Count < 3)
            {
                throw new IndexOutOfRangeException("(topped) pyramid must have -at least- 3 front_corners in list (=" + front_corners.Count + ").");
            }
            List <Scientrace.PlaneBorder> truncatedPyramidBorders = new List <Scientrace.PlaneBorder>();

            truncatedPyramidBorders.Add(     //adding large (opening) plane
                PlaneBorder.createBetween3LocationsPointingTo(front_corners[0], front_corners[1], front_corners[2], pyramid_top_location)
                );

            int fcc = front_corners.Count;

            for (int iBorder = 0; iBorder < fcc; iBorder++)       //adding side planes
            //Console.WriteLine("PLANE:"+
            //front_corners[iBorder].trico()+ front_corners[(iBorder+1)%fcc].trico()+ pyramid_top_location.trico()+" towards: "+front_corners[(iBorder+2)%fcc]);
            {
                truncatedPyramidBorders.Add(
                    PlaneBorder.createBetween3LocationsPointingTo(
                        front_corners[iBorder], front_corners[(iBorder + 1) % fcc], pyramid_top_location, front_corners[(iBorder + 2) % fcc])
                    );
            }

            truncatedPyramidBorders.Add(topping_plane);     //adding small (closing) plane

            return(new PlaneBorderEnclosedVolume(parent, mprops,
                                                 truncatedPyramidBorders));
        }         // end createTruncatedPyramid Factory Method
예제 #13
0
 public bool isParallelTo(PlaneBorder anotherPlaneBorder)
 {
     Scientrace.UnitVector n1, n2;
     n1 = this.allowedDirNormal.toUnitVector();
     n2 = anotherPlaneBorder.allowedDirNormal.toUnitVector();
     //Console.WriteLine("DEBUG: Crossproduct "+n1.trico()+"/"+n2.trico()+": "+n1.crossProduct(n2).length);
     return (n1.crossProduct(n2).length == 0);
 }
 public bool contains(Scientrace.Location aLocation, PlaneBorder excludeBorder)
 {
     return(this.contains(aLocation, excludeBorder, MainClass.SIGNIFICANTLY_SMALL));
 }
예제 #15
0
        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;
        }