I've read several of the Bezier curve posts & questions, but can't get my head around the maths or what I need to do to achieve what I'm after. I have an enclosed shape described by a poly-Bezier curve (actually I have several of these different shapes). Each segment of the bezier curve has a start-point, start-point-control-point, end-point, and end-point-control point. The end-point of one curve becomes the start point of the adjacent curve & the end-point of the final (nth) curve is the start point of the first curve. The curve is in 2D space. I have each of the points & control-points for the curve-shape in C# arrays (or lists).
I have a moving game object & want to test whether the object 'hits' (or is inside of) the curve-shape. My coordinates are in 2D space, so a test if point XY lies on or inside a nth-order Bezier curve that describes a closed shape. I was hoping to use C# .NET4 system.drawing.drawing2D dll funtionality.
// ....
using System.Drawing.Drawing2D;
using System.Drawing;
List<GraphicsPath> Forests = new List<GraphicsPath>();
List<Point> points = new List<Point>();
System.Drawing.Drawing2D.GraphicsPath forest = new System.Drawing.Drawing2D.GraphicsPath();
// populate the forest shape (poly-bezier curve)
int i = 0;
while (i <= (points.Count - 4))
{
System.Drawing.PointF p1 = new System.Drawing.PointF((float)points[i].x, (float)points[i].y);
System.Drawing.PointF cp1 = new System.Drawing.PointF((float)points[i + 1].x, (float)points[i + 1].y);
System.Drawing.PointF cp2 = new System.Drawing.PointF((float)points[i + 2].x, (float)points[i + 2].y);
System.Drawing.PointF p2 = new System.Drawing.PointF((float)points[i + 3].x, (float)points[i + 3].y);
forest.AddBezier(p1, cp1, cp2, p2);
i += 4;
}
// TODO: last point of last cubic spline mus join
// first point of spline
Forests.Add(forest);
// .....
// the hit-test
System.Drawing.PointF ObjectPos =
new System.Drawing.PointF((float)aircrafts[i].Pos().x, (float)aircrafts[i].Pos().y);
for (int j = 0; j < Forests.Count; j++)
{
if (Forests[j].IsVisible(ObjectPos))
{ // object position is 'inside' the forest
// do hit collision struff
}
}