Beispiel #1
0
        //--------------------------------------------------------------------------------------------------

        public static bool ComputeAxisFromVertex(TopoDS_Face face, TopoDS_Vertex vertex, out Ax1 axis)
        {
            // Get normal at point of vertex
            var uv          = BRep_Tool.Parameters(vertex, face);
            Pnt centerPoint = Pnt.Origin;
            Vec faceNormal  = Vec.Zero;

            new BRepGProp_Face(face).Normal(uv.X, uv.Y, ref centerPoint, ref faceNormal);

            // Find edges
            var edges = face.Edges(false).Where(edge => edge.Vertices().ContainsSame(vertex)).ToList();

            if (edges.Count != 2)
            {
                axis = new Ax1();
                return(false);
            }

            // Calc direction
            bool order    = false; // is false if face is on the left of edge1
            var  tangents = new Vec[2];

            for (var edgeIndex = 0; edgeIndex < edges.Count; edgeIndex++)
            {
                var edge = edges[edgeIndex];

                var edgeAdaptor = edge.Adaptor();
                var parameter   = BRep_Tool.Parameter(vertex, edge);

                Pnt unusedPoint = Pnt.Origin;
                Vec edgeTangent = Vec.Zero;
                edgeAdaptor.D1(parameter, ref unusedPoint, ref edgeTangent);

                var parameterReversed = parameter > (edgeAdaptor.FirstParameter() + edgeAdaptor.LastParameter()) * 0.5;
                if (parameterReversed)
                {
                    edgeTangent.Reverse();
                }

                if (edgeIndex == 0 && parameterReversed != (edge.Orientation() == TopAbs_Orientation.TopAbs_REVERSED))
                {
                    order = true; // face is on the right of edge1
                }
                tangents[edgeIndex] = edgeTangent.Normalized();
            }

            var direction = tangents[0].Added(tangents[1]);

            var angleBetweenTangents = tangents[0].AngleWithRef(tangents[1], faceNormal);

            if (order)
            {
                angleBetweenTangents *= -1.0;
            }
            if (angleBetweenTangents < 0)
            {
                // Concave vertex
                direction.Reverse();
            }

            axis = new Ax1(centerPoint, direction.ToDir());
            return(true);
        }