public bool EdgesShareVertex(Vector.MemorySafe_CartCoord vertex, DOEgbXMLBasics.EdgeFamily edge)
        {
            double lengthTol = DOEgbXMLBasics.Tolerances.SurfacePLCoordTolerance;
            double dx = Math.Abs(vertex.X - edge.startendpt[0].X);
            double dy = Math.Abs(vertex.Y - edge.startendpt[0].Y);
            double dz = Math.Abs(vertex.Z - edge.startendpt[0].Z);
            if(dx <= lengthTol && dy <= lengthTol && dz <= lengthTol)
            {
                return true;
            }

            dx = Math.Abs(vertex.X - edge.startendpt[1].X);
            dy = Math.Abs(vertex.Y - edge.startendpt[1].Y);
            dz = Math.Abs(vertex.Z - edge.startendpt[1].Z);

            if(dx <= lengthTol && dy <= lengthTol && dz <= lengthTol)
            {
                return true;
            }

            return false;
        }
 public bool EdgesShareVertex(DOEgbXMLBasics.EdgeFamily edge, DOEgbXMLBasics.EdgeFamily checkEdge)
 {
     double lengthTol = DOEgbXMLBasics.Tolerances.SurfacePLCoordTolerance;
     double startdX = Math.Abs(edge.startendpt[0].X - checkEdge.startendpt[0].X);
     double startdY = Math.Abs(edge.startendpt[0].Y - checkEdge.startendpt[0].Y);
     double startdZ = Math.Abs(edge.startendpt[0].Z - checkEdge.startendpt[0].Z);
     if (startdX <= lengthTol && startdY <= lengthTol && startdZ <= lengthTol)
     {
         return true;
     }
     startdX = Math.Abs(edge.startendpt[0].X - checkEdge.startendpt[1].X);
     startdY = Math.Abs(edge.startendpt[0].Y - checkEdge.startendpt[1].Y);
     startdZ = Math.Abs(edge.startendpt[0].Z - checkEdge.startendpt[1].Z);
     if (startdX <= lengthTol && startdY <= lengthTol && startdZ <= lengthTol)
     {
         return true;
     }
     double enddX = Math.Abs(edge.startendpt[1].X - checkEdge.startendpt[1].X);
     double enddY = Math.Abs(edge.startendpt[1].Y - checkEdge.startendpt[1].Y);
     double enddZ = Math.Abs(edge.startendpt[1].Z - checkEdge.startendpt[1].Z);
     if (enddX <= lengthTol && enddY <= lengthTol && enddZ <= lengthTol)
     {
         return true;
     }
     enddX = Math.Abs(edge.startendpt[1].X - checkEdge.startendpt[0].X);
     enddY = Math.Abs(edge.startendpt[1].Y - checkEdge.startendpt[0].Y);
     enddZ = Math.Abs(edge.startendpt[1].Z - checkEdge.startendpt[0].Z);
     if (enddX <= lengthTol && enddY <= lengthTol && enddZ <= lengthTol)
     {
         return true;
     }
     return false;
 }
