コード例 #1
0
        /// <summary>
        /// Create a CurveByPoints element by three given points
        /// </summary>
        public static CurveByPoints MakeCurve(
            FamilyItemFactory creator,
            XYZ pa,
            XYZ pb,
            XYZ pc)
        {
            ReferencePoint rpa = creator.NewReferencePoint(pa);
            ReferencePoint rpb = creator.NewReferencePoint(pb);
            ReferencePoint rpc = creator.NewReferencePoint(pc);

            ReferencePointArray arr = new ReferencePointArray();

            arr.Append(rpa);
            arr.Append(rpb);
            arr.Append(rpc);

            return(creator.NewCurveByPoints(arr));
        }
コード例 #2
0
        /// <summary>
        /// Create a CurveByPoints element by three given points
        /// </summary>
        public static CurveByPoints MakeCurve(
            FamilyItemFactory creator,
            XYZ pa,
            XYZ pb,
            XYZ pc)
        {
            ReferencePoint rpa = creator.NewReferencePoint( pa );
              ReferencePoint rpb = creator.NewReferencePoint( pb );
              ReferencePoint rpc = creator.NewReferencePoint( pc );

              ReferencePointArray arr = new ReferencePointArray();

              arr.Append( rpa );
              arr.Append( rpb );
              arr.Append( rpc );

              return creator.NewCurveByPoints( arr );
        }
コード例 #3
0
        //绘制模型线
        private void CreateCurve(XYZ startPoint, XYZ endPoint, XYZ normal1, XYZ normal2)
        {
            XYZ StartToEnd = new XYZ((endPoint - startPoint).X, (endPoint - startPoint).Y, 0);
            XYZ p_normal1  = new XYZ(normal1.X, normal1.Y, 0);
            XYZ p_normal2  = new XYZ(normal2.X, normal2.Y, 0);

            p_normal1 = p_normal1 / (Math.Sqrt(p_normal1.X * p_normal1.X + p_normal1.Y * p_normal1.Y));
            p_normal2 = p_normal2 / (Math.Sqrt(p_normal2.X * p_normal2.X + p_normal2.Y * p_normal2.Y));


            XYZ XoYprj_start = new XYZ(startPoint.X, startPoint.Y, 0);
            XYZ XoYprj_end   = new XYZ(endPoint.X, endPoint.Y, 0);

            //在起点、终点间插值,并在z=0平面上绘制NurbSpline曲线
            double[]    doubleArray    = { 1, 1, 1, 1, 1, 1 };
            IList <XYZ> controlPoints2 = new List <XYZ>();

            controlPoints2.Add(XoYprj_start);
            controlPoints2.Add(XoYprj_start + p_normal1 * mmToFeet(2000));
            controlPoints2.Add(XoYprj_start + p_normal1 * mmToFeet(4000));
            controlPoints2.Add(XoYprj_end + p_normal2 * mmToFeet(4000));
            controlPoints2.Add(XoYprj_end + p_normal2 * mmToFeet(2000));
            controlPoints2.Add(XoYprj_end);

            Curve nbLine = NurbSpline.Create(controlPoints2, doubleArray);


            //提取曲线上的拟合点,并在z轴方向插值拟合原曲线
            IList <XYZ> ptsOnCurve = nbLine.Tessellate();

            int ptCount = ptsOnCurve.Count;
            ReferencePointArray ptArr = new ReferencePointArray();

            for (int i = 0; i < ptCount; i++)
            {
                XYZ pt = ptsOnCurve[i];
                if (i < (ptCount - 1) / 8)
                {
                    ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z)));
                }
                else if (i > 7 * (ptCount - 1) / 8)
                {
                    ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, endPoint.Z)));
                }
                else
                {
                    ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z + (i - (ptCount - 1) / 8) * (endPoint.Z - startPoint.Z) / (0.75 * (ptCount - 1)))));
                }
                //ReferencePoint p = m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z + i*(endPoint.Z - startPoint.Z)/ (ptCount - 1)));
                //ptArr.Append(p);
            }

            CurveByPoints curve = m_familyCreator.NewCurveByPoints(ptArr);

            curve.Visible = false;

            //创建放样平面并加入参照数组中
            int step = 8;//取step个点进行拟合
            ReferenceArrayArray refArr = new ReferenceArrayArray();

            for (int i = 0; i <= step; i++)
            {
                int position = i * (ptCount - 1) / step;

                //取起点截面及第二个截面作为参照平面
                if (i == 0)
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), ptArr.get_Item((i + 1) * (ptCount - 1) / step), (curve.GeometryCurve as HermiteSpline).Tangents[position], (curve.GeometryCurve as HermiteSpline).Tangents[((i + 1) * (ptCount - 1) / step)]));
                }
                //取终点截面及倒数第二个截面作为参照平面
                else if (i == step)
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), ptArr.get_Item((i - 1) * (ptCount - 1) / step), (curve.GeometryCurve as HermiteSpline).Tangents[position], (curve.GeometryCurve as HermiteSpline).Tangents[((i - 1) * (ptCount - 1) / step)]));
                }
                else
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), (curve.GeometryCurve as HermiteSpline).Tangents[position]));
                }
            }

            //创建放样实体
            m_familyCreator.NewLoftForm(true, refArr);
        }