Ejemplo n.º 1
0
        internal static bool _2DProjectionCheck(TessellatedSolid solid, TessellatedSolid solidBlocking, double[] direction)
        {
            var movingProj = _3Dto2D.Get2DProjectionPoints(solid.Vertices, direction);
            var moving2D   = new _3Dto2D
            {
                ThreeD = solid,
                Points = movingProj,
                Edges  = _3Dto2D.Get2DEdges(solid, movingProj)
            };
            var referenceProj = _3Dto2D.Get2DProjectionPoints(solidBlocking.Vertices, direction);
            var reference2D   = new _3Dto2D
            {
                ThreeD = solidBlocking,
                Points = referenceProj,
                Edges  = _3Dto2D.Get2DEdges(solidBlocking, referenceProj)
            };
            var blocked =
                moving2D.Edges.Any(
                    movEdge =>
                    reference2D.Edges.Any(
                        refEdge =>
                        NonadjacentBlockingDeterminationPro.DoIntersect(movEdge, refEdge)));

            return(blocked);
        }
        internal static void Run(designGraph graph,
                                 List <TessellatedSolid> solids, List <int> gDir)
        {
            foreach (var dir in gDir)
            {
                var direction             = DisassemblyDirections.Directions[dir];
                var blockingsForDirection = new List <NonAdjacentBlockings>();
                foreach (var solid in solids.Where(s => graph.nodes.Any(n => n.name == s.Name)))
                {
                    var movingProj = _3Dto2D.Get2DProjectionPoints(solid.Vertices, direction);

                    /*var edgeList1 = new List<double[]>();
                     * foreach (var edge in solid.Edges)
                     * {
                     *  var edge2D = new double[][2];
                     *  edge2D[0] = edge.From.Position;
                     *  edge2D[1] = edge.To.Position;
                     *  edgeList1.Add(edge2D);
                     * }*/
                    var moving2D = new _3Dto2D {
                        ThreeD = solid, Points = movingProj, Edges = _3Dto2D.Get2DEdges(solid, movingProj)
                    };
                    foreach (var solidBlocking in
                             solids.Where(s => graph.nodes.Any(n => n.name == s.Name) && // it is not fastener
                                          s != solid           // it is not the same as current solid
                                          &&
                                          !graph.arcs.Any(a => // there is no arc between the current and the candidate
                                                          (a.From.name == solid.Name && a.To.name == s.Name) ||
                                                          (a.From.name == s.Name && a.To.name == solid.Name))))
                    {
                        var referenceProj = _3Dto2D.Get2DProjectionPoints(solidBlocking.Vertices, direction);
                        var reference2D   = new _3Dto2D {
                            ThreeD = solidBlocking, Points = referenceProj, Edges = _3Dto2D.Get2DEdges(solidBlocking, referenceProj)
                        };
                        var blocked = IsItBlocked(moving2D, reference2D);
                        if (blocked)
                        {
                            blockingsForDirection.Add(new NonAdjacentBlockings
                            {
                                blockingSolids = new[] { solid, solidBlocking }
                            });
                        }
                    }
                }
                NonadjacentBlockingDetermination.NonAdjacentBlocking.Add(dir, blockingsForDirection);
            }
        }
        private static bool ProximityBeta(TessellatedSolid solid1, TessellatedSolid solid2, List <int> localDirInd)
        {
            var counter1 = 0;
            var counter2 = 0;
            var counter3 = 0;
            var s        = new Stopwatch();

            s.Start();
            for (int i = 0; i < solid1.Faces.Length; i++)
            {
                var a = solid1.Faces[i];
                for (int j = 0; j < solid2.Faces.Length; j++)
                {
                    var b = solid2.Faces[j];
                    if (Math.Abs(a.Normal.dotProduct(b.Normal) + 1) > 0.0055)
                    {
                        continue;                                                       // 0.0055
                    }
                    counter2++;
                    var q  = a.Center;
                    var p  = b.Center;
                    var pq = new[] { q[0] - p[0], q[1] - p[1], q[2] - p[2] };
                    if (Math.Abs(pq.dotProduct(a.Normal)) > 0.011)
                    {
                        continue;                                            //0.11 //0.005
                    }
                    counter3++;

                    /*var overl = true;
                     * foreach (var edge in a.Edges)
                     * {
                     *  var edgeVector = edge.Vector;
                     *  var third = a.Vertices.First(ad => ad != edge.From && ad != edge.To).Position;
                     *  var checkVec = third.subtract(edge.From.Position);
                     *  double[] cross1 = edgeVector.crossProduct(checkVec);
                     *  var c = 0;
                     *  foreach (var vertexB in b.Vertices)
                     *  {
                     *      var newVec = vertexB.Position.subtract(edge.From.Position);
                     *      var cross2 = edgeVector.crossProduct(newVec);
                     *      if ((Math.Sign(cross1[0]) != Math.Sign(cross2[0]) ||
                     *           (Math.Sign(cross1[0]) == 0 && Math.Sign(cross2[0]) == 0)) &&
                     *          (Math.Sign(cross1[1]) != Math.Sign(cross2[1]) ||
                     *           (Math.Sign(cross1[1]) == 0 && Math.Sign(cross2[1]) == 0)) &&
                     *          (Math.Sign(cross1[2]) != Math.Sign(cross2[2]) ||
                     *           (Math.Sign(cross1[2]) == 0 && Math.Sign(cross2[2]) == 0)))
                     *      {
                     *          c++;
                     *      }
                     *  }
                     *  if (c == 3)
                     *  {
                     *      overl = false;
                     *      break;
                     *  }
                     * }
                     * if (!overl) continue;
                     * foreach (var edge in b.Edges)
                     * {
                     *  var edgeVector = edge.Vector;
                     *  var third = b.Vertices.First(ad => ad != edge.From && ad != edge.To).Position;
                     *  var checkVec = third.subtract(edge.From.Position);
                     *  double[] cross1 = edgeVector.crossProduct(checkVec);
                     *  var c = 0;
                     *  foreach (var vertexB in a.Vertices)
                     *  {
                     *      var newVec = vertexB.Position.subtract(edge.From.Position);
                     *      var cross2 = edgeVector.crossProduct(newVec);
                     *      if ((Math.Sign(cross1[0]) != Math.Sign(cross2[0]) ||
                     *           (Math.Sign(cross1[0]) == 0 && Math.Sign(cross2[0]) == 0)) &&
                     *          (Math.Sign(cross1[1]) != Math.Sign(cross2[1]) ||
                     *           (Math.Sign(cross1[1]) == 0 && Math.Sign(cross2[1]) == 0)) &&
                     *          (Math.Sign(cross1[2]) != Math.Sign(cross2[2]) ||
                     *           (Math.Sign(cross1[2]) == 0 && Math.Sign(cross2[2]) == 0)))
                     *      {
                     *          c++;
                     *      }
                     *  }
                     *  if (c == 3)
                     *  {
                     *      overl = false;
                     *      break;
                     *  }
                     * }
                     * if (!overl) continue;*/
                    var aProj = _3Dto2D.Get2DProjectionPoints(a.Vertices, a.Normal);
                    var a2D   = new _3Dto2D {
                        Points = aProj, Edges = _3Dto2D.Get2DEdgesFromFace(a, aProj)
                    };
                    var bProj = _3Dto2D.Get2DProjectionPoints(b.Vertices, a.Normal);
                    var b2D   = new _3Dto2D {
                        Points = bProj, Edges = _3Dto2D.Get2DEdgesFromFace(b, bProj)
                    };
                    if (!NonadjacentBlockingDeterminationPro.IsItBlocked(a2D, b2D))
                    {
                        continue;
                    }
                    counter1++;
                    for (var k = 0; k < localDirInd.Count; k++)
                    {
                        var dir = DisassemblyDirections.Directions[localDirInd[k]];
                        if (a.Normal.dotProduct(dir) < -0.04)
                        {
                            localDirInd.Remove(localDirInd[k]);
                            k--;
                        }
                    }
                    break;
                }
            }
            // Merge removal directions:
            var final = new List <int>();

            foreach (var i in localDirInd)
            {
                if (
                    final.Any(
                        d =>
                        1 - DisassemblyDirections.Directions[d].dotProduct(DisassemblyDirections.Directions[i]) <
                        0.05))
                {
                    continue;
                }
                final.Add(i);
            }
            s.Stop();
            Console.WriteLine(s.Elapsed);
            return(true);
        }
 internal static bool IsItBlocked(_3Dto2D moving2D, _3Dto2D reference2D)
 {
     return(moving2D.Edges.Any(movEdge => reference2D.Edges.Any(refEdge => DoIntersect(movEdge, refEdge))));
 }
