1

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
       }
    }
  • 1
    be precise in your description: do you have a single curve that represents a closed shape, of nth order, or do you have a poly-bezier, consisting of lots of joined-up bezier curves, but that you can conveniently *specify* as just a series of points? Are you using any predefined libraries? (if not, why not?). If it's for a game, visual collision is far more important than true mathematical collision, which cheaper approximations (polyhull, bounding box, etc) have you tried (with code) and why were they insufficient? These questions are annoying, but from scratch this is *a lot* of work. – Mike 'Pomax' Kamermans Feb 04 '16 at 18:33
  • I have a single bezier curve of nth-order that makes up a closed shape. Much like a polygon, but with curved edges instead of straight edges. Each segment of the bezier curve is a cubic curve with 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 (n-order) curve is the start point of the first curve. The curve is in 2D space, and is a series of 'joined' bezier curves. I was hoping to use C# .NET4 system.drawing.drawing2D dll funtionality. ie – user3602836 Feb 06 '16 at 02:27
  • `GraphicsPath forest = new GraphicsPath();` – user3602836 Feb 06 '16 at 02:27
  • `forest.AddBezier(p1, cp1, cp2, p2);if (Forests[j].IsVisible(MyPos));// do collission hit` – user3602836 Feb 06 '16 at 02:38
  • please add all that information to your question, don't put them in as comments (when asked for more details, the idea is you build out your question, so that others can read all the details where they belong, not have to trawl a comment thread) – Mike 'Pomax' Kamermans Feb 06 '16 at 03:11
  • you can't have both "an nth-order bezier curve" and "a shape of which the segments are cubic curves". These are two different things (the second is simply "a poly-bezier" with cubic segments), so which do you have: a shape that has a path consisting of multiple cubic bezier segments (a poly-bezier), or a *single, closed curve* modeled with a single, closed, incredibly-high-order bezier curve (an nth order curve)? – Mike 'Pomax' Kamermans Feb 06 '16 at 03:13
  • 1st post edited ... it seems I have a poly-bezier – user3602836 Feb 06 '16 at 04:07

0 Answers0