2
\$\begingroup\$

So how do I implement the collision detection for an arc of a circle? Will I have to use the Box 2D collision or can I do it some other way using Rectangle or stuff like that?

BTW I hate box2d because I don't understand most of the things in it, so if there is a solution that excludes the box2d, it will be very much appreciated.

yellow arc

The yellow arc keeps on rotating over the black circle. How do I implement collision detection in here?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Please don't cross post questions between SE sites. If necessary, request that your question be migrated. \$\endgroup\$
    – Pikalek
    Commented May 4, 2017 at 15:32
  • \$\begingroup\$ I'm voting to close this question as off-topic because it is a intra-network cross-post. \$\endgroup\$
    – user1430
    Commented May 4, 2017 at 15:38
  • \$\begingroup\$ @Pikalek ok sorry but i was not getting any reply. \$\endgroup\$ Commented May 4, 2017 at 15:45
  • \$\begingroup\$ @SagarBalyan I understand - given the rapid response to most questions it can be frustrating to not get a quick reply yourself. Even if your intent is good, attempts to do an end-run around the system often do less good than just letting the system do its thing. \$\endgroup\$
    – Pikalek
    Commented May 4, 2017 at 15:51

1 Answer 1

0
\$\begingroup\$

I answered this question already Collision detection for an arc of a circle however I will sum it up here:

You can create a polygon that represents the area you want to detect collisions for using code similar to:

    polya = new Polygon();

    // create vertices
    float section = 15f;
    float[] newVerts = new float[200];
    for(int i = 0; i < 50; i++){
        newVerts[i*2] = (float)Math.sin(i/section); //x 0 to 98 even
        newVerts[i*2+1] = (float)Math.cos(i/section); //y 1 to 99  odd

        newVerts[199-i*2] = (float)Math.cos(i/section); //x 100 to 108
        newVerts[198-i*2] = (float)Math.sin(i/section) + 0.2f; //y 101 to 199

    }

    polya.setVertices(newVerts);
    polya.scale(50);

Then you use the polygon.contains(x,y) method to check if the point x,y is inside. This will return a boolean value true if the point is inside the polygon which equates to a collision.

if(polya.contains(mp.x,mp.y)){
      //point has collided with polygon do something
}
\$\endgroup\$
1
  • \$\begingroup\$ If you know the question is a cross post, please don't answer it, and flag the question for moderator attention. Cross posting on Stack Exchange is not allowed. \$\endgroup\$
    – Vaillancourt
    Commented May 4, 2017 at 15:34

Not the answer you're looking for? Browse other questions tagged .