コード例 #1
0
        /// <summary>
        /// 将Curve用交点打断,分解成最小的单元
        /// </summary>
        /// <param name="locationLines"></param>
        /// <returns>返回分解后的curve</returns>
        public void DecomposeCurves(List <Line3D> regionEdges, List <Line3D> decomposLines)
        {
            foreach (Line3D pw1 in regionEdges)
            {
                //获取一条线
                List <Vector3D> intersects = new List <Vector3D>();
                //和所有的线相交计算,获取交点的位置
                foreach (Line3D pw2 in regionEdges)
                {
                    Vector3D intersect = null;
                    intersect = pw1.Intersect(pw2);
                    if (intersect != null)
                    {
                        if (!IsAtCurveEnd(intersect, pw1))
                        {
                            intersects.Add(intersect);
                        }
                    }
                }
                if (intersects.Count > 0)
                {
                    //获取所有的交点,对交点进行排序
                    intersects.Add(pw1.Start);
                    intersects.Add(pw1.End);
                    intersects = intersects.OrderBy(t => t.Distance(pw1.Start)).ToList();
                    intersects = intersects.Distinct().ToList();
                    for (int i = 1; i < intersects.Count; i++)
                    {
                        Line3D baseLine = Line3D.Create(intersects[i - 1], intersects[i]);

                        decomposLines.Add(baseLine);
                    }
                }
                else
                {
                    //不和任何线中心相交,则添加自己
                    decomposLines.Add(pw1);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// 绘制当前直线
 /// </summary>
 public override void Update()
 {
     if (Start != null && end != null)
     {
         //对直线矩形偏移
         Line3D subline3d       = Line3D.Create(Vector3D.Create(Start.X, Start.Y, 0), Vector3D.Create(end.X, end.Y, 0));
         var    offsetDirection = subline3d.Direction.Cross(Vector3D.BasisZ);
         //获取偏移量
         var offsetdir = Vector2D.Create(offsetDirection.X, offsetDirection.Y) * KernelProperty.PixToMM(SublineOffset);
         //添加偏移
         var             offline = Line2D.Create(Start, end).Offset(offsetdir);
         List <Vector2D> points  = new List <Vector2D>();
         this.DashStyle      = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);
         this.PenColor       = Colors.DeepSkyBlue;
         this.Pen.EndLineCap = PenLineCap.Triangle;
         points.Add(Start);
         points.Add(offline.Start);
         points.Add(offline.End);
         points.Add(end);
         this.Draw(points);
     }
 }
コード例 #3
0
        /// <summary>
        /// 将三维线段打断成最小的单元
        /// </summary>
        /// <param name="lines"></param>
        /// <returns></returns>
        public List <Line3D> Decompose(List <Line3D> lines)
        {
            //获取原始的线集合
            List <Line3D> newLines = new List <Line3D>(lines);

            //获取线和分割点的字典表
            Dictionary <Line3D, List <Vector3D> > lineDIC = new Dictionary <Line3D, List <Vector3D> >();

            //循环所有的线的相交关系,得到字典表
            for (int i = 0; i < newLines.Count; i++)
            {
                for (int j = i; j < newLines.Count; j++)
                {
                    Vector3D IntersectP = newLines[i].Intersect(newLines[j]);

                    if (IntersectP != null)
                    {
                        if (!IntersectP.IsEndPoint(newLines[i]))
                        {
                            if (lineDIC[newLines[i]] == null)
                            {
                                lineDIC.Add(newLines[i], new List <Vector3D>()
                                {
                                    IntersectP
                                });
                            }
                            else
                            {
                                lineDIC[newLines[i]].Add(IntersectP);
                            }
                        }
                        if (!IntersectP.IsEndPoint(newLines[j]))
                        {
                            if (lineDIC[newLines[j]] == null)
                            {
                                lineDIC.Add(newLines[j], new List <Vector3D>()
                                {
                                    IntersectP
                                });
                            }
                            else
                            {
                                lineDIC[newLines[j]].Add(IntersectP);
                            }
                        }
                    }
                }
            }
            //变化所有线
            foreach (KeyValuePair <Line3D, List <Vector3D> > vetsInLine in lineDIC)
            {
                //移除原来线段
                newLines.Remove(vetsInLine.Key);

                vetsInLine.Value.Add(vetsInLine.Key.Start);
                vetsInLine.Value.Add(vetsInLine.Key.End);
                ///去掉重复的点
                var vets = vetsInLine.Value.Distinct <Vector3D>(new Vector3DEqualityComparer());


                //通过比较距离
                var orderVets = vets.OrderBy(x => x.Distance(vetsInLine.Key.Start));


                var count = orderVets.Count();
                for (int i = 0; i < count - 1; i++)
                {
                    newLines.Add(Line3D.Create(orderVets.ElementAt(i), orderVets.ElementAt(i + 1)));
                }
            }
            return(newLines);
        }
コード例 #4
0
        /// <summary>
        /// 更新当前图形
        /// </summary>
        /// <param name="ms"></param>
        public override void Update()
        {
            List <Vector2D> points = new List <Vector2D>();

            if (Central != null)
            {
                if (this.central.IntersectPointStyle == 0)
                {
                    var v1 = new Vector2D(central.Point.X - 5 * KernelProperty.PixelToSize, central.Point.Y - 5 * KernelProperty.PixelToSize);
                    var v2 = new Vector2D(central.Point.X + 5 * KernelProperty.PixelToSize, central.Point.Y - 5 * KernelProperty.PixelToSize);
                    var v3 = new Vector2D(central.Point.X + 5 * KernelProperty.PixelToSize, central.Point.Y + 5 * KernelProperty.PixelToSize);
                    var v4 = new Vector2D(central.Point.X - 5 * KernelProperty.PixelToSize, central.Point.Y + 5 * KernelProperty.PixelToSize);
                    points.Add(v1);
                    points.Add(v2);
                    points.Add(v3);
                    points.Add(v4);
                    points.Add(v1);
                    base.Draw(points);
                }
                else if (this.central.IntersectPointStyle == 1)
                {
                    if (this.central.Line != null)
                    {
                        var Start  = this.central.Line.Start;
                        var End    = this.central.Line.End;
                        var Middle = central.Point;
                        //对直线矩形偏移
                        Line3D subline3d       = Line3D.Create(Vector3D.Create(Start.X, Start.Y, 0), Vector3D.Create(End.X, End.Y, 0));
                        var    offsetDirection = subline3d.Direction.Cross(Vector3D.BasisZ);
                        //获取偏移量
                        var offsetdir = Vector2D.Create(offsetDirection.X, offsetDirection.Y) * KernelProperty.PixToMM(KernelProperty.SublineOffset);

                        //冻结画笔,这样能加快绘图速度
                        DrawingContext dc = this.RenderOpen();
                        Pen.Freeze();
                        this.DashStyle      = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);
                        this.PenColor       = Colors.DeepSkyBlue;
                        this.Pen.EndLineCap = PenLineCap.Triangle;
                        var v1 = Start;
                        //添加偏移
                        var v2 = Start.Offset(offsetdir);
                        //绘制第一个线
                        dc.DrawLine(Pen, KernelProperty.MMToPix(v1), KernelProperty.MMToPix(v2));
                        var v3 = Middle.Offset(offsetdir);
                        //第二个线
                        dc.DrawLine(Pen, KernelProperty.MMToPix(v2), KernelProperty.MMToPix(v3));
                        //绘制文本
                        this.SetText(dc, Line2D.Create(v2, v3));
                        //绘制三个线竖线
                        dc.DrawLine(Pen, KernelProperty.MMToPix(v3), KernelProperty.MMToPix(Middle));

                        var v4 = End.Offset(offsetdir);
                        //绘制第四个线
                        dc.DrawLine(Pen, KernelProperty.MMToPix(v3), KernelProperty.MMToPix(v4));
                        this.SetText(dc, Line2D.Create(v3, v4));
                        //绘制第五个线
                        dc.DrawLine(Pen, KernelProperty.MMToPix(v4), KernelProperty.MMToPix(End));


                        //绘制偏移的线

                        var v5 = new Vector2D(central.Point.X - 5 * KernelProperty.PixelToSize, central.Point.Y - 5 * KernelProperty.PixelToSize);
                        var v6 = new Vector2D(central.Point.X + 5 * KernelProperty.PixelToSize, central.Point.Y - 5 * KernelProperty.PixelToSize);
                        var v7 = new Vector2D(central.Point.X - 5 * KernelProperty.PixelToSize, central.Point.Y + 5 * KernelProperty.PixelToSize);
                        var v8 = new Vector2D(central.Point.X + 5 * KernelProperty.PixelToSize, central.Point.Y + 5 * KernelProperty.PixelToSize);
                        dc.DrawLine(Pen, KernelProperty.MMToPix(v5), KernelProperty.MMToPix(v6));
                        dc.DrawLine(Pen, KernelProperty.MMToPix(v6), KernelProperty.MMToPix(v7));
                        dc.DrawLine(Pen, KernelProperty.MMToPix(v7), KernelProperty.MMToPix(v8));
                        dc.DrawLine(Pen, KernelProperty.MMToPix(v8), KernelProperty.MMToPix(v5));
                        dc.Close();
                    }
                }
                else if (this.central.IntersectPointStyle == 2)
                {
                    //冻结画笔,这样能加快绘图速度
                    DrawingContext dc = this.RenderOpen();
                    Pen.Freeze();
                    this.DashStyle      = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);
                    this.PenColor       = Colors.DeepSkyBlue;
                    this.Pen.EndLineCap = PenLineCap.Triangle;
                    if (this.central.Refences != null)
                    {
                        this.central.Refences.ForEach(x => {
                            dc.DrawLine(Pen, KernelProperty.MMToPix(x.Start), KernelProperty.MMToPix(x.End));
                        });
                    }

                    dc.Close();
                }
                else if (this.central.IntersectPointStyle == 3)
                {
                    DrawingContext dc = this.RenderOpen();
                    Pen.Freeze();
                }
            }
        }
