JavaScript 中直线和圆之间的碰撞检测 [英] Collision detection between a line and a circle in JavaScript
问题描述
我正在寻找一个明确的答案,也许是一个函数,因为我很慢,它将确定线段和圆是否在 javascript 中发生碰撞(使用画布)
I'm looking for a definitive answer, maybe a function cos I'm slow, that will determine if a line segment and circle have collided, in javascript (working with canvas)
一个像下面这样的函数,如果碰撞就返回真,否则返回假,那就太棒了.我什至可以给你捐一个孩子.
A function like the one below that simply returns true if collided or false if not would be awesome. I might even donate a baby to you.
function isCollided(lineP1x, lineP1y, lineP2x, lineP2y, circlex, circley, radius) {
...
}
我发现了很多公式,就像这个,但它们都超过了我的头.
I've found plenty of formulas, like this one, but they are over my head.
推荐答案
这里你需要一些数学:
如果您不知道一般如何求解方程,这是基本概念.我会把剩下的想法留给你.;) 找出CD
的长度并不难.
This is the basic concept if you don't know how to solve equations in general. I will leave the rest of the thinking to you. ;) Figuring out CD
's length isn't that hard.
如果您要问如何,那就是:在 JavaScript 中查找冲突有点复杂.
If you are asking how, that's how: Finding collisions in JavaScript is kind of complicated.
这篇关于JavaScript 中直线和圆之间的碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!