我正在寻找一个明确的答案,也许是一个函数,因为我很慢,它将确定线段和圆是否发生碰撞,在 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)
像下面这样的函数,如果发生碰撞,则返回 true,否则返回 false.我什至可以给你捐一个婴儿.
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中直线和圆之间的碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Angular 2/Typescript 中使用 IScrollUse IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
Anime.js 在 Ionic 3 项目中不起作用anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 项目中不起作用)
Ionic 3 - 使用异步数据更新 ObservableIonic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用异步数据更新 Observable)
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
将 ViewChild 用于动态元素 - Angular 2 &离子2Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(将 ViewChild 用于动态元素 - Angular 2 amp;离子2)