Ejemplo n.º 5
0
        private static bool newApproachBoundingBox(double[] v, double[] bB, double[] mB)
        {
            var mV1       = new Vertex(new[] { mB[0], mB[2], mB[4] });
            var mV2       = new Vertex(new[] { mB[0], mB[3], mB[4] });
            var mV3       = new Vertex(new[] { mB[1], mB[3], mB[4] });
            var mV4       = new Vertex(new[] { mB[1], mB[2], mB[4] });
            var mV5       = new Vertex(new[] { mB[0], mB[2], mB[5] });
            var mV6       = new Vertex(new[] { mB[0], mB[3], mB[5] });
            var mV7       = new Vertex(new[] { mB[1], mB[3], mB[5] });
            var mV8       = new Vertex(new[] { mB[1], mB[2], mB[5] });
            var movingVer = new List <Vertex> {
                mV1, mV2, mV3, mV4, mV5, mV6, mV7, mV8
            };
            var mE1       = new Edge(mV1, mV2, true);
            var mE2       = new Edge(mV1, mV4, true);
            var mE3       = new Edge(mV1, mV5, true);
            var mE4       = new Edge(mV2, mV3, true);
            var mE5       = new Edge(mV2, mV6, true);
            var mE6       = new Edge(mV7, mV6, true);
            var mE7       = new Edge(mV7, mV3, true);
            var mE8       = new Edge(mV7, mV8, true);
            var mE9       = new Edge(mV5, mV6, true);
            var mE10      = new Edge(mV5, mV8, true);
            var mE11      = new Edge(mV4, mV3, true);
            var mE12      = new Edge(mV4, mV8, true);
            var movingEdg = new List <Edge> {
                mE1, mE2, mE3, mE4, mE5, mE6, mE7, mE8, mE9, mE10, mE11, mE12
            };

            var bV1         = new Vertex(new[] { bB[0], bB[2], bB[4] });
            var bV2         = new Vertex(new[] { bB[0], bB[3], bB[4] });
            var bV3         = new Vertex(new[] { bB[1], bB[3], bB[4] });
            var bV4         = new Vertex(new[] { bB[1], bB[2], bB[4] });
            var bV5         = new Vertex(new[] { bB[0], bB[2], bB[5] });
            var bV6         = new Vertex(new[] { bB[0], bB[3], bB[5] });
            var bV7         = new Vertex(new[] { bB[1], bB[3], bB[5] });
            var bV8         = new Vertex(new[] { bB[1], bB[2], bB[5] });
            var blockingVer = new List <Vertex> {
                bV1, bV2, bV3, bV4, bV5, bV6, bV7, bV8
            };
            var bE1         = new Edge(bV1, bV2, true);
            var bE2         = new Edge(bV1, bV4, true);
            var bE3         = new Edge(bV1, bV5, true);
            var bE4         = new Edge(bV2, bV3, true);
            var bE5         = new Edge(bV2, bV6, true);
            var bE6         = new Edge(bV7, bV6, true);
            var bE7         = new Edge(bV7, bV3, true);
            var bE8         = new Edge(bV7, bV8, true);
            var bE9         = new Edge(bV5, bV6, true);
            var bE10        = new Edge(bV5, bV8, true);
            var bE11        = new Edge(bV4, bV3, true);
            var bE12        = new Edge(bV4, bV8, true);
            var blockingEdg = new List <Edge> {
                bE1, bE2, bE3, bE4, bE5, bE6, bE7, bE8, bE9, bE10, bE11, bE12
            };

            var movingProj   = _3Dto2D.Get2DProjectionPoints(movingVer, v);
            var blockingProj = _3Dto2D.Get2DProjectionPoints(blockingVer, v);
            var moving2D     = new _3Dto2D {
                Points = movingProj, Edges = _3Dto2D.Get2DEdges2(movingEdg, movingVer, movingProj)
            };
            var blocking2D = new _3Dto2D {
                Points = blockingProj, Edges = _3Dto2D.Get2DEdges2(blockingEdg, blockingVer, movingProj)
            };

            return(moving2D.Edges.Any(movEdge => blocking2D.Edges.Any(refEdge => NonadjacentBlockingDeterminationPro.DoIntersect(movEdge, refEdge))));
        }