Solved

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

Posted on 2010-09-13
5,327 Views
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
• 3
• 2

LVL 85

Assisted Solution

Mike Tomlinson earned 500 total points
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
``````
PieSlice.jpg
0

LVL 7

Author Comment

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):

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

Please let me know if you need further information.

Thanks.

0

LVL 85

Expert Comment

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:

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

LVL 85

Accepted Solution

Mike Tomlinson earned 500 total points

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

Sounds like a plan, will give this a try and will keep you posted on progress.  Thanks!
0

LVL 29

Expert Comment

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!