util.js 337 B

123456789
  1. const getOffset = radius => {
  2. if (radius === 0) {
  3. return 0;
  4. }
  5. // 如果要考虑通用性,这里应该用三角函数 Math.sin(45)
  6. // 但是这个场景比较特殊,始终是等腰直角三角形,所以直接用 Math.sqrt() 开方即可
  7. return radius - Math.sqrt(Math.pow(radius, 2) / 2);
  8. };
  9. export default getOffset;