本文整理汇总了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);
};
}
示例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,
},
};
}
示例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),
),
);
});
}
示例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)),
),
),
),
);
}
示例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;
}
示例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 });
}
示例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;
}
示例8: removeCap
function removeCap(polyhedron: Polyhedron, cap: Cap) {
return removeExtraneousVertices(
polyhedron.withChanges(solid =>
solid.withoutFaces(cap.faces()).addFaces([cap.boundary().vertices]),
),
);
}
示例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);
}
示例10:
_.forEach(edge.vertices, (v, j) => {
_.set(
newVertexMapping,
[oppositeFace.index, v.index],
polyhedron.numVertices() + ((i + j) % boundary.numSides),
);
});