gpt4 book ai didi

java - 计算矩形内的六边形?

转载 作者:行者123 更新时间:2023-12-04 02:56:41 24 4
gpt4 key购买 nike

我正在寻找一种算法来计算落在矩形区域内的六边形,无论是否裁剪。

我知道以下内容:

rectWidth = 1280;
rectHeight = 720;
hexRadius = 50; // middle to corner
hexHeight = hexRadius * 2;
hexShortSpan = hexRadius * 0.5;
hexLongSpan = cos(radians(30)) * hexRadius;
hexWidth = hexLongSpan * 2;
hexSide = hexRadius + hexShortSpan; // this is not a side but side + shortSpan for horizontal rows

无法找出 mod op 以获得正确的结果。

float A = rectWidth / hexWidth;
float B = rectHeight / hexSide;
float hexCount = A * B +????;
// etc. etc. not sure about the rest...

罗布

这是一张图片……

http://moggach.com/media/img/hexGrid.jpg

最佳答案

计算一个六边形的面积,用长方形的面积除以六边形的面积。

六边形的面积是

a*a * (3 * sqrt(3))/2

其中 a 是六边形的边长。

关于java - 计算矩形内的六边形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7460301/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com