JavaScript中的线和圆之间的碰撞检测 [英] Collision detection between a line and a circle in JavaScript
问题描述
我正在寻找一个确定的答案,也许一个函数cos我很慢,将确定一个线段和圆形是否冲突,在javascript(使用画布)
一个类似下面的函数,如果碰撞则返回true,否则返回false。
函数isCollided(lineP1x,lineP1y,lineP2x,lineP2y,circlex,circley,radius) {
...
}
大量的公式,喜欢这一个,但他们在我的头。
这里你需要一些数学:
这是基本概念,如果你不知道如何解方程一般。我会把其余的想法留给你。 ;)找出 CD
的长度并不难。
如果你问的是怎么样, :
在JavaScript中查找碰撞很复杂。 p>
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.
Here you will need some Math:
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.
If you are asking how, that's how: Finding collisions in JavaScript is kind of complicated.
这篇关于JavaScript中的线和圆之间的碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!