当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Polyhedron.centroid方法代码示例

本文整理汇总了TypeScript中math/polyhedra.Polyhedron.centroid方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Polyhedron.centroid方法的具体用法?TypeScript Polyhedron.centroid怎么用?TypeScript Polyhedron.centroid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在math/polyhedra.Polyhedron的用法示例。


在下文中一共展示了Polyhedron.centroid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: isProperPolyhedron

function isProperPolyhedron(polyhedron: Polyhedron) {
  const expectedSideLength = polyhedron.edgeLength();
  for (let edge of polyhedron.edges) {
    const sideLength: number = edge.length();
    if (_.isNaN(sideLength)) {
      console.log(`edge ${edge} has length NaN`);
      return false;
    }
    if (Math.abs(sideLength - expectedSideLength) > PRECISION) {
      console.log(
        `edge ${edge} has length ${sideLength} which is different from ${expectedSideLength}`,
      );
      return false;
    }
    // Make sure the whole thing is convex
    if (edge.dihedralAngle() > Math.PI - PRECISION) {
      console.log(`polyhedron concave at edge ${edge}`);
      return false;
    }
  }

  // Make sure all faces are facing the right way
  const centroid = polyhedron.centroid();
  for (let face of polyhedron.faces) {
    const faceCentroid = face.centroid();
    const normal = face.normal();
    const expectedNormal = faceCentroid.sub(centroid);
    if (normal.angleBetween(expectedNormal, true) > Math.PI / 2) {
      console.log(`polyhedron inside out at ${face.index}`);
      return false;
    }
  }
  return true;
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:34,代码来源:operationTestUtils.ts

示例2: getSnubAngle

export function getSnubAngle(polyhedron: Polyhedron, faces: Face[]) {
  const [face0, ...rest] = faces;
  const faceCentroid = face0.centroid();
  const faceNormal = face0.normal();
  const midpoint = face0.edges[0].midpoint();

  const face1 = _.minBy(rest, face => midpoint.distanceTo(face.centroid()))!;

  const plane = getPlane([
    faceCentroid,
    face1.centroid(),
    polyhedron.centroid(),
  ]);

  const normMidpoint = midpoint.sub(faceCentroid);
  const projected = plane.getProjectedPoint(midpoint).sub(faceCentroid);
  const angle = normMidpoint.angleBetween(projected, true) || 0;
  // Return a positive angle if it's a ccw turn, a negative angle otherwise
  const sign = normMidpoint
    .cross(projected)
    .getNormalized()
    .equalsWithTolerance(faceNormal, PRECISION)
    ? -1
    : 1;
  return angle * sign;
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:26,代码来源:resizeUtils.ts


注:本文中的math/polyhedra.Polyhedron.centroid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。