我已经阅读了几篇Bezier曲线帖子和问题,但无法理解数学或我需要做什么来实现我所追求的目标。我有一个由poly-Bezier曲线描述的封闭形状(实际上我有几个不同的形状)。贝塞尔曲线的每个段都有一个起点,起点控制点,终点和终点控制点。一条曲线的终点成为相邻曲线的起点。最终(第n)曲线的终点是第一条曲线的起点。曲线位于2D空间中。我有各自的要点和C#数组(或列表)中曲线形状的控制点。
我有一个移动的游戏对象&想测试对象是否“撞击”(或在曲线形状内)。我的坐标位于2D空间中,因此测试XY点是否位于描述闭合形状的n阶Bezier曲线上或内部。我希望使用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
}
}