如何找到能够适合已知尺寸的椭圆形的最大矩形?

时间:2018-10-18 12:45:13

标签: javascript algorithm geometry

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

1 个答案:

答案 0 :(得分:1)

只要看一下这张图片就可以清楚地看到:http://tinypic.com/view.php?pic=sxhlc0&s=7(来自这个答案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());