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


TypeScript Polyhedron.edgeLength方法代碼示例

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


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

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

示例2: doElongate

function doElongate(polyhedron: Polyhedron, twist?: Twist) {
  const caps = Cap.getAll(polyhedron);
  const boundary = caps[0].boundary();
  const n = boundary.numSides;
  const duplicated = duplicateVertices(polyhedron, boundary, twist);
  let vertexSets: VertexList[];
  let multiplier: number;

  const duplicatedCaps = Cap.getAll(duplicated);
  if (duplicatedCaps.length === 2) {
    vertexSets = duplicatedCaps;
    multiplier = 1 / 2;
  } else {
    // Otherwise it's the largest face
    vertexSets = [boundary.adjacentFaces()[0].withPolyhedron(duplicated)];
    multiplier = 1;
  }
  const adjustInfo = { vertexSets, boundary, multiplier };

  const height = polyhedron.edgeLength() * (twist ? antiprismHeight(n) : 1);

  const endVertices = getScaledPrismVertices(adjustInfo, height, twist);
  return {
    animationData: {
      start: duplicated,
      endVertices,
    },
  };
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:29,代碼來源:elongate.ts

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

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

示例5: doTurn

function doTurn(polyhedron: Polyhedron, { twist = 'left' }: Options) {
  const adjustInfo = getAdjustInformation(polyhedron);
  const { boundary } = adjustInfo;
  const isAntiprism = boundary.adjacentFaces()[0].numSides === 3;

  const duplicated = isAntiprism
    ? polyhedron
    : bisectPrismFaces(polyhedron, boundary, twist);

  const n = boundary.numSides;
  const scale =
    polyhedron.edgeLength() * (antiprismHeight(n) - 1) * (isAntiprism ? -1 : 1);

  const endVertices = getScaledPrismVertices(adjustInfo, scale, twist);
  return {
    animationData: {
      start: duplicated,
      endVertices,
    },
    result: isAntiprism
      ? joinAntiprismFaces(polyhedron, boundary, twist).withVertices(
          endVertices,
        )
      : undefined,
  };
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:26,代碼來源:turn.ts

示例6: getContractLength

function getContractLength(polyhedron: Polyhedron, faceType: number) {
  // Calculate dihedral angle
  // https://en.wikipedia.org/wiki/Platonic_solid#Angles
  const family = getFamily(polyhedron);
  const s = polyhedron.edgeLength();
  const p = faceType;
  const q = 3 + familyMap[family] - p;
  const h = coxeterNum[family];
  const tanTheta2 = Math.cos(Math.PI / q) / Math.sin(Math.PI / h);

  // Calculate the inradius
  // https://en.wikipedia.org/wiki/Platonic_solid#Radii,_area,_and_volume
  return (s / 2 / Math.tan(Math.PI / p)) * tanTheta2;
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:14,代碼來源:contract.ts

示例7: doShorten

function doShorten(polyhedron: Polyhedron, options: Options) {
  const adjustInfo = getAdjustInformation(polyhedron);
  const { boundary } = adjustInfo;
  const isAntiprism = boundary.adjacentFaces()[0].numSides === 3;
  const { twist = isAntiprism ? 'left' : undefined } = options;

  const n = boundary.numSides;
  const scale = polyhedron.edgeLength() * (twist ? antiprismHeight(n) : 1);

  const endVertices = getScaledPrismVertices(adjustInfo, -scale, twist);

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

示例8: doTruncate

function doTruncate(polyhedron: Polyhedron, rectify = false, result?: string) {
  const truncateLength = getTruncateLength(polyhedron);
  const oldSideLength = polyhedron.edgeLength();
  const truncateScale = (oldSideLength - truncateLength) / 2 / oldSideLength;
  const duplicated = duplicateVertices(polyhedron);
  const transform = getTruncateTransform(polyhedron, result);

  const truncatedVertices = duplicated.vertices.map(vertex => {
    const adjacentVertices = vertex.adjacentVertices();
    const v = vertex.vec;
    const v1 = find(adjacentVertices, adj => adj.vec.distanceTo(v) > PRECISION);
    const truncated = v.interpolateTo(v1.vec, rectify ? 0.5 : truncateScale);
    return !!transform ? transform(truncated, vertex) : truncated;
  });
  return {
    animationData: {
      start: duplicated,
      endVertices: truncatedVertices,
    },
  };
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:21,代碼來源:truncate.ts

示例9: doTwist

// TODO deduplicate with expand/contract
function doTwist(
  polyhedron: Polyhedron,
  referenceName: string,
  twist: Twist = 'left',
) {
  const reference = Polyhedron.get(referenceName);
  const isSnub = expansionType(polyhedron) === 'snub';
  const f0 = polyhedron.largestFace();
  const n = f0.numSides;
  const twistFaces = getExpandedFaces(polyhedron, n);

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

  const refFaces = getExpandedFaces(reference, n);
  const angle = !isSnub
    ? getTwistSign(twist) * Math.abs(getSnubAngle(reference, refFaces))
    : -getSnubAngle(polyhedron, twistFaces);
  const snubTwist = angle > 0 ? 'left' : 'right';

  const duplicated = isSnub
    ? polyhedron
    : bisectEdgeFaces(twistFaces, snubTwist);
  const endVertices = getResizedVertices(twistFaces, referenceLength, angle);

  return {
    animationData: {
      start: duplicated,
      endVertices,
    },
    result: isSnub
      ? joinEdgeFaces(twistFaces, snubTwist).withVertices(endVertices)
      : undefined,
  };
}
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:40,代碼來源:twist.ts


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