javascript - 如何创建并排堆叠拱门(形成一个圆圈)的功能?

标签 javascript math

我想创建一个以下列方式堆叠拱门的函数:

enter image description here

(这是一个简化版本。在真正的应用程序中,可能会有更多拱门。) 每个拱门的长度42。将拱门置于上部中心的旋转158

我的数学很差,所以这就是我能想到的:

positionArches () {
  const archWidth = 42
  const arches = [
    { name: 'arch1', rotation: 0 }, // must change the rotation
    { name: 'arch2', rotation: 0 },
    { name: 'arch3', rotation: 0 }
  ]
  if (this.isOdd) {
    // 1 arch: [158]
    // 3 arches: [158 - archLength, 158, 158 + archLength] // smaller to larger
  } else {
    // 2 arches: [158-(archLength/2), 158+(archLength/2)]
  }
}

但我不知道如何继续。有什么想法吗?

最佳答案

假设 arches 数组包含您需要放置的尽可能多的拱门,您可以这样做:

arches.forEach(function (arch, i) {
    arch.rotation = 180 - arches.length * 21 + i * 42;
});

请注意,如果您有超过 4 个拱门,它们将开始重叠。

另请注意,如果您的足弓尺寸为 42 度,则 158 度与理想位置相差 1 度:应该是 159 度。

关于javascript - 如何创建并排堆叠拱门(形成一个圆圈)的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41393015/

相关文章:

javascript - 如何在文本插入后放置回插入符号?

arrays - 如何在恒定时间内找到相关线性方程组的解?

java - 数组值未按预期工作

javascript - 以下演示中的 FadeIn 和 fadeOut

javascript - 使用 Javascript 填充 Select

javascript - 为什么这个正则表达式匹配?

java - 离散化困境

c# - 为什么 C# Math.Ceiling 向下舍入?

objective-c - objective-c 中的科学记数法(与基数 e 计算混淆)

javascript - 使用 JSON.stringify 和 JSON.parse 将多边形坐标存储到 oracle 中