【问题标题】:How to find the the largest rectangle able to fit within an ellipse of known dimensions?如何找到能够容纳在已知尺寸的椭圆内的最大矩形?
【发布时间】:2019-03-23 06:48:45
【问题描述】:

更具体地说:给定一个具有已知宽度、高度和 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);

【问题讨论】:

标签: javascript algorithm geometry


【解决方案1】:

好吧,看这张图就明白了:

从这个答案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());

【讨论】:

    猜你喜欢
    • 2010-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    相关资源
    最近更新 更多