예제 #1
0
        Point2D?IntersectWith(LineSegment2D other)
        {
            var d0 = Delta;
            var d1 = other.Delta;

            if (!d0.IsParallelTo(d1))
            {
                var    e = other.StartPoint - StartPoint;
                double s = e.CrossProduct(d1) / d0.CrossProduct(d1);
                return(StartPoint + d0 * s);
            }
            return(null);
        }
예제 #2
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;
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public static Matrix2D Mirror(LineSegment2D line)
 {
     return(Matrix2D.Mirror(line.StartPoint, line.EndPoint));
 }