tags:

views:

19

answers:

0

As an example imagine you have a rectangular clock. The hand is made of a filled triangle with a border. The border is drawn with a gdi+ pen and the thickness can vary from 1 upwards.
The problem is, the hand should always be within the bounds of the clock face. Using pen Alignment.Inset solves this problem but, because it renders terribly, it's not an option.

To ensure the hand is within the bounds of the clock, I find the intersection point on the border based on the angle. I then rotate the 2 points at the base of the hand by the same angle and join the points up to form a triangle.

Now, this ensures the point is on the border based on a 1 pixel line, but when rendered with a thicker line, it bleeds over the edge. To account for this, I did some basic trig to predict how long the line would be after rendering, based on the pen thickness, and then reduced the clock border bounds before finding the intersection point.
This helped, but was not accurate enough. I must be missing something about how exactly borders are rendered in gdi+ based on the pen thickness. If anyone has any knowledge then please let me know. If anyone thinks its a waste of time to even attempt to account for it then, again, let me know and save me a day.

ETA: Below is an example screenshot that renders the hand for a pen width larger that 1. Ignore the circle, and imagine the two lines extend to form a triangle at the centre of the circle. I need a way to predict the length of the part that extends beyond the border, based on the pen size, angle and clock size, so that I can reduce the hand size first.

alt text