简体   繁体   English

检查圆与圆扇形的周长之间是否存在碰撞

[英]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. 1.我有一个由圆心(x1,y1),半径(r1)和角度(m)定义的圆弧,告诉我圆弧的起点和终点。
2. On the other hand, I have a circle defined by the center point (x2,y2), the radius(r2). 2.另一方面,我有一个由中心点(x2,y2),半径(r2)定义的圆。
3. I'm creating a small game in HTML5 canvas in which both of these geometric shapes can move freely. 3.我正在用HTML5画布创建一个小游戏,其中这两个几何形状都可以自由移动。
4. The problem is that I wanna know if these two (the green circle sector and the green circle) are colliding to each other. 4.问题是我想知道这两个(绿色圆圈部分和绿色圆圈)是否相互碰撞。

在此处输入图片说明

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). 注意:圆扇形(绿色)具有线宽(如图中所示),并且角度m发生变化(因为圆扇形围绕中心旋转)。

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. 当角度c大于a且小于b您会遇到碰撞。

Next will be to figure out side collisions 接下来将找出侧面碰撞

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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