當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript polyhedra.Polyhedron類代碼示例

本文整理匯總了TypeScript中math/polyhedra.Polyhedron的典型用法代碼示例。如果您正苦於以下問題:TypeScript Polyhedron類的具體用法?TypeScript Polyhedron怎麽用?TypeScript Polyhedron使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Polyhedron類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getTruncateTransform

function getTruncateTransform(polyhedron: Polyhedron, result = ''): Transform {
  if (polyhedron.isRegular()) {
    return vector => vector;
  }

  // If we're doing a bevel, we need to do some fidgeting to make sure the created
  // faces are all regular
  const truncateLength = getTruncateLength(polyhedron);
  const oldSideLength = polyhedron.edgeLength();

  const multiplier = getRectifiedMultiplier(result);
  const newSideLength = oldSideLength * multiplier;
  const faceResizeScale = newSideLength / truncateLength;

  const reference = Polyhedron.get(result);
  const normalizedResizeAmount =
    reference.faceWithNumSides(6).distanceToCenter() / reference.edgeLength() -
    polyhedron.smallestFace().distanceToCenter() / newSideLength;

  return (vector, vertex) => {
    const smallFace = find(vertex.adjacentFaces(), {
      numSides: 6,
    });
    const normal = smallFace.withPolyhedron(polyhedron).normal();
    const transform = withOrigin(smallFace.centroid(), v =>
      v
        .scale(faceResizeScale)
        .add(normal.scale(normalizedResizeAmount * newSideLength)),
    );
    return transform(vector);
  };
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:32,代碼來源:truncate.ts

示例2: doExpansion

function doExpansion(
  polyhedron: Polyhedron,
  referenceName: string,
  twist?: Twist,
) {
  const reference = Polyhedron.get(referenceName);
  const n = polyhedron.getFace().numSides;
  const duplicated = duplicateVertices(polyhedron, twist);

  // TODO precalculate this
  const referenceFace =
    _.find<Face>(reference.faces, face => isExpandedFace(reference, face, n)) ||
    reference.getFace();
  const referenceLength =
    (referenceFace.distanceToCenter() / reference.edgeLength()) *
    polyhedron.edgeLength();

  const expandFaces = _.filter<Face>(duplicated.faces, face =>
    isExpandedFace(duplicated, face, n),
  );
  const refFaces = getExpandedFaces(reference, n);
  const angle = twist
    ? getTwistSign(twist) * Math.abs(getSnubAngle(reference, refFaces))
    : 0;

  // Update the vertices with the expanded-out version
  const endVertices = getResizedVertices(expandFaces, referenceLength, angle);

  return {
    animationData: {
      start: duplicated,
      endVertices,
    },
  };
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:35,代碼來源:expand.ts

示例3: duplicateVertices

function duplicateVertices(polyhedron: Polyhedron) {
  const mapping: NestedRecord<number, number, number> = {};
  const count = polyhedron.getVertex().adjacentFaces().length;
  _.forEach(polyhedron.vertices, v => {
    _.forEach(v.adjacentFaces(), (face, i) => {
      _.set(mapping, [face.index, v.index], i);
    });
  });

  return polyhedron.withChanges(solid => {
    return solid
      .withVertices(_.flatMap(polyhedron.vertices, v => repeat(v.value, count)))
      .mapFaces(face => {
        return _.flatMap(face.vertices, v => {
          const base = count * v.index;
          const j = mapping[face.index][v.index];
          return [base + ((j + 1) % count), base + j];
        });
      })
      .addFaces(
        _.map(polyhedron.vertices, v =>
          _.range(v.index * count, (v.index + 1) * count),
        ),
      );
  });
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:26,代碼來源:truncate.ts

示例4: duplicateVertices

/**
 * Duplicate the vertices, so that each face has its own unique set of vertices,
 * and create a new face for each edge and new vertex set.
 */
function duplicateVertices(polyhedron: Polyhedron, twist?: Twist) {
  const count = polyhedron.getVertex().adjacentFaces().length;

  const newVertexMapping: NestedRecord<number, number, number> = {};
  _.forEach(polyhedron.vertices, (v, vIndex: number) => {
    // For each vertex, pick one adjacent face to be the "head"
    // for every other adjacent face, map it to a duplicated vertex
    _.forEach(v.adjacentFaces(), (f, i) => {
      _.set(newVertexMapping, [f.index, v.index], v.index * count + i);
    });
  });

  return polyhedron.withChanges(solid =>
    solid
      .withVertices(_.flatMap(polyhedron.vertices, v => repeat(v.value, count)))
      .mapFaces(face =>
        face.vertices.map(v => newVertexMapping[face.index][v.index]),
      )
      // Add a new face for each original vertex
      .addFaces(
        _.map(polyhedron.vertices, v =>
          _.range(v.index * count, (v.index + 1) * count),
        ),
      )
      // Add a new face for each original edge
      .addFaces(
        _.flatMap(polyhedron.edges, edge =>
          _.map(getEdgeFacePaths(edge, twist), face =>
            _.map(face, path => _.get(newVertexMapping, path)),
          ),
        ),
      ),
  );
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:38,代碼來源:expand.ts

示例5: 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

示例6: getsharpenFaces

function getsharpenFaces(polyhedron: Polyhedron, faceType: number) {
  // Special octahedron case
  if (polyhedron.isRegular()) {
    const face0 = polyhedron.getFace();
    const adjacentFaces = face0.adjacentFaces();
    return _.filter(face0.vertexAdjacentFaces(), f => !f.inSet(adjacentFaces));
  }

  return _.filter(polyhedron.faces, { numSides: faceType });
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:10,代碼來源:sharpen.ts

示例7: 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

示例8: removeCap

function removeCap(polyhedron: Polyhedron, cap: Cap) {
  return removeExtraneousVertices(
    polyhedron.withChanges(solid =>
      solid.withoutFaces(cap.faces()).addFaces([cap.boundary().vertices]),
    ),
  );
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:7,代碼來源:diminish.ts

示例9: getTruncateLength

function getTruncateLength(polyhedron: Polyhedron) {
  const face = polyhedron.smallestFace();
  const n = face.numSides;
  const theta = Math.PI / n;
  const newTheta = theta / 2;
  return 2 * face.apothem() * Math.tan(newTheta);
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:7,代碼來源:truncate.ts

示例10:

 _.forEach(edge.vertices, (v, j) => {
   _.set(
     newVertexMapping,
     [oppositeFace.index, v.index],
     polyhedron.numVertices() + ((i + j) % boundary.numSides),
   );
 });
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:7,代碼來源:elongate.ts


注:本文中的math/polyhedra.Polyhedron類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。