前段时间实现了一下椭圆工具的编辑工具,里面涉及到计算椭圆的外包围盒.隐隐觉得椭圆应该有计算外包围盒的数学方法,可惜问GPT4永远都是循环360度去算边缘返回外包围盒.要不就是按照正椭圆的方式来算外包围盒.
昨天认真搜索了一下竟然真搜索到了计算方法.(果然gpt还是没法完全替代搜索引擎的O(∩_∩)O哈哈~)
再附上自己写的js实现
// centerX,centerY 椭圆中心点,a 长轴,b 短轴, theta 弧度
export function getEllipseBoundingBox(centerX: number, centerY: number, a: number, b: number, theta: number) {
const sin_theta = Math.sin(theta)
const cos_theta = Math.cos(theta)
const A = a ** 2 * sin_theta ** 2 + b ** 2 * cos_theta ** 2
const B = 2 * (a ** 2 - b ** 2) * sin_theta * cos_theta
const C = a ** 2 * cos_theta ** 2 + b ** 2 * sin_theta ** 2
const D = -(a ** 2 * b ** 2)
const h = Math.sqrt((4 * A * D) / (B ** 2 - 4 * A * C))
const w = Math.sqrt((4 * C * D) / (B ** 2 - 4 * A * C))
const minX = centerX - w
const maxX = centerX + w
const minY = centerY - h
const maxY = centerY + h
return { minX, maxX, minY, maxY }
}
看的我热血沸腾啊https://www.237fa.com/
《Def喜剧果酱25》喜剧片高清在线免费观看:https://www.jgz518.com/xingkong/53430.html
《桃源》爱情片高清在线免费观看:https://www.jgz518.com/xingkong/22107.html