automatic-ref-counting - 椭圆弧的边界
问题描述
我需要找到 2D 变换椭圆弧的确切边界。
录入数据如下:
- a - 椭圆半径 x
- b - 椭圆半径 y
- transform - 0 平移的 2D 变换 (a, b, c, d, tx, ty)
- startAngle - 圆弧起始角度
- endAngle - 圆弧结束角度
我已经使用这个主题答案来找到变换椭圆的边界 https://math.stackexchange.com/questions/91132/how-to-get-the-limits-of-rotated-ellipse
它工作正常。
我现在拥有的
const rx2 = radiusX * radiusX;
const ry2 = radiusY * radiusY;
let maxX = Math.sqrt(rx2 * transform.a * transform.a + ry2 * transform.c * transform.c);
let maxY = Math.sqrt(rx2 * transform.b * transform.b + ry2 * transform.d * transform.d);
let minX = -maxX;
let minY = -maxY;
下一步是找到点 p1、p2、p3、p4(见图)然后我可以检查哪些点在 startAngle 和 endAngle 内。
椭圆的方程为: 简单方程
变换椭圆的方程应为: 变换方程
为了找到所需的点,必须为 x 和 y 求解最后一个方程
解决方案
我有这个。
所以我只需要对点(minX,minY)应用逆变换;(最大X,最小Y);(最大X,最大Y);(最大X,最小Y);然后使用简单的椭圆(上面提到过)和直线方程找到四个交点,然后将其转换为全局坐标乘以进行变换。
这是一点的代码
arcLineIntersection(lineStart, lineEnd, rx2, ry2, out) {
const lineK = (lineEnd.y - lineStart.y) / (lineEnd.x - lineStart.x);
if (Number.isFinite(lineK)) {
const lineB = lineStart.y - lineK * lineStart.x;
const a = lineK * lineK + ry2 / rx2;
const b = 2 * lineK * lineB;
const x = -b / (2 * a);
const y = lineK * x + lineB;
out.set(x, y);
} else {
const x = lineStart.x;
const y = Math.sqrt(ry2 * (1 - x * x / rx2));
out.set(x, y);
}
}
推荐阅读
- html - 背景颜色无法正确显示文本和图像
- android - 不要重复依赖
- apache-spark - 如何使用 GeoSpark 在 AWS/EMR 上配置 Yarn/Spark?
- java - 使用 Selenium Webdriver 将以 Json 格式存储的数据从 Excel 工作表传递到应用程序的 UI
- javascript - 即使距离和重量设置为零,获得直边线的问题
- vba - 在 word vba 中创建更长的列表
- sql - PostgreSQL:如何在 sql 查询中将 date_trunc 周开始日从星期一更改为另一天?
- flutter - 如何在未来完成后验证某些行为,使用 mockito
- excel - 将 SUBSTITUTE 与通配符一起使用
- javascript - 如果文本框为空,则单击提交按钮后将用户保持在同一个 div 中