javascript - 空心圆盘的角速度 MatterJS
问题描述
我想在 MatterJS 中围绕它的中心旋转一个空心的圆盘状圆圈。我使用下面的代码创建了这样一个空心体,基本上组合了无数个矩形。它看起来像这样:
function containerPolygon(
x, y, sides, radius, color
) {
const width = 2;
const extraLength = 1.15;
const initialRotation = 0;
const theta = (2 * Math.PI) / sides;
const sideLength = ((2 * radius * theta) / 2) * extraLength;
const parts = [];
for (let i = 0; i < sides; i++) {
// We'll build thin sides and then translate + rotate them appropriately.
const body = Bodies.rectangle(0, 0, sideLength, width, {
render: {
fillStyle: color,
},
});
Body.rotate(body, i * theta);
Body.translate(body, {
x: radius * Math.sin(i * theta),
y: -radius * Math.cos(i * theta),
});
parts.push(body);
}
const ret = Body.create({
isStatic: true,
// frictionAir: 0,
friction: 1,
// // frictionStatic: 0,
// inertia: Infinity, // setting inertia to infinty will prevent rotation upon collision
rotationSpeed: -2.5,
restitution: ball_restitution,
});
Body.setParts(ret, parts);
Body.translate(ret, { x: x, y: y });
return ret;
}
我使用下面的代码调用该函数:
let rotating_circle = containerPolygon(
window.innerWidth / 2,
window.innerHeight / 2,
50,
radius + object_radius,
outter_circle_color
);
我想设置它的角速度,使其围绕其中心旋转,但我尝试使用下面的这种方法,它甚至没有旋转。
Body.setAngularVelocity(rotating_cicle, Math.PI/6);
解决方案
推荐阅读
- urlopen - TensorFlow hub、Elmo 模块的证书验证失败
- reactjs - 在开发模式下使用 Create-React-App 配置 TypeScript 目标
- r - 试图获得 r 的月份差异
- c# - 无法访问已处置的对象。对象名称:'System.Net.Http.HttpMessageInvoker'
- javascript - 我们可以将 JavaScript 变量传递给 Python 文件吗?
- python - 由于 python 版本,使用 python 3.8 安装包后 Pipenv 不会锁定
- r - 按组查找列中最小数字的汇总统计信息
- javascript - Safari 和移动 Chrome 中的视频流问题
- python - 如何检测表格的水平和垂直线并消除噪音?
- ios - 在 Xcode + Swift 中,变量名前的正斜杠有什么作用?