Drawing a Pentagon Polygon in XAML


Posted on October 01, 2016

I found myself needing to draw a pentagon in XAML and couldn't find the x and y coordinates for a pentagon polygon.
It wasn't exactly straight forward to work out so I thought i'd share my findings.

Oddly, I was unable to find some existing sample coordinates online, however I stumbed upon the formula for calculating them here.

http://mathworld.wolfram.com/Pentagon.html

Pentagon x,y coordinates

Pentagon x,y coordinate formula

But weirdly it doesn't seem to actually show the resulting coordinates in the maths equations, so I worked them out myself.

Pentagon coordinate calculation

0,1 0.95,0.309 0.588,-0.809 -0.588,-0.809 -0.95,0.309

However, if you put those coordinates into a XAML polygon control, you'll get an upside down polygon. So you'll need to reverse all the Y coordinates, making negative positive and positive negative.

0,-1 0.95,-0.309 0.588,0.809 -0.588,0.809 -0.95,-0.309

The resulting xaml is below.

Pentagon XAML

Which gives a resulting pentagon that looks like this.

Resulting Pentagon

Ignore some of the lines in the screenshot, they are because I put the polygon in a Viewbox element.