示例#1
0
        public static void ShowFaceDirection(TopoDSFace face, Document Document)
        {
            var p1 = new gpPnt();
            var v1 = new gpVec();
            var v2 = new gpVec();

            var sf = new BRepAdaptorSurface(face, true);
            var u  = sf.FirstUParameter;
            var x  = sf.LastUParameter;

            if (Precision.IsInfinite(u))
            {
                u = (Precision.IsInfinite(x)) ? 0.0 : x;
            }
            else if (!Precision.IsInfinite(x))
            {
                u = (u + x) / 2.0;
            }

            var v = sf.FirstVParameter;

            x = sf.LastVParameter;
            if (Precision.IsInfinite(v))
            {
                v = (Precision.IsInfinite(x)) ? 0.0 : x;
            }
            else if (!Precision.IsInfinite(x))
            {
                v = (v + x) / 2.0;
            }

            sf.D1(u, v, p1, v1, v2);
            var vector = v1.Crossed(v2);

            x = vector.Magnitude;

            // The direction vector length
            const double length = 70.0;

            if (x > 0.0000001)
            {
                vector.Multiply(length / x);
            }
            else
            {
                vector.SetCoord(length / 2.0, 0, 0);
            }

            var p2 = new gpPnt(p1.X, p1.Y, p1.Z);

            p2.Translate(vector);

            if (p1.IsEqual(p2, Precision.Confusion))
            {
                return;
            }

            DrawArrow(Document, p1, p2, face.Orientation());
        }