本文整理匯總了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,
},
};
}
示例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,
},
};
}
示例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);
};
}
示例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;
}
示例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,
};
}
示例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;
}
示例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,
},
};
}
示例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,
},
};
}
示例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,
};
}