コード例 #5
0
ファイル: TransformUtil.cs プロジェクト: AlbertMin/AlbertCAD
        /// <summary>
        /// 将二维线段,向上偏移到三维空间
        /// </summary>
        /// <param name="line2d"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public static Line3D Projection(Line2D line2d, double z)
        {
            Line3D line3d = Line3D.Create(Projection(line2d.Start, z), Projection(line2d.End, z));

            return(line3d);
        }
コード例 #6
0
ファイル: TransformUtil.cs プロジェクト: AlbertMin/AlbertCAD
        /// <summary>
        /// 进行投影转换操作
        /// </summary>
        /// <param name="line3D"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        public static Line3D Transform(Line3D line3D, Matrix4 m)
        {
            Line3D nline3D = Line3D.Create(m * line3D.Start, m * line3D.End);

            return(nline3D);
        }
コード例 #7
0
        /// <summary>
        /// 对指定的进行每个线段进行缩放,并且指定缩放的长度,传入的线,不能共线或者重叠,否则会出现错误
        /// </summary>
        /// <param name="nlist"></param>
        /// <returns></returns>
        public List <Line2D> Elastic2(List <Tuple <Line2D, Double> > nlist)
        {
            List <Line2D> lines = new List <Line2D>();

            //不处理变形的情况
            foreach (var tp in nlist)
            {
                if (tp.Item1.Length < tp.Item2)
                {
                    return(null);
                }
                else
                {
                    lines.Add(tp.Item1);
                }
            }

            //获取当前线段的顺时针排序
            List <Line2D> sortLines = GraphicAlgorithm.Sort(lines, null, 1);

            List <Line2D> moveLines = new List <Line2D>();

            ///开始线段偏移
            for (int i = 0; i < sortLines.Count; i++)
            {
                var v1      = Vector3D.Create(sortLines[i].Start.X, sortLines[i].Start.Y, 0);
                var v2      = Vector3D.Create(sortLines[i].End.X, sortLines[i].End.Y, 0);
                var l1      = Line3D.Create(v1, v2);
                var moveDir = l1.Direction.Cross(Vector3D.BasisZ);
                var tp      = nlist.Find(x => x.Item1.IsAlmostEqualTo(sortLines[i]));
                var nl      = l1.Offset(tp.Item2, -moveDir);
                moveLines.Add(TransformUtil.Projection(nl));
            }
            List <Vector2D> NPList = new List <Vector2D>();

            //开始循环所有的线段
            for (int i = 0; i < moveLines.Count; i++)
            {
                Vector2D v = null;
                if (i == 0)
                {
                    v = moveLines[0].IntersectStraightLine(moveLines[moveLines.Count - 1]);
                }
                else
                {
                    v = moveLines[i].IntersectStraightLine(moveLines[i - 1]);
                }

                if (v == null)
                {
                    return(null);
                }
                else
                {
                    NPList.Add(v);
                }
            }

            List <Line2D> nliset = new List <Line2D>();

            //生成新的多边形
            for (int i = 0; i < NPList.Count; i++)
            {
                if (i == 0)
                {
                    nliset.Add(Line2D.Create(NPList[NPList.Count - 1], NPList[i]));
                }
                else
                {
                    nliset.Add(Line2D.Create(NPList[i - 1], NPList[i]));
                }
            }

            return(nliset);
        }
