示例#1
0
        public static double AroundLength(CadFigure fig)
        {
            if (fig == null)
            {
                return(0);
            }

            int cnt = fig.PointCount;

            if (cnt < 2)
            {
                return(0);
            }

            CadVertex p0;
            CadVertex p1;

            CadVertex pd;

            double d = 0;

            for (int i = 0; i < cnt - 1; i++)
            {
                p0 = fig.GetPointAt(i);
                p1 = fig.GetPointAt(i + 1);

                pd = p1 - p0;

                d += pd.Norm();
            }

            return(d);
        }
示例#2
0
 // 三角形の重心を求める
 public static Vector3d TriangleCentroid(CadFigure fig)
 {
     return(CadMath.TriangleCentroid(
                fig.GetPointAt(0).vector,
                fig.GetPointAt(1).vector,
                fig.GetPointAt(2).vector
                ));
 }
示例#3
0
 // 三角形の面積 3D対応
 public static double TriangleArea(CadFigure fig)
 {
     return(CadMath.TriangleArea(
                fig.GetPointAt(0).vector,
                fig.GetPointAt(1).vector,
                fig.GetPointAt(2).vector
                ));
 }
示例#4
0
        public override void Undo(CadObjectDB db)
        {
            CadLayer  layer = db.GetLayer(LayerID);
            CadFigure fig   = db.GetFigure(FigureID);

            if (fig == null)
            {
                return;
            }

            int idx = PointIndex;
            int i   = 0;

            if (mPointList == null)
            {
                mPointList = new VertexList();
            }

            mPointList.Clear();

            for (; i < InsertNum; i++)
            {
                mPointList.Add(fig.GetPointAt(idx + i));
            }

            fig.RemovePointsRange(idx, InsertNum);
        }
示例#5
0
        public static int InsertBezierHandle(CadFigure fig, int idx1, int idx2)
        {
            CadVertex a = fig.GetPointAt(idx1);
            CadVertex b = fig.GetPointAt(idx2);

            CadVertex hp1 = b - a;

            hp1 = hp1 / 3;
            hp1 = hp1 + a;

            CadVertex hp2 = a - b;

            hp2 = hp2 / 3;
            hp2 = hp2 + b;

            hp1.IsHandle = true;
            hp2.IsHandle = true;

            fig.InsertPointAt(idx1 + 1, hp1);
            fig.InsertPointAt(idx1 + 2, hp2);

            return(2);
        }
示例#6
0
        public static EditResult CutSegment(CadObjectDB db, MarkSegment seg, Vector3d p)
        {
            EditResult result = new EditResult();

            if (seg.Figure.Type != CadFigure.Types.POLY_LINES)
            {
                return(result);
            }

            CrossInfo ci = CadMath.PerpendicularCrossSeg(seg.pA.vector, seg.pB.vector, p);

            if (!ci.IsCross)
            {
                return(result);
            }

            CadFigure org = db.GetFigure(seg.FigureID);

            int a = Math.Min(seg.PtIndexA, seg.PtIndexB);
            int b = Math.Max(seg.PtIndexA, seg.PtIndexB);


            CadFigure fa = db.NewFigure(CadFigure.Types.POLY_LINES);
            CadFigure fb = db.NewFigure(CadFigure.Types.POLY_LINES);

            fa.AddPoints(org.PointList, 0, a + 1);
            fa.AddPoint(new CadVertex(ci.CrossPoint));

            fb.AddPoint(new CadVertex(ci.CrossPoint));
            fb.AddPoints(org.PointList, b);

            if (org.IsLoop)
            {
                fb.AddPoint(fa.GetPointAt(0));
            }

            result.AddList.Add(new EditResult.Item(seg.LayerID, fa));
            result.AddList.Add(new EditResult.Item(seg.LayerID, fb));
            result.RemoveList.Add(new EditResult.Item(org.LayerID, org));

            return(result);
        }