internal static Gear PolynomialTrendDetector(TessellatedSolid solid)
        {
            // Since gears have different shapes, we need to generate bounding circles in multiple locations
            // around the gear (bounding cylinde). If any of them are showing a gear, return true.
            // This makes the code really slow.
            // To also find negative (internal) gears:
            //   1. if the closest with negative dot product triangles to bounding cylinder points, it is a positive gear
            //   2. if the closest with positive dot product triangles to bounding cylinder points, it is a negative gear
            var section          = 5.0;
            var bC               = BoundingCylinder.Run(solid);
            var kPointsOnSurface = KpointObMidSurfaceOfCylinderGenerator(bC, 1000);

            for (var i = 0.0; i <= 1; i += 1 / section)
            {
                var distancePointToSolidPositive = PointToSolidDistanceCalculator(solid, kPointsOnSurface, bC, i);
                // in the distance point to solid array, first one  is for outer triangle (general case)
                // the second one is for inner triangle (written for negative gears)
                List <int> originalInds;
                distancePointToSolidPositive[0] =
                    FastenerPolynomialTrend.MergingEqualDistances(distancePointToSolidPositive[0], out originalInds, 0.001);
                //FastenerPolynomialTrend.PlotInMatlab(distancePointToSolidPositive[0]);
                if (IsGear(distancePointToSolidPositive[0]))
                {
                    return new Gear
                           {
                               Solid               = solid,
                               PointOnAxis         = bC.PointOnTheCenterLine,
                               Axis                = bC.CenterLineVector,
                               LargeCylinderRadius = bC.Radius,
                               SmallCylinderRadius = bC.Radius - TeethDepthFinder(distancePointToSolidPositive[0])
                           }
                }
                ;
                // check and see if it is an inner gear
                List <int> originalInds2;
                distancePointToSolidPositive[1] =
                    FastenerPolynomialTrend.MergingEqualDistances(distancePointToSolidPositive[1], out originalInds2, 0.001);
                if (IsGear(distancePointToSolidPositive[1]))
                {
                    return new Gear
                           {
                               Solid               = solid,
                               Type                = GearType.Internal,
                               PointOnAxis         = bC.PointOnTheCenterLine,
                               Axis                = bC.CenterLineVector,
                               LargeCylinderRadius = bC.Radius,
                               SmallCylinderRadius = bC.Radius - TeethDepthFinder(distancePointToSolidPositive[0])
                           }
                }
                ;
            }
            return(null);
        }
Пример #2
0
        internal static void CreateBoundingCylinder(Dictionary <string, List <TessellatedSolid> > solids)
        {
            // This function uses my own OBB code not the one in TVGL
            // It has more accurate results
            //var s = new Stopwatch();
            //s.Start();
            //Console.WriteLine();
            //Console.WriteLine("Bounding Cylinders are being Created ...");
            var solidGeometries = solids.SelectMany(s => s.Value).ToList();

            Parallel.ForEach(solidGeometries, solid =>
            {
                var bc = BoundingCylinder.Run(solid);
                lock (BoundingCylinderDic)
                {
                    BoundingCylinderDic.Add(solid, bc);
                }
            }
                             );
            //s.Stop();
            //Console.WriteLine("Bounding Cylinder Creation is done in:" + "     " + s.Elapsed);
        }