Solved

Sector in Circle - pie-shaped region bounded by an arc and an angle

Posted on 2010-09-13
7
5,344 Views
Last Modified: 2012-05-10
I have a static image containing a circle
Triangle size needs to always be the same area (should make it easy)
Triangle could be placed in different region of circle,
Triangle will always be pointed to the center
I need something similiar to this:

http://www.worsleyschool.net/science/files/sector/calculations.html

How do I draw a triangle region inside of a circle.  

0
Comment
Question by:Padre_Corleone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 500 total points
ID: 33669034
Make yourself some pie!...
http://msdn.microsoft.com/en-us/library/hhfwf6kx.aspx

Example:
Public Class Form1

    Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        PictureBox1.Image = DrawPie(numDiameter.Value, numStart.Value, numSweep.Value, Color.Red, Color.Yellow, Color.Black)
    End Sub

    Private Sub num_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numStart.ValueChanged, numSweep.ValueChanged, numDiameter.ValueChanged
        If Me.IsHandleCreated Then
            PictureBox1.Image = DrawPie(numDiameter.Value, numStart.Value, numSweep.Value, Color.Red, Color.Yellow, Color.Black)
        End If
    End Sub

    Private Function DrawPie(ByVal diameter As Integer, ByVal startAngle As Integer, ByVal sweepAnalge As Integer, ByVal pieColor As Color, ByVal sliceColor As Color, ByVal backColor As Color) As Bitmap
        Dim bmp As New Bitmap(diameter, diameter)
        Using G As Graphics = Graphics.FromImage(bmp)
            G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
            G.Clear(backColor)
            Using pieBrush As New SolidBrush(pieColor)
                G.FillEllipse(pieBrush, 0, 0, bmp.Width - 1, bmp.Height - 1)
            End Using
            Using sliceBrush As New SolidBrush(sliceColor)
                G.FillPie(sliceBrush, 0, 0, bmp.Width - 1, bmp.Height - 1, startAngle, sweepAnalge)
            End Using
        End Using
        Return bmp
    End Function

End Class

Open in new window

PieSlice.jpg
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 33669223
This look very very good, thanks!

My only concern is "I have a static image containing a circle"(from my first comment) I have to use a very specific image file that contains a circle as the template that contain some items including some lines... so i would need to incorporate this example to an existing image already available.

The best way i can discribe my image template is this: (found on the internet):

http://www.gordonsgallery.net/wp-content/uploads/blank-wheel.jpg  (please ignore the big black center dot)

Basically i will have 12 sections divided just like the url provided.

Please let me know if you need further information.

Thanks.

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33669269
You need to figure out where the center of that circle is on your static image and start a 1x1 rectangle there:

    Dim rc As New Rectangle(CenterX, CenterY, 1, 1)

Next inflate the rectangle by the radius in pixels:

    rc.Inflate(radius, radius)

Now you can use "rc" with FillEllipse() and FillPie()...they both have overloaded methods that accept a rectangle isntead of individual parameters.

Take a look a the documentation to understand how the start and sweep angles work.

You'll just have to play with it until it looks right!  =)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 33669274
Oh...you can start with the static image like this:

    Dim bmp As New Bitmap("c:\some\path\staticImage.jpg")

Then the rest of the code follows but you don't need the Clear() call anymore:

    ' G.Clear(backColor) <--- get rid of this since we have the static image in the background
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 33673767
Sounds like a plan, will give this a try and will keep you posted on progress.  Thanks!
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34026556
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Send SMS from vb.net desktop app 30 46
SQL Server Serialization error 8 43
.NET Redemption/Outlook Examples 3 26
VB.NET Parsing UDP Bytes 15 31
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question