PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 2:16 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Thu Jul 08, 2010 10:40 pm 
Offline

Joined: Mon Mar 08, 2010 5:46 pm
Posts: 5
I am trying to create a 3D pie wedge (If you have a method that will do this, please let me know). I am using the XGraphics.DrawPie() method to draw the top piece of the wedge, and to ensure that I can determine the endpoints, I am trying to manually outline it. Below is a simple routine to show you what I am doing. I'm just not seeing what I'm doing wrong. Any help would be greatly appreciated.

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using PdfSharp;
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Drawing.Layout;
using PdfSharp.Drawing.BarCodes;

namespace Sample_PDF
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument document = new PdfDocument();
            PdfPage page = document.AddPage();
            page.Width = XUnit.FromInch(5);
            page.Height = XUnit.FromInch(5);
            XGraphics gfx = XGraphics.FromPdfPage(page);
            XPen pen = new XPen(XBrushes.Black.Color, 1);

            XRect rect = new XRect(10, 10, (page.Width / 2) - 20, (page.Height / 4) - 20);
            gfx.DrawPie(XBrushes.Cyan, rect, 0, 25);

            XPoint p1 = PointFromEllipse(rect, 0);
            XPoint p2 = PointFromEllipse(rect, 25);
            XGraphicsPath path = new XGraphicsPath();
            path.AddLine(rect.Center, p1);
            path.AddArc(rect, 0, 25);
            path.AddLine(p2, rect.Center);

            gfx.DrawPath(pen, path);
            document.Save("c:\\TestPDF.pdf");
        }

        private static XPoint PointFromEllipse(XRect bounds, double degrees)
        {
            double a = bounds.Width / 2.0;
            double b = bounds.Height / 2.0;
            double rad = (Math.PI / 180.0) * degrees;

            XPoint ptCenter = bounds.Center;

            double x = bounds.Center.X + (a * Math.Cos(rad));
            double y = bounds.Center.Y + (b * Math.Sin(rad));

            return new XPoint(x, y);
        }
    }
}


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 427 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group