Example #1
0
        //--------------------------------------------------------------------------------------------------

        public static bool ComputeAxisFromEdge(TopoDS_Face face, TopoDS_Edge edge, double parameter, out Ax1 axis)
        {
            axis = new Ax1();

            // Get edge point and tangent
            var adaptorEdge = edge.Adaptor();
            var edgeFirst   = adaptorEdge.FirstParameter();
            var edgeLast    = adaptorEdge.LastParameter();
            var centerParam = parameter.Clamp(edgeFirst, edgeLast);
            Pnt centerPoint = Pnt.Origin;
            Vec edgeTangent = Vec.Zero;

            adaptorEdge.D1(centerParam, ref centerPoint, ref edgeTangent);

            if (edge.Orientation() == TopAbs_Orientation.TopAbs_REVERSED)
            {
                edgeTangent.Reverse();
            }

            // Get normal at point of edge
            double first = 0, last = 0;
            var    curveOnSurface = BRep_Tool.CurveOnSurface(edge, face, ref first, ref last);

            if (curveOnSurface == null)
            {
                return(false);
            }

            var paramNormalized = (centerParam - edgeFirst) / (edgeLast - edgeFirst);
            var centerUV        = curveOnSurface.Value(first + (last - first) * paramNormalized);
            Vec faceNormal      = Vec.Zero;

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

            axis = new Ax1(centerPoint, faceNormal.ToDir().Crossed(edgeTangent.ToDir()));
            return(true);
        }
Example #2
0
        //--------------------------------------------------------------------------------------------------

        public static double CalculateBaseParameter(TopoDS_Edge edge, double normalizedParameter)
        {
            var adaptorEdge = edge.Adaptor();

            return((adaptorEdge.FirstParameter() + adaptorEdge.LastParameter()) * 0.5);
        }