Exemple #1
0
        public override Entity2D Copy()
        {
            var cir =
                new CircleArc2D(
                    Center,
                    Radius,
                    StartAngle,
                    EndAngle);

            cir.LayerName = LayerName;
            return(cir);
        }
Exemple #2
0
        public CircleArc2D(Point2D pt1, Point2D pt2, Point2D pt3, bool isWholeCircle)
        {
            if (isWholeCircle)
            {
                var xy1 = Math.Pow(pt1.X, 2) + Math.Pow(pt1.Y, 2);
                var xy2 = xy1 - Math.Pow(pt3.X, 2) - Math.Pow(pt3.Y, 2);
                var xy3 = xy1 - Math.Pow(pt2.X, 2) - Math.Pow(pt2.Y, 2);
                xy1 = (pt1.X - pt2.X) * (pt1.Y - pt3.Y) - (pt1.X - pt3.X) * (pt1.Y - pt2.Y);
                if (GeoUtils.Equals(xy1, 0))
                {
                    throw new Exception("无法创建圆!");
                }

                Center =
                    new Point2D(
                        (xy3 * (pt1.Y - pt3.Y) - xy2 * (pt1.Y - pt2.Y)) / (2 * xy1),
                        (xy2 * (pt1.X - pt2.X) - xy3 * (pt1.X - pt3.X)) / (2 * xy1));

                Radius = (pt1 - Center).Length;
                if (GeoUtils.Equals(Radius, 0))
                {
                    throw new Exception("半径为零!");
                }

                StartAngle = Angle.Zero;
                EndAngle   = Angle.Degree360;
            }
            else
            {
                CircleArc2D cir = new CircleArc2D(pt1, pt2, pt3, true);
                Center = cir.Center;
                Radius = cir.Radius;

                IsClockWise =
                    Vector2D.IsClockWise(
                        pt1 - cir.Center,
                        pt2 - cir.Center,
                        pt3 - cir.Center);
            }
        }
Exemple #3
0
        public override IEnumerable <int> Draw(Graphics g, Pen pen, GraphicsPath path)
        {
            GraphicsPath fill = new GraphicsPath();

            for (int i = 0; i < SegmentCount; i++)
            {
                var curve = GetSegmentAt(i);
                var ver   = Vertexs[i];
                if (ver.StartWidth == 0 && ver.EndWidth == 0)
                {
                    curve.DrawTo(g, path);
                }
                else
                {
                    var w1    = ver.StartWidth / 2;
                    var w2    = ver.EndWidth / 2;
                    var cpath = new GraphicsPath();
                    if (curve is LineSegment2D)
                    {
                        var line = curve as LineSegment2D;
                        var vec  = line.EndPoint - line.StartPoint;
                        vec = vec.UnitVector.RotateBy(Angle.Degree90);
                        var pts =
                            new PointF[]
                        {
                            line.StartPoint + vec * w1,
                            line.EndPoint + vec * w2,
                            line.EndPoint - vec * w2,
                            line.StartPoint - vec * w1
                        };
                        cpath.AddLines(pts);
                        cpath.CloseFigure();
                    }
                    else
                    {
                        var arc  = curve as CircleArc2D;
                        var vec1 = new Vector2D(w1, arc.StartAngle);
                        var pt   = arc.GetPointAtParam(arc.EndParam / 2);
                        var vec2 = (pt - arc.Center).UnitVector * (w1 + w2) / 2;
                        var vec3 = new Vector2D(w2, arc.EndAngle);
                        var pts  =
                            new Point2D[]
                        {
                            arc.StartPoint + vec1,
                            pt + vec2,
                            arc.EndPoint + vec3,
                            arc.EndPoint - vec3,
                            pt - vec2,
                            arc.StartPoint - vec1
                        };

                        var arc1  = new CircleArc2D(pts[0], pts[1], pts[2]);
                        var line1 = new LineSegment2D(pts[2], pts[3]);
                        var arc2  = new CircleArc2D(pts[3], pts[4], pts[5]);
                        var line2 = new LineSegment2D(pts[5], pts[0]);
                        arc1.DrawTo(g, cpath);
                        line1.DrawTo(g, cpath);
                        arc2.DrawTo(g, cpath);
                        line2.DrawTo(g, cpath);
                    }
                    fill.AddPath(cpath, false);
                    path.AddPath(cpath, false);
                    path.StartFigure();
                }
            }
            yield return(0);

            g.FillPath(pen.Brush, fill);
            yield break;
        }