docs-desktop
docs-desktop copied to clipboard
Correction to BuildRegularPolygon
Thanks for giving the BuildRegularPolygon code but to work correctly you should change the using block as follows:
using (StreamGeometryContext ctx = geometry.Open())
{
double step = 2 * Math.PI / Math.Max(numSides, 3);
Point cur = c;
double a = Math.PI * offsetDegree / 180.0;
for (int i = 0; i < numSides; i++, a += step)
{
cur.X = c.X + r * Math.Cos(a);
cur.Y = c.Y + r * Math.Sin(a);
if (i == 0)
{
ctx.BeginFigure(cur, true /* is filled */, true /* is closed */);
}
else
{
ctx.LineTo(cur, true /* is stroked */, false /* is smooth join */);
}
}
}
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 6ffa9b16-059c-9281-bcd6-79f29c67a067
- Version Independent ID: 2836c340-b97b-5e9c-7d95-b12984dd281b
- Content: How to: Create a Shape Using a StreamGeometry - WPF .NET Framework
- Content Source: dotnet-desktop-guide/framework/wpf/graphics-multimedia/how-to-create-a-shape-using-a-streamgeometry.md
- Product: dotnet-framework
- Technology: dotnet-wpf
- GitHub Login: @adegeo
- Microsoft Alias: adegeo
Thank you for opening this issue. I'll add it to the backlog. If you would like to contribute, you can submit a fix by editing the original article. Click on the Content Source link at the bottom of your original comment. To learn how to edit, see the Editing files in a repository article from GitHub.
Thanks again!