Silverlight Polygon - Push Inside?
I have a Polygon (Hex for a board game) in Silverlight, something like:
public class GridHex : IGridShape
{
.....
public IList<Point> Points { get; protected set; }
public bool Intersects(Point point) { ... }
}
I would like to say
if(myHex.Intersects(clickedPoint)) { ... }
However, I don't know which algorithm to use in the Intersects method - I currently use an inner "bounding box" inside each hexagon to determine if a point is in it, but there must be an algorithm to figure it out outside? I know the coordinates for 6 points of each hexagon.
I thought I could create a Silverlight Polygon and do some impact testing? Of course this would be quite memory intensive (I would repeat a large number of hexes to see which Heck the mouse click hit inside ...) so it would be better to use a mathematical formula to work out if the point is inside a Hex ....
source to share
Have you looked at built-in support using FindElementsInHostCoordinates ? I would have expected this to be faster as it is probably using unmanaged code.
Here's a sample that works with vector shapes, supported in Silverlight 2.
And here's an updated sample that uses WriteableBitmap to expand support for bump and bitmap testing.
source to share