コード例 #8
0
        /// <summary>
        /// 更新当前图形
        /// </summary>
        /// <param name="ms"></param>
        public override void Update()
        {
            if (Start != null && End != null)
            {
                List <Vector2D> fillPoints = new List <Vector2D>();


                var      halfFB    = 300 / 2;
                var      start3D   = new Albert.Geometry.Primitives.Vector3D(Start.X, Start.Y, 0);
                var      end3D     = new Albert.Geometry.Primitives.Vector3D(End.X, End.Y, 0);
                Vector3D lineDir   = Line3D.Create(end3D, start3D).Direction;
                Vector3D offsetDir = lineDir.Cross(new Vector3D(0, 0, 1)).Normalize();

                //偏移出上下点
                Vector3D offv1 = start3D + halfFB * offsetDir;
                Vector3D offv2 = start3D - halfFB * offsetDir;
                Vector3D offv3 = end3D - halfFB * offsetDir;
                Vector3D offv4 = end3D + halfFB * offsetDir;

                var HalfYYThinkness = 30 / 2;

                Vector3D v1 = offv1 + HalfYYThinkness * lineDir;
                Vector3D v2 = offv1 + HalfYYThinkness * -lineDir;

                Vector3D v3 = offv2 + HalfYYThinkness * lineDir;
                Vector3D v4 = offv2 + HalfYYThinkness * -lineDir;


                var HalfFBThinkness = 30 / 2;

                Vector3D v5 = v2 + (halfFB - HalfFBThinkness) * -offsetDir;
                Vector3D v6 = v4 + (halfFB - HalfFBThinkness) * offsetDir;



                Vector3D v7 = offv3 + HalfYYThinkness * -lineDir;
                Vector3D v8 = offv3 + HalfYYThinkness * lineDir;

                Vector3D v9  = offv4 + HalfYYThinkness * -lineDir;
                Vector3D v10 = offv4 + HalfYYThinkness * lineDir;


                Vector3D v12 = v8 + (halfFB - HalfFBThinkness) * offsetDir;
                Vector3D v11 = v10 + (halfFB - HalfFBThinkness) * -offsetDir;


                fillPoints.Add(TransformUtil.Projection(v1));
                fillPoints.Add(TransformUtil.Projection(v2));
                fillPoints.Add(TransformUtil.Projection(v5));
                fillPoints.Add(TransformUtil.Projection(v11));
                fillPoints.Add(TransformUtil.Projection(v8));
                fillPoints.Add(TransformUtil.Projection(v7));
                fillPoints.Add(TransformUtil.Projection(v9));
                fillPoints.Add(TransformUtil.Projection(v10));
                fillPoints.Add(TransformUtil.Projection(v12));
                fillPoints.Add(TransformUtil.Projection(v6));
                fillPoints.Add(TransformUtil.Projection(v4));
                fillPoints.Add(TransformUtil.Projection(v3));
                this.DrawFill(fillPoints);
            }
        }