Reputation: 240
I'm trying to place some icons equally on the upper half of a circle.
I managed to place them around a whole circle with the following formula/code
for(int i=0;i<numberOfItems;i++)
{
float x = (float)(center.X + radius * Math.Cos(2 * Math.PI * i / numberOfItems))-iconBmp.Width/2;
float y = (float)(center.Y + radius * Math.Sin(2 * Math.PI * i/ numberOfItems))-iconBmp.Height/2;
canvas.DrawBitmap(iconBmp, new SKPoint(x, y));
}
But I can't figure how to do it for just the upper half of the circle? Is there a formula for that as well? I have the feeling that the one I have for the whole circle just needs some adjustment to achieve that...but can't figure what.
Thank you already!
Upvotes: 0
Views: 368
Reputation: 843
This is more a math question than a programming question.
2pi radians = 360 degrees
So if you want all of the items shown, but the shape to be a half circle, then use:
Math.PI * i / numberOfItems
instead of 2 * Math.PI * i / numberOfItems
Also because screen coordinates start in the top-left corner. That will make it the bottom half of the circle with the first item on the right. If you want the top half of the circle with the first item on the left, then just add pi:
Math.PI + (Math.PI * i / numberOfItems)
Whole code:
for(int i=0;i<numberOfItems;i++)
{
float x = (float)(center.X + radius * Math.Cos(Math.PI + (Math.PI * i / numberOfItems)))-iconBmp.Width/2;
float y = (float)(center.Y + radius * Math.Sin(Math.PI + (Math.PI * i / numberOfItems)))-iconBmp.Height/2;
canvas.DrawBitmap(iconBmp, new SKPoint(x, y));
}
Upvotes: 3