示例#1
0
        public RoundCappedLine(Point point1, Point point2, double radius) : this()
        {
            Vector2 vector   = new Vector2(point2 - new Vector2(point1));
            Vector2 normVect = vector;

            normVect = normVect.Normalized;

            Point pt1a = point1 + radius * new Vector2(normVect.Y, -normVect.X);
            Point pt2a = pt1a + vector;
            Point pt1b = point1 + radius * new Vector2(-normVect.Y, normVect.X);
            Point pt2b = pt1b + vector;

            lineSegment1 = new LineSegment2(pt1a, pt2a);
            arcSegment1  = new ArcSegment2(point2, radius, pt2a, pt2b);
            lineSegment2 = new LineSegment2(pt2b, pt1b);
            arcSegment2  = new ArcSegment2(point1, radius, pt1b, pt1a);
        }
示例#2
0
        public RoundCappedPath(Point point1, Point point2, double radius1, double radius2)
            : this()
        {
            Point  c0 = point1;
            Point  c1 = point2;
            double r0 = radius1;
            double r1 = radius2;

            // Get vector from c1 to c0
            Vector2 vCenters = new Vector2(c0) - new Vector2(c1);

            // Get length and normalized version
            double d = vCenters.Length;

            vCenters = vCenters.Normalized;

            // Create focal point F extending from c0
            double e = d * r0 / (r1 - r0);
            Point  F = c0 + e * vCenters;

            // Find angle and length of right-triangle legs
            double alpha = 180 * Math.Asin(r0 / e) / Math.PI;
            double leg0  = Math.Sqrt(e * e - r0 * r0);
            double leg1  = Math.Sqrt((e + d) * (e + d) - r1 * r1);

            // Vectors of tangent lines
            Vector2 vRight = -vCenters.Rotate(alpha);
            Vector2 vLeft  = -vCenters.Rotate(-alpha);

            // Find tangent points
            Point t0R = F + leg0 * vRight;
            Point t0L = F + leg0 * vLeft;
            Point t1R = F + leg1 * vRight;
            Point t1L = F + leg1 * vLeft;

            lineSegment1 = new LineSegment2(t1R, t0R);
            arcSegment1  = new ArcSegment2(c0, r0, t0R, t0L);
            lineSegment2 = new LineSegment2(t0L, t1L);
            arcSegment2  = new ArcSegment2(c1, r1, t1L, t1R);
        }