本文整理匯總了TypeScript中math/polyhedra.Polyhedron.centroid方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Polyhedron.centroid方法的具體用法?TypeScript Polyhedron.centroid怎麽用?TypeScript Polyhedron.centroid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類math/polyhedra.Polyhedron
的用法示例。
在下文中一共展示了Polyhedron.centroid方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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;
}
示例2: 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;
}