示例#3
0
        public static Dictionary<int, DOEgbXMLBasics.EdgeFamily> FindEdgeMatch(Dictionary<int, DOEgbXMLBasics.EdgeFamily> uniqueedges, DOEgbXMLBasics.EdgeFamily edge)
        {
            try
            {
                int edgeloopcounter = 0; //keeps track of how many guest edges in the unique edge dictionary I've searched through
                foreach (KeyValuePair<int, DOEgbXMLBasics.EdgeFamily> kp in uniqueedges)
                {
                    Vector.MemorySafe_CartCoord gueststartpt = kp.Value.startendpt[0];
                    //In the unique edge dictionary, I have located at least one point that is similar to my test edge, a tolerance needed?
                    if (gueststartpt.X == edge.startendpt[0].X && gueststartpt.Y == edge.startendpt[0].Y && gueststartpt.Z == edge.startendpt[0].Z)
                    {
                        //found at least one perfect coordinate match, try to match the second...get the endpoint of the unique edge in the dictionary
                        Vector.MemorySafe_CartCoord guestendpt = kp.Value.startendpt[1];
                        if (guestendpt.X == edge.startendpt[1].X && guestendpt.Y == edge.startendpt[1].Y && guestendpt.Z == edge.startendpt[1].Z)
                        {
                            //both match, means the match is perfect, so the unique edge has found it complement related edge.  Great!
                            kp.Value.relatedEdges.Add(edge);
                            //I am done searching this test edge, and I can start over again with the next edge in question
                            break;

                        }
                        else
                        {
                            //so far, I have found only one thing in common, sharing of one point, even though second point did not match, the edges could still align
                            //draw vector A
                            double Ax = guestendpt.X - edge.startendpt[1].X;
                            double Ay = guestendpt.Y - edge.startendpt[1].Y;
                            double Az = guestendpt.Z - edge.startendpt[1].Z;
                            Vector.MemorySafe_CartVect A = new Vector.MemorySafe_CartVect(Ax, Ay, Az);
                            double Amag = Vector.VectorMagnitude(A);

                            //take cross product to see if they are even in same plane
                            double evX = guestendpt.X - gueststartpt.X;
                            double evY = guestendpt.Y - gueststartpt.Y;
                            double evZ = guestendpt.Z - gueststartpt.Z;
                            Vector.MemorySafe_CartVect ev = new Vector.MemorySafe_CartVect(evX, evY, evZ);
                            double evmag = Vector.VectorMagnitude(ev);
                            Vector.MemorySafe_CartVect cross = Vector.CrossProduct(A, ev);
                            double dot = Vector.DotProduct(A, ev);
                            double crossmag = Vector.VectorMagnitude(cross);
                            //If Vector A and ev are parallel, then the cross product magnitude should be zero, add a small tolerance?
                            if (dot == 1)
                            {
                                //then we are at least parallel but they are perfect matches
                                //now see if both points of the test edge resides ON the  guest edge or OUTSIDE of it
                                double Bx = gueststartpt.X - edge.startendpt[1].X;
                                double By = gueststartpt.Y - edge.startendpt[1].Y;
                                double Bz = gueststartpt.Z - edge.startendpt[1].Z;
                                Vector.MemorySafe_CartVect B = new Vector.MemorySafe_CartVect(Bx, By, Bz);
                                double Bmag = Vector.VectorMagnitude(B);
                                //check to see if the test edge is inside the guest edge (shorter than)
                                //check to see if the test edge is outside of the guest edge (longer than)
                                //the first check is easier and should always yield an easy answer
                                if (Amag < evmag && Bmag < evmag)
                                {
                                    //true
                                    //we choose to create related edges relationship for test and guest edge because a perfect match wasn't found
                                    //so this test edge is added to the guest unique edge
                                    kp.Value.relatedEdges.Add(edge);
                                    //and the test edge itself accumulate its own relationships (it is seen as sort of unique)
                                    edge.relatedEdges.Add(kp.Value);
                                    //we will continue checking the unique guest edges to look for another match, since we have not found perfection
                                    edgeloopcounter++;
                                    continue;
                                }
                                //otherwise it does not fall inside the guest edge
                                //check now to see if the test edge falls outside of the guest edge
                                //it either overlaps it, or does not overlap it at all
                                //we know the two vectors are parallel and not antiparallel because of the dot product above
                                //now test the quality of their relationship
                            }
                            //some sort of tolerance here?
                            else if (dot == -1)
                            {
                                double testedgeX = edge.startendpt[1].X - edge.startendpt[0].X;
                                double testedgeY = edge.startendpt[1].Y - edge.startendpt[0].Y;
                                double testedgeZ = edge.startendpt[1].Z - edge.startendpt[0].Z;
                                Vector.MemorySafe_CartVect edgevec = new Vector.MemorySafe_CartVect(testedgeX, testedgeY, testedgeZ);
                                double testedgemag = Vector.VectorMagnitude(edgevec);

                                if (evmag < testedgemag)
                                {
                                    //this means the test edge is longer than the guest edge,
                                    //since we know they are parallel and share a common first point, we can conclude
                                    //they overlap but are not perfect matches.
                                    //so each accumulates a relationship
                                    kp.Value.relatedEdges.Add(edge);
                                    //the edge is still unique but accumulates a neighbor
                                    edge.relatedEdges.Add(kp.Value);
                                    edgeloopcounter++;
                                    continue;
                                }
                                //deprecated as not productive code on March 30, 2014

                                //double Cx = gueststartpt.X - edge.startendpt[1].X;
                                //double Cy = gueststartpt.Y - edge.startendpt[1].Y;
                                //double Cz = gueststartpt.Z - edge.startendpt[1].Z;
                                //Vector.MemorySafe_CartVect C = new Vector.MemorySafe_CartVect(Cx, Cy, Cz);
                                //double Cmag = Vector.VectorMagnitude(C);

                                //double Dx = guestendpt.X - edge.startendpt[1].X;
                                //double Dy = guestendpt.Y - edge.startendpt[1].Y;
                                //double Dz = guestendpt.Z - edge.startendpt[1].Z;
                                //Vector.MemorySafe_CartVect D = new Vector.MemorySafe_CartVect(Dx, Dy, Dz);
                                //double Dmag = Vector.VectorMagnitude(D);

                                //if (Dmag < testedgemag && Cmag < testedgemag)
                                //{
                                //    //this means the test edge is longer than the guest edge,
                                //    //since we know they are parallel and share a common first point, we can conclude
                                //    //they overlap but are not perfect matches.
                                //    //so each accumulates a relationship
                                //    kp.Value.relatedEdges.Add(edge);
                                //    //the edge is still unique but accumulates a neighbor
                                //    edge.relatedEdges.Add(kp.Value);
                                //    edgeloopcounter++;
                                //    continue;
                                //}

                            }//are the two lines parallel
                            else
                            {
                                //the two lines aren't parallel, so just move on
                                edgeloopcounter++;
                                continue;
                            }
                        }//else there is not a perfect match
                    } //if one coordinate has perfectly matched
                    //here the the start point of the guest edge matches the end point of the testedge, a switcheroo
                    else if (gueststartpt.X == edge.startendpt[1].X && gueststartpt.Y == edge.startendpt[1].Y && gueststartpt.Z == edge.startendpt[1].Z)
                    {
                        //found at least one perfect coordinate match, try to match the second
                        Vector.MemorySafe_CartCoord guestendpt = kp.Value.startendpt[1];
                        if (guestendpt.X == edge.startendpt[0].X && guestendpt.Y == edge.startendpt[0].Y && guestendpt.Z == edge.startendpt[0].Z)
                        {
                            //both match, means the match is perfect, so add it to the related surfaces list
                            kp.Value.relatedEdges.Add(edge);
                            break;

                        }
                        else
                        {
                            //the edge may be unique, though it could still have neighboring relationships
                            double Ax = guestendpt.X - edge.startendpt[0].X;
                            double Ay = guestendpt.Y - edge.startendpt[0].Y;
                            double Az = guestendpt.Z - edge.startendpt[0].Z;
                            Vector.MemorySafe_CartVect A = new Vector.MemorySafe_CartVect(Ax, Ay, Az);
                            double Amag = Vector.VectorMagnitude(A);

                            //take cross product to see if they are even in same plane
                            double evX = guestendpt.X - gueststartpt.X;
                            double evY = guestendpt.Y - gueststartpt.Y;
                            double evZ = guestendpt.Z - gueststartpt.Z;
                            Vector.MemorySafe_CartVect ev = new Vector.MemorySafe_CartVect(evX, evY, evZ);
                            double evmag = Vector.VectorMagnitude(ev);
                            double dot = Vector.DotProduct(A, ev);
                            Vector.MemorySafe_CartVect cross = Vector.CrossProduct(A, ev);
                            double crossmag = Vector.VectorMagnitude(cross);
                            //tolerance?
                            //we know that they are parallel, and therefore that the test edge is shorter than the guest edge
                            if (dot == 1)
                            {
                                //we now verify if the point resides on the edge or outside of it
                                double Bx = gueststartpt.X - edge.startendpt[0].X;
                                double By = gueststartpt.Y - edge.startendpt[0].Y;
                                double Bz = gueststartpt.Z - edge.startendpt[0].Z;
                                Vector.MemorySafe_CartVect B = new Vector.MemorySafe_CartVect(Bx, By, Bz);
                                double Bmag = Vector.VectorMagnitude(B);
                                //check to see if the test edge is inside the guest edge
                                if (Amag < evmag && Bmag < evmag)
                                {
                                    //this means it lies on the plane at least, so it shares, but it is also still independent because a perfect match wasn't found
                                    kp.Value.relatedEdges.Add(edge);
                                    //accumulate its own relationships
                                    edge.relatedEdges.Add(kp.Value);
                                    edgeloopcounter++;
                                    continue;
                                }
                            }
                            //we know the lines are antiparallel, meaning that the test edge is longer than the guest edge
                            else if (dot == -1)
                            {
                                double testedgeX = edge.startendpt[1].X - edge.startendpt[0].X;
                                double testedgeY = edge.startendpt[1].Y - edge.startendpt[0].Y;
                                double testedgeZ = edge.startendpt[1].Z - edge.startendpt[0].Z;
                                Vector.MemorySafe_CartVect edgevec = new Vector.MemorySafe_CartVect(testedgeX, testedgeY, testedgeZ);
                                double testedgemag = Vector.VectorMagnitude(edgevec);

                                //we verify
                                if (testedgemag > evmag)
                                {
                                    //this means the test edge is longer than the guest edge, but they overlap
                                    kp.Value.relatedEdges.Add(edge);
                                    //the edge is still unique but accumulates a neighbor
                                    edge.relatedEdges.Add(kp.Value);
                                    edgeloopcounter++;
                                    continue;
                                }
                                //deprecated as not productive code March 30 2014
                                //double Cx = gueststartpt.X - edge.startendpt[0].X;
                                //double Cy = gueststartpt.Y - edge.startendpt[0].Y;
                                //double Cz = gueststartpt.Z - edge.startendpt[0].Z;
                                //Vector.MemorySafe_CartVect C = new Vector.MemorySafe_CartVect(Cx, Cy, Cz);
                                //double Cmag = Vector.VectorMagnitude(C);

                                //double Dx = guestendpt.X - edge.startendpt[0].X;
                                //double Dy = guestendpt.Y - edge.startendpt[0].Y;
                                //double Dz = guestendpt.Z - edge.startendpt[0].Z;
                                //Vector.MemorySafe_CartVect D = new Vector.MemorySafe_CartVect(Dx, Dy, Dz);
                                //double Dmag = Vector.VectorMagnitude(D);

                                //if (Dmag < testedgemag && Cmag < testedgemag)
                                //{
                                //    //this means the test edge is longer than the guest edge, but they overlap
                                //    kp.Value.relatedEdges.Add(edge);
                                //    //the edge is still unique but accumulates a neighbor
                                //    edge.relatedEdges.Add(kp.Value);
                                //    edgeloopcounter++;
                                //    continue;
                                //}
                            }
                            else
                            {
                                //this other point isn't relevant, and the edges don't coincide
                                edgeloopcounter++;
                                continue;
                            }
                        }

                    }//second point matches first point
                    //neither points perfectly coincide, so we do an exhaustive overlap check.
                    else
                    {
                        Vector.MemorySafe_CartCoord guestendpt = kp.Value.startendpt[1];
                        //are the two vectors even parallel?  because if they are not, no need to get more complex
                        double evX = guestendpt.X - gueststartpt.X;
                        double evY = guestendpt.Y - gueststartpt.Y;
                        double evZ = guestendpt.Z - gueststartpt.Z;
                        Vector.MemorySafe_CartVect guestvec = new Vector.MemorySafe_CartVect(evX, evY, evZ);
                        double guestvecmag = Vector.VectorMagnitude(guestvec);

                        double edgeX = edge.startendpt[1].X - edge.startendpt[0].X;
                        double edgeY = edge.startendpt[1].Y - edge.startendpt[0].Y;
                        double edgeZ = edge.startendpt[1].Z - edge.startendpt[0].Z;
                        Vector.MemorySafe_CartVect testedgev = new Vector.MemorySafe_CartVect(edgeX, edgeY, edgeZ);
                        //tolerance?
                        if (Vector.VectorMagnitude(Vector.CrossProduct(guestvec, testedgev)) != 0)
                        {
                            //they are not even parallel so move on
                            edgeloopcounter++;
                            continue;
                        }
                        //if the cross product is zero
                        //try to determine if the two edges are parallel or antiparallel
                        //test edge point 1

                        double Ax = gueststartpt.X - edge.startendpt[0].X;
                        double Ay = gueststartpt.Y - edge.startendpt[0].Y;
                        double Az = gueststartpt.Z - edge.startendpt[0].Z;
                        Vector.MemorySafe_CartVect A = new Vector.MemorySafe_CartVect(Ax, Ay, Az);
                        double Amag = Vector.VectorMagnitude(A);

                        //take cross product to see if they are even in same plane

                        Vector.MemorySafe_CartVect cross1 = Vector.CrossProduct(A, guestvec);
                        double crossA = Vector.VectorMagnitude(cross1);
                        //tolerance?
                        if (crossA == 0)
                        {
                            //we are at least parallel, now to check for a real intersection
                            double Bx = gueststartpt.X - edge.startendpt[1].X;
                            double By = gueststartpt.Y - edge.startendpt[1].Y;
                            double Bz = gueststartpt.Z - edge.startendpt[1].Z;
                            Vector.MemorySafe_CartVect B = new Vector.MemorySafe_CartVect(Bx, By, Bz);
                            double Bmag = Vector.VectorMagnitude(B);
                            double crossB = Vector.VectorMagnitude(Vector.CrossProduct(B, guestvec));
                            //check to see if the test edge's first point (index 0) is totally inside the guest edge
                            if (crossB == 0)
                            {
                                //we know they are now surely parallel, and that they are on top of one another, question is, do they overlap?
                                Vector.PointVector guestPV = new Vector.PointVector(gueststartpt, guestendpt);
                                Vector.PointVector test1 = new Vector.PointVector(gueststartpt, edge.startendpt[0]);
                                Vector.PointVector test2 = new Vector.PointVector(gueststartpt, edge.startendpt[1]);

                                bool test1inside = false;
                                bool test2inside = false;
                                //tolerance?
                                if (Vector.DotProduct(guestPV.v, test1.v) == 1)
                                {
                                    //then pointed in the same direction

                                    double ratio = Amag / guestvecmag;
                                    if (ratio > 1)
                                    {
                                        //then this point is outside of evmag
                                    }
                                    else
                                    {
                                        //there is an intersection at the point of the test edge
                                        test1inside = true;
                                    }
                                }
                                //tolerance?
                                if (Vector.DotProduct(guestPV.v, test1.v) == 1)
                                {
                                    //then this second test edge point is in a straight line in the same direction as the vector formed by the test edge
                                    double ratio = Bmag / guestvecmag;
                                    if (ratio > 1)
                                    {
                                        //then this point is outside
                                    }
                                    else
                                    {
                                        //this is also inside
                                        test2inside = true;
                                    }

                                }

                                if (test1inside == true && test2inside == false)
                                {
                                    //make a temporary edge from just point 1 in the test edge
                                    //this should never happen for a single space, should it?

                                }
                                else if (test1inside == false && test2inside == true)
                                {
                                    //make a temporary edge from just point 2 in the test edge
                                    //this should never happen for a single space, should it?
                                }
                                else if (test1inside == true && test2inside == true)
                                {
                                    //the entire test edge is contained within
                                    //this means the test edge is longer than the guest edge, but they overlap
                                    kp.Value.relatedEdges.Add(edge);
                                    //the edge is still unique but accumulates a neighbor
                                    edge.relatedEdges.Add(kp.Value);
                                    edgeloopcounter++;
                                    continue;
                                }
                                else
                                {
                                    //do nothing because neither points reside inside.
                                }

                            }
                        }
                    }
                    int uniqueedgect = uniqueedges.Count() + 1;
                    uniqueedges[uniqueedgect] = edge;
                }

            }
            catch (Exception e)
            {

            }
            return uniqueedges;
        }