javascript - 检测两个圆之间的碰撞角度
问题描述
我正在检测两个圆圈之间的碰撞,如下所示:
var circle1 = {radius: 20, x: 5, y: 5}; //moving
var circle2 = {radius: 12, x: 10, y: 5}; //not moving
var dx = circle1.x - circle2.x;
var dy = circle1.y - circle2.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < circle1.radius + circle2.radius) {
// collision detected
}
我的问题是如何检测碰撞角度circle2
?(circle2
不动)。我将不胜感激任何解释
解决方案
您可以使用一些简单的三角函数来检测角度。
切线=相反/相邻
所以let angle = Math.atan(dy/dx)
推荐阅读
- graphql - GraphQL 数据存储在哪里?
- python - 为什么链接列表上的索引匹配失败?
- ios - 如何将对象传递给应该快速确认两个协议的函数?
- c# - 添加 NuGet 包后 Clickonce 部署大小膨胀
- url - Google News XML API:使用国家/语言参数
- python - 查询大型 SQL Server 表时,pymssql/pyodbc 性能(cursor.execute)非常慢
- shell - 我想编写一个 unix 代码来从 .txt 文件中的这个 SQL 代码中提取括号之间的所有列名
- simulink - Simulink 采样时间与中断服务程序采样时间有何关系?
- javascript - 是否可以提取 youtube 频道/视频页面的 Adsense 发布者 ID?
- java - 使用 Gmail Api 线程化电子邮件 [在新线程化要求之后]