javascript - 如何找到能够容纳在已知尺寸的椭圆内的最大矩形?
问题描述
更具体地说:给定一个具有已知宽度、高度和 x、y 位置的椭圆——如何找到能够在其中绘制的最大可能矩形的宽度、高度和 x、y 位置。
// eWidth, eHeight, eX, eY are known, arbitrary values
const ellipse = draw.ellipse(eWidth, eHeight).move(eX, eY);
// rWidth, rHeight, rX, rY are unknown
const rect = draw.rect(rWidth, rHeight).move(rX, rY);
解决方案
好吧,看这张图就清楚了:
从这个答案https://stackoverflow.com/a/6716520/160937
// eWidth, eHeight, eX, eY are known, arbitrary values
const ellipse = draw.ellipse(eWidth, eHeight).move(eX, eY);
// Each radius * Square root of 2
const rect = draw.rect((ellipse.width() / 2) * Math.SQRT2, (ellipse.height() / 2) * Math.SQRT2)
// Then move to the center of the ellipse
.cx(ellipse.cx()).cy(ellipse.cy());
推荐阅读
- primary-key - 如何在clickhouse的主键中使用`toYYYYMMDD(timestamp)`
- python - /cart/'car' 处的 NoReverseMatch 不是 Python Django 中的已注册命名空间错误
- routing - 类型“NavController”上不存在属性“父级”
- perl - Compilation of pattern failed at LibXML.pm
- sql - SQL分页重复,按非唯一值排序
- spring - RabbitMQ:如何为所有消费者设置通用的 prefetchCount?
- asp.net-mvc - 如何为一组人设置一个登录页面,为另一组人设置另一个登录页面?
- javascript - 如何根据选择日期显示日历?
- laravel - Laravel 角色中间件角色或角色而不是角色和角色
- reactjs - 未捕获的 TypeError:formData 不可迭代