简体   繁体   中英

Check for collision between a circle and the perimeter of a circle sector

I'm trying to create a function that checks if there is a collision/intersection between a circle and the perimeter of a circle sector.

I'm going to explain my problem in more detail:
1. I have a circle sector defined by the center point(x1,y1), the radius(r1) and the angle(m) that tells me where the circle sector starts and ends.
2. On the other hand, I have a circle defined by the center point (x2,y2), the radius(r2).
3. I'm creating a small game in HTML5 canvas in which both of these geometric shapes can move freely.
4. The problem is that I wanna know if these two (the green circle sector and the green circle) are colliding to each other.

在此处输入图片说明

My current code is very basic (as I can't come up of something that can efficiently check collision). It only checks the collision between the circle that defines that circle sector and the other circle:

this.crashWith = function(otherobj) {
    // "this" is the circle
    // "otherobj" is the circle sector
    var dx = this.x - otherobj.x;
    var dy = this.y - otherobj.y;
    var distance = Math.sqrt(dx * dx + dy * dy);
    var crash = false;
    if (distance < this.radius +otherobj.radius) {
        crash = true;
    }
    return crash;
}

Note: The circle sector (in color green) has a line width (as seen in the image) and the angle m changes (because the circle sector is spinning around the center).

I think the proper solution would be something that can can calculate collisions knowing that the circle sector shape doesn't change (it is only spinning).

Looks like you have a clear understanding of geometry...
You are already using Pythagoras to determine if the circles collide.

To detect head on collisions you need to include the angles in your condition, see image below:

在此处输入图片说明

When angle c is greater than a and less than b you got yourself a head on collision.

Next will be to figure out side collisions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM