javascript - 使用 2 个点和圆弧半径计算路径圆弧上的中点
问题描述
求从 A 到 B 的路径弧的中点 M:
图表:
我有 :
- 点 A(x,y)
- 点 B(x,y)
- 圆弧半径
我尝试了以下代码,但不推荐使用getPointAtLength。
var myarc = document.getElementById("myarc");
// Get the length of the path
var pathLen = myarc.getTotalLength();
console.log(pathLen);
// How far along the path to we want the position?
var pathDistance = pathLen * 0.5;
console.log(pathDistance);
// Get the X,Y position
var midpoint = myarc.getPointAtLength(pathDistance)
console.log(myarc.getAttribute("d"));
console.log(midpoint);
解决方案
几何计算:
计算向量
AB = B - A (AB.x = B.x - A.x, similar for Y)
是长度
lAB = sqrt(AB.x*AB.x + AB.y*AB.y)
归一化向量
uAB = AB / lAB
和弦中点
mAB = (A + B)/2
箭头值
F = R - sqrt(R*R - lAB*lAB/4)
现在弧的中间:
M.x = mAB.x - uAB.Y * F
M.y = mAB.y + uAB.X * F
请注意,有两个点(您需要知道与 AB 相关的圆心方向),对于第二个,第二个项的变化符号
推荐阅读
- java - 有没有办法在TestNG中向@Factory注解发送多个参数
- django - 如何在 django rest 中找到两个用户之间的连接?
- python - 如何在python中输入一对浮点数和整数
- java - 在 Eclipse 格式化程序中应用正则表达式
- javascript - 在 MongoDB 中存储文章的图像
- java - Android Wear:很奇怪的等待周期
- python - 使用 PIL 模块写入特定字段
- php - WooCommerce:在购物车中的产品名称下移动价格和小计
- c# - 如何将两个表达式与 Any 链接以制定 EF Core 查询
- javascript - 无法在 Ubuntu 16.04 上安装浏览同步