Exemplo n.º 1
0
        private BrepTrim GetClosetBrepTrim(BrepTrimList TrimList, Curve Crv)
        {
            foreach (BrepTrim item in TrimList)
            {
                //
                //item.TrimCurve 会出现问题,
                //关于TrimCurve官方的解释如下
                //Gets the Brep.Curves2D 2d curve geometry used by this trim, or null.
                //item.Edge is an 2D Curve
                //
                //这里只对两根线是否相等进行了简单的判断,如果起始点相等,那么就相等,否则不相等
                Curve EdgeCrv = item.Edge.EdgeCurve;

                Point3d TrimSPt = EdgeCrv.PointAtStart;
                Point3d TrimEPt = EdgeCrv.PointAtEnd;

                bool IsMeetEnd = (TrimSPt.EpsilonEquals(Crv.PointAtStart, 10) && TrimEPt.EpsilonEquals(Crv.PointAtEnd, 10)) ||
                                 (TrimSPt.EpsilonEquals(Crv.PointAtEnd, 10) && TrimEPt.EpsilonEquals(Crv.PointAtStart, 10));

                if (IsMeetEnd)
                {
                    return(item);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
 public bool EpsilonEquals(Plane other, double epsilon)
 {
     return(m_origin.EpsilonEquals(other.m_origin, epsilon) &&
            m_xaxis.EpsilonEquals(other.m_xaxis, epsilon) &&
            m_yaxis.EpsilonEquals(other.m_yaxis, epsilon) &&
            m_zaxis.EpsilonEquals(other.m_zaxis, epsilon));
 }
Exemplo n.º 3
0
        public void TestEvaluatAndProject()
        {
            Action <Plane3d, double, double> test = (plane, u, v) =>
            {
                Point3d  p  = plane.Evaluate(u, v);
                double[] uv = plane.Project(p);
                Assert.IsTrue(u.EpsilonEquals(uv[0]) && u.EpsilonEquals(uv[1]));
                Point3d p2 = plane.Evaluate(uv[0], uv[1]);
                Assert.IsTrue(p.EpsilonEquals(p2));
            };

            // Comprueba los métodos Evaluate y Project sobre planos ortonormales.
            {
                Plane3d plane = Plane3d.NewOrthonormal(new Point3d(10, 0, 0), new Point3d(0, 10, 0), new Point3d(0, 0, 10));
                test(plane, -10, -10);
                test(plane, -1, -1);
                test(plane, -0.5, -0.5);
                test(plane, 0, 0);
                test(plane, 0.5, 0.5);
                test(plane, 1, 1);
                test(plane, 10, 10);
            }

            // Comprueba los métodos Evaluate y Project sobre planos no ortonormales.
            {
                Plane3d plane = Plane3d.NewNonOrthonormal(new Point3d(10, 0, 0), new Point3d(0, 10, 0), new Point3d(0, 0, 10));
                test(plane, -10, -10);
                test(plane, -1, -1);
                test(plane, -0.5, -0.5);
                test(plane, 0, 0);
                test(plane, 0.5, 0.5);
                test(plane, 1, 1);
                test(plane, 10, 10);
            }
        }
Exemplo n.º 4
0
        public void TestEvaluatAndProject()
        {
            Action <Triangle3d, double, double> test01 = (tri, u, v) =>
            {
                Point3d  p  = tri.Evaluate01(u, v);
                double[] uv = tri.Project01(p);
                Assert.IsTrue(u.EpsilonEquals(uv[0]) && v.EpsilonEquals(uv[1]));
                Point3d p2 = tri.Evaluate01(uv[0], uv[1]);
                Assert.IsTrue(p.EpsilonEquals(p2));
            };

            Action <Triangle3d, double, double> testBar = (tri, u, v) =>
            {
                Point3d  p   = tri.EvaluateBar(u, v);
                double[] uvw = tri.ProjectBar(p);
                Assert.IsTrue(u.EpsilonEquals(uvw[0]) && v.EpsilonEquals(uvw[1]) && (1 - u - v).EpsilonEquals(uvw[2]));
                Point3d p2 = tri.EvaluateBar(uvw[0], uvw[1], uvw[2]);
                Assert.IsTrue(p.EpsilonEquals(p2));
            };

            /*Action<Triangle3d,REAL, REAL, REAL> testTri = (tri, x, y, z) =>
             * {
             *  POINT p = tri.EvaluateTri(x, y, z);
             *  REAL[] xyz = tri.ProjectTri(p);
             *  Assert.IsTrue(x.EpsilonEquals(xyz[0]) && y.EpsilonEquals(xyz[1]) && z.EpsilonEquals(xyz[2]));
             *  POINT p2 = tri.EvaluateTri(xyz[0], xyz[1], xyz[2]);
             *  Assert.IsTrue(p.EpsilonEquals(p2));
             * };*/

            {
                Triangle3d tri = new Triangle3d(new Point3d(1, 0, 0), new Point3d(0, 1, 0), new Point3d(0, 0, 1));
                test01(tri, 0, 0);
                test01(tri, 0.1, 0.1);
                test01(tri, 0.2, 0.2);
                test01(tri, 0.3, 0.3);
                test01(tri, 0, 0.3);
                test01(tri, 0.3, 0);

                Assert.IsTrue(tri.EvaluateBar(1, 0, 0).EpsilonEquals(tri.P0));
                Assert.IsTrue(tri.EvaluateBar(0, 1, 0).EpsilonEquals(tri.P1));
                Assert.IsTrue(tri.EvaluateBar(0, 0, 1).EpsilonEquals(tri.P2));

                testBar(tri, 0, 0);
                testBar(tri, 1, 0);
                testBar(tri, 0, 1);
                testBar(tri, 0.5, 0);
                testBar(tri, 0.5, 0.5);
                testBar(tri, 1.0 / 3.0, 1.0 / 3.0);
            }
        }
Exemplo n.º 5
0
        public void TestDistance()
        {
            Func <Plane3d, Point3d, bool> test = (plane, p) =>
            {
                double[] uv = plane.Project(p);

                Point3d pEnPlano = plane.Evaluate(uv[0], uv[1]);

                Point3d closestPoint;
                double  d = plane.Distance(p, out closestPoint);

                Point3d p3 = pEnPlano + plane.Normal * d;

                bool pEqualsP3 = p.EpsilonEquals(p3);
                bool pEnPlanoEqualsClosestPoint = pEnPlano.EpsilonEquals(closestPoint);

                return(pEqualsP3 && pEnPlanoEqualsClosestPoint && p.DistanceTo(pEnPlano).EpsilonEquals(Math.Abs(d)));
            };

            // Comprueba los metodos Project, Evaluate y DistanceTo sobre planos ortonormales.
            {
                Plane3d plane = Plane3d.NewOrthonormal(new Point3d(10, 0, 0), new Point3d(0, 10, 0), new Point3d(0, 0, 10));
                Assert.IsTrue(test(plane, new Point3d(0, 0, 0)));
                Assert.IsTrue(test(plane, new Point3d(100, 100, 100)));
                Assert.IsTrue(test(plane, new Point3d(5, 5, 5)));
                Assert.IsTrue(test(plane, new Point3d(10 / 3.0, 10 / 3.0, 10 / 3.0)));

                Assert.IsTrue(plane.Distance(new Point3d(0, 0, 0)).EpsilonEquals(-5.773, 1e-3));
                Assert.IsTrue(plane.Distance(new Point3d(100, 100, 100)).EpsilonEquals(167.431, 1e-3));
                Assert.IsTrue(plane.Distance(new Point3d(5, 5, 5)).EpsilonEquals(2.886, 1e-3));
                Assert.IsTrue(plane.Distance(new Point3d(10 / 3.0, 10 / 3.0, 10 / 3.0)).EpsilonEquals(0));
            }

            // Comprueba los metodos Project, Evaluate y DistanceTo sobre planos no ortonormales.
            {
                Plane3d plane = Plane3d.NewNonOrthonormal(new Point3d(10, 0, 0), new Point3d(0, 10, 0), new Point3d(0, 0, 10));
                Assert.IsTrue(test(plane, new Point3d(0, 0, 0)));
                Assert.IsTrue(test(plane, new Point3d(100, 100, 100)));
                Assert.IsTrue(test(plane, new Point3d(5, 5, 5)));
                Assert.IsTrue(test(plane, new Point3d(10 / 3.0, 10 / 3.0, 10 / 3.0)));

                Assert.IsTrue(plane.Distance(new Point3d(0, 0, 0)).EpsilonEquals(-5.773, 1e-3));
                Assert.IsTrue(plane.Distance(new Point3d(100, 100, 100)).EpsilonEquals(167.431, 1e-3));
                Assert.IsTrue(plane.Distance(new Point3d(5, 5, 5)).EpsilonEquals(2.886, 1e-3));
                Assert.IsTrue(plane.Distance(new Point3d(10 / 3.0, 10 / 3.0, 10 / 3.0)).EpsilonEquals(0));
            }
        }
Exemplo n.º 6
0
 public bool EpsilonEquals(Line other, double epsilon)
 {
     return(m_from.EpsilonEquals(other.m_from, epsilon) &&
            m_to.EpsilonEquals(other.m_to, epsilon));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Removes duplicate/invalid/tiny curves and outputs the cleaned list, a list of unique nodes and a list of node pairs.
        /// </summary>
        public static List <Curve> CleanNetwork(List <Curve> inputStruts, double tol, out Point3dList nodes, out List <IndexPair> nodePairs)
        {
            nodes     = new Point3dList();
            nodePairs = new List <IndexPair>();

            var struts = new List <Curve>();

            // Loop over list of struts
            for (int i = 0; i < inputStruts.Count; i++)
            {
                Curve strut = inputStruts[i];
                // Unitize domain
                strut.Domain = new Interval(0, 1);
                // Minimum strut length (if user defined very small tolerance, use 100*rhinotolerance)
                double minLength = Math.Max(tol, 100 * RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                // If strut is invalid, ignore it
                if (strut == null || !strut.IsValid || strut.IsShort(minLength))
                {
                    continue;
                }

                Point3d[] pts = new Point3d[2] {
                    strut.PointAtStart, strut.PointAtEnd
                };
                List <int> nodeIndices = new List <int>();
                // Loop over end points of strut
                // Check if node is already in nodes list, if so, we find its index instead of creating a new node
                for (int j = 0; j < 2; j++)
                {
                    Point3d pt = pts[j];
                    // Find closest node to current pt
                    int closestIndex = nodes.ClosestIndex(pt);

                    // If node already exists (within tolerance), set the index
                    if (nodes.Count != 0 && pt.EpsilonEquals(nodes[closestIndex], tol))
                    {
                        nodeIndices.Add(closestIndex);
                    }
                    // If node doesn't exist
                    else
                    {
                        // Update lookup list
                        nodes.Add(pt);
                        nodeIndices.Add(nodes.Count - 1);
                    }
                }

                // We must ignore duplicate struts
                bool      isDuplicate = false;
                IndexPair nodePair    = new IndexPair(nodeIndices[0], nodeIndices[1]);

                int dupIndex = nodePairs.IndexOf(nodePair);
                // dupIndex equals -1 if nodePair not found, i.e. if it doesn't equal -1, a match was found
                if (nodePairs.Count != 0 && dupIndex != -1)
                {
                    // Check the curve midpoint to make sure it's a duplicate
                    Curve   testStrut = struts[dupIndex];
                    Point3d ptA       = strut.PointAt(0.5);
                    Point3d ptB       = testStrut.PointAt(0.5);
                    if (ptA.EpsilonEquals(ptB, tol))
                    {
                        isDuplicate = true;
                    }
                }

                // So we only create the strut if it doesn't exist yet (check nodePairLookup list)
                if (!isDuplicate)
                {
                    // Update the lookup list
                    nodePairs.Add(nodePair);
                    strut.Domain = new Interval(0, 1);
                    struts.Add(strut);
                }
            }

            return(struts);
        }