Collision detecting a custom sketch represented as a list of points

I have a set of dots drawn by the user. They will paint around some objects.

I need to somehow turn this set of points into a shape, so I can find an area for collision detection.

The image will clarify:

A set of points presented as a form http://www.imagechicken.com/uploads/1277188630025178800.jpg .

The best idea I've had so far involves repeating each pixel that determines whether it is “inside” or “outside” of the form, but that would be terribly slow, and I'm not even sure how to make the definition of “inside ' / 'outside' bit ...

Any clues? I am using .NET (C # and XNA) if this helps you to help me!

+3
source share
3 answers

Well, I got a job thanks to some help on another forum .

I used the class GraphicsPathto do all the hard work for me.

Here is what my method looked like:

public bool IsColliding(Vector2 point)
{
    GraphicsPath gp = new GraphicsPath();

    Vector2 prevPoint = points[0];
    for (int i = 1; i < points.Count; i++)
    {
        Vector2 currentPoint = points[i];

        gp.AddLine(prevPoint.X, prevPoint.Y, currentPoint.X, currentPoint.Y);

        prevPoint = currentPoint;
    }
    gp.CloseFigure();   //closing line segment

    return gp.IsVisible(point.X, point.Y);
}

Thanks for your suggestions to both of you.

+1
source

, .
, :
, - , .
- , .
- , ( ) , - , ( ) , ( - ).
- , .

+1

, , , , .

, , Hit Boxes. , , . , .

Collision 'Bubbles', . , . Collision Bubbles Super Smash Brothers.

, , .

To take this one step further, I did a little research, I saw an excellent algorithm (more advanced than the two best sentences), "Gilbert-Johnson-Keerthi Collision Detection Algorithm for Convex Objects". Here is the link for ya. The presented implementation is written in D. If your work in C # should not be too complicated for translation (I would strongly suggest digesting the algorithm too).

Hope this gives you some direction.

+1
source

Source: https://habr.com/ru/post/1751142/


All Articles