本文整理汇总了TypeScript中math/polyhedra.Face类的典型用法代码示例。如果您正苦于以下问题:TypeScript Face类的具体用法?TypeScript Face怎么用?TypeScript Face使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Face类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: doAugment
// Augment the following
function doAugment(
polyhedron: Polyhedron,
base: Face,
augmentType: string,
gyrate?: string,
) {
const numSides = base.numSides;
const augmentee = getAugmentee(augmentType, numSides);
const underside = augmentee.faceWithNumSides(base.numSides);
// Determine the orientations of the underside and the base
const undersideRadius = underside.vertices[0].vec
.sub(underside.centroid())
.getNormalized();
const baseIsAligned = isAligned(
polyhedron,
base,
underside,
isFastigium(augmentType, numSides) ? 'gyro' : gyrate,
augmentType,
);
const offset = baseIsAligned ? 0 : 1;
const baseRadius = base.vertices[offset].vec
.sub(base.centroid())
.getNormalized();
// https://math.stackexchange.com/questions/624348/finding-rotation-axis-and-angle-to-align-two-oriented-vectors
// Determine the transformation that rotates the underside orientation to the base orientation
// TODO we probably want this as some sort of generic method
const transformMatrix = getOrthonormalTransform(
undersideRadius,
underside.normal().getInverted(),
baseRadius,
base.normal(),
);
const transform = withOrigin(base.centroid(), u =>
transformMatrix.applyTo(u),
);
// Scale and position the augmentee so that it lines up with the base
const alignedVertices = augmentee.vertices.map(v => {
return v.vec
.sub(underside.centroid())
.scale(base.sideLength() / augmentee.edgeLength())
.add(base.centroid());
});
// Rotate the vertices so that they align with the base
const rotatedVertices = alignedVertices.map(v => transform(v));
const newAugmentee = augmentee.withChanges(solid =>
solid.withVertices(rotatedVertices).withoutFaces([underside]),
);
return polyhedron.withChanges(solid =>
solid.withoutFaces([base]).addPolyhedron(newAugmentee),
);
}
示例2: isExpandedFace
export function isExpandedFace(
polyhedron: Polyhedron,
face: Face,
nSides?: number,
) {
const type = expansionType(polyhedron);
if (typeof nSides === 'number' && face.numSides !== nSides) return false;
if (!face.isValid()) return false;
return _.every(face.adjacentFaces(), { numSides: edgeShape[type] });
}
示例3: isAligned
// Return true if the base and augmentee are aligned
function isAligned(
polyhedron: Polyhedron,
base: Face,
underside: Face,
gyrate: string | undefined,
augmentType: string,
) {
if (augmentType === 'pyramid') return true;
const baseType = getBaseType(base);
if (baseType === 'pyramid' || baseType === 'antiprism') {
return true;
}
if (baseType === 'prism' && Cap.getAll(polyhedron).length === 0) {
return true;
}
if (baseType !== 'truncated' && _.isNil(gyrate)) {
throw new Error(`Must define 'gyrate' for augmenting ${baseType} `);
}
const adjFace =
baseType === 'prism' ? getOppositePrismFace(base) : base.adjacentFaces()[0];
const alignedFace = getCyclic(underside.adjacentFaces(), -1);
if (baseType === 'rhombicosidodecahedron') {
const isOrtho = (adjFace.numSides !== 4) === (alignedFace.numSides !== 4);
return isOrtho === (gyrate === 'ortho');
}
// It's orthogonal if triangle faces are aligned or non-triangle faces are aligned
const isOrtho = (adjFace.numSides !== 3) === (alignedFace.numSides !== 3);
if (baseType === 'truncated') {
return !isOrtho;
}
// "ortho" or "gyro" is actually determined by whether the *tops* are aligned, not the bottoms
// So for a cupola-rotunda, it's actually the opposite of everything else
if (isCupolaRotunda(Cap.getAll(polyhedron)[0].type, augmentType)) {
return isOrtho !== (gyrate === 'ortho');
}
return isOrtho === (gyrate === 'ortho');
}
示例4: getFaceDistance
function getFaceDistance(face1: Face, face2: Face) {
let dist = 0;
let current = [face1];
while (!face2.inSet(current)) {
dist++;
current = flatMapUniq(current, face => face.adjacentFaces(), 'index');
if (dist > 10) {
throw new Error('we went toooooo far');
}
}
return dist;
}
示例5: getBaseType
function getBaseType(base: Face) {
const adjacentFaces = base.adjacentFaces();
const adjacentFaceCounts = _(adjacentFaces)
.map('numSides')
.uniq()
.value();
if (setEquals(adjacentFaceCounts, [3, 4])) {
return 'cupola';
} else if (setEquals(adjacentFaceCounts, [4])) {
return 'prism';
} else if (setEquals(adjacentFaceCounts, [3])) {
return _.intersection(adjacentFaces).length > 0 ? 'pyramid' : 'antiprism';
} else if (setEquals(adjacentFaceCounts, [3, 5])) {
return 'rotunda';
} else if (setEquals(adjacentFaceCounts, [4, 5])) {
return 'rhombicosidodecahedron';
} else {
return 'truncated';
}
}
示例6: getVertexToAdd
function getVertexToAdd(polyhedron: Polyhedron, face: Face) {
const dist = getsharpenDist(polyhedron, face);
return face.normalRay().getPointAtDistance(dist);
}
示例7: calculatesharpenDist
function calculatesharpenDist(face: Face, edge: Edge) {
const apothem = face.apothem();
const theta = Math.PI - edge.dihedralAngle();
return apothem * Math.tan(theta);
}
示例8: getAugmentAlignment
function getAugmentAlignment(polyhedron: Polyhedron, face: Face) {
const boundary = getSingle(Cap.getAll(polyhedron)).boundary();
return isInverse(boundary.normal(), face.normal()) ? 'para' : 'meta';
}
示例9:
const alignedVertices = augmentee.vertices.map(v => {
return v.vec
.sub(underside.centroid())
.scale(base.sideLength() / augmentee.edgeLength())
.add(base.centroid());
});