Hi
I am trying to plot a series of shapes in a circular fashion. All shapes
are evenly spaced with lines going between each shape. At present, all
shapes are the same size so I can easily plot the shapes evenly around a
circle. As I add more shapes, I just increase the radius of the circle.
I'm calculating the radius as follows:
Dim m As Single = 20.39285714
Dim x As Single = Me.Flowchart1.Shapes.Count
Dim c As Single = 55.52380952
radius = (m * x) + c
I am then plotting the shapes using the following code:
'get center point
Dim centerPoint As New PointF(Me.Flowchart1.Width / 2,
Me.Flowchart1.Height / 2)
'get 360/shapes.count
Dim angle As New Single
angle = 360 / Me.Flowchart1.Shapes.Count
Dim i As New Integer = 1
For Each tmpShape As Shape In Me.Flowchart1.Shapes.Values
'move shape using ( (angle*i)-angle )
Dim calculatedPoint As New PointF
Dim newPoint As New PointF
calculatedPoint = LocateByAngleInt(centerPoint, ((angle *
i) - angle) - 90, radius)
'adjust the point to accommodate the size of the shape
newPoint = New PointF(calculatedPoint.X - tmpShape.Width /
2, calculatedPoint.Y - tmpShape.Height / 2)
If Me.Flowchart1.Shapes.Contains(i.ToString) Then
CType(Me.Flowchart1.Shapes(i.ToString), Shape).Location
= newPoint
End If
i = i + 1
Next
Here's some helper functions I'm using:
Private Function LocateByAngleInt(ByVal Location As PointF, ByVal
Angle As Single, ByVal Radius As Single) As PointF
Dim objPoint As Drawing.PointF
Dim dblRadians As Double
dblRadians = DegreesToRadians(Angle)
objPoint.X = Location.X + CSng(Radius * Math.Cos(dblRadians))
objPoint.Y = Location.Y + CSng(Radius * Math.Sin(dblRadians))
Return objPoint
End Function
Private Function DegreesToRadians(ByVal Degrees As Single) As Double
Return Degrees * Math.PI / 180
End Function
The easy part about the above solution is that I can simply divide 360 by
the number of shapes I have to give me the spacing between each.
What I want to do is allow for the shapes to be resized vertically and then
adjust the circle as necessary whilst keeping spacing between shapes the
same. I have uploaded some crude diagrams of how I would like this to work.
(http://www.bwbfc.com/math/circle.html) If all the shapes are the same
height then the spacing between the shapes will be equal. When a shapes
height increases as shown in the second diagram, I want all shapes to
shuffle round to accommodate the new height. Therefore, using the concept
of a clock face, shapes nearer 3 and 9 o'clock will take up more of the
circumference whereas shapes nearer 12 and 6 o'clock will take up no more
space should their height increase.
So my question is, how can I calculate the location to plot each shape after
taking into consideration their height and position around the circle?
Again, the distance between all shapes should be the same. I figured it
would be easy to work out how much circumference the lines would take. The
nightmare begins when I start to consider that depending on which point of
the circle a shape falls, dictates how much circumference it requires.
More over, this needs to be fast therefore a linear programming approach
would probably be too expensive.
Is this even possible?!? Please let me know if more information or
explanation is required.
Kind regards, Carl Gilbert