Esempio n. 1
0
        private IEnumerable <PdfPathCommand> GetCommands(double theta, double startAngle)
        {
            if (theta <= 0.0)
            {
                yield break;
            }

            // from http://www.tinaja.com/glib/bezcirc2.pdf
            var x0 = Math.Cos(theta * 0.5);
            var y0 = -Math.Sin(theta * 0.5);

            var x3 = x0;
            var y3 = -y0;

            var x1 = (4.0 - x0) / 3.0;
            var y1 = ((1.0 - x0) * (3.0 - x0)) / (3.0 * y0);

            var x2 = x1;
            var y2 = -y1;

            var p0 = new PdfPoint(PdfMeasurement.Points(x0), PdfMeasurement.Points(y0));
            var p1 = new PdfPoint(PdfMeasurement.Points(x1), PdfMeasurement.Points(y1));
            var p2 = new PdfPoint(PdfMeasurement.Points(x2), PdfMeasurement.Points(y2));
            var p3 = new PdfPoint(PdfMeasurement.Points(x3), PdfMeasurement.Points(y3));

            // now rotate points by (theta / 2) + startAngle
            var rotTheta = theta * 0.5 + startAngle;

            p0 = p0.RotateAboutOrigin(rotTheta);
            p1 = p1.RotateAboutOrigin(rotTheta);
            p2 = p2.RotateAboutOrigin(rotTheta);
            p3 = p3.RotateAboutOrigin(rotTheta);

            // multiply by the radius
            p0 = new PdfPoint(p0.X * RadiusX, p0.Y * RadiusY);
            p1 = new PdfPoint(p1.X * RadiusX, p1.Y * RadiusY);
            p2 = new PdfPoint(p2.X * RadiusX, p2.Y * RadiusY);
            p3 = new PdfPoint(p3.X * RadiusX, p3.Y * RadiusY);

            // do final rotation
            p0 = p0.RotateAboutOrigin(RotationAngle);
            p1 = p1.RotateAboutOrigin(RotationAngle);
            p2 = p2.RotateAboutOrigin(RotationAngle);
            p3 = p3.RotateAboutOrigin(RotationAngle);

            // offset for the center
            p0 += Center;
            p1 += Center;
            p2 += Center;
            p3 += Center;

            yield return(new PdfPathMoveTo(p0));

            yield return(new PdfCubicBezier(p1, p2, p3));
        }