body 不遵守低速反射定律
body not respecting the law of reflection at lower speeds
我正在尝试模拟一个球在游泳池周围弹跳 table 并且遇到了一个问题。 (视图是从上面俯视table)。
我总是希望球能根据反射定律反弹出边界。 Angle of incidence = angle of reflection
在右侧边界的模拟结束时,球似乎沿着它滚动。为什么不遵循反射定律?
示例:https://jsfiddle.net/5sjx7oyw/
var Engine = Matter.Engine,
Render = Matter.Render,
World = Matter.World,
Bodies = Matter.Bodies,
Body = Matter.Body,
Vector = Matter.Vector,
Events = Matter.Events;
// create an engine
var engine = Engine.create();
var canvas = document.getElementById('canvas');
engine.world.gravity.y = 0; // gravity not needed in this app
// create a renderer
var render = Render.create({
element: document.body,
canvas: canvas,
engine: engine,
options: {wireframes: true}
});
var ball_options = {
density: 0.04,
restitution: 1,// 0 = no bouncing, 1 = 100% of kinetic energy bounce back
friction: 0,
frictionAir: 0.05,
inertia: Infinity
};
var boundary_options = {
isStatic: true
};
var ball = Bodies.circle(100, 150, 11, ball_options);
var boundary_left = Bodies.rectangle(10, 160, 100, 200, boundary_options);
var boundary_right = Bodies.rectangle(300, 160, 100, 200, boundary_options);
var boundary_top = Bodies.rectangle(150, 10, 200, 100, boundary_options);
var boundary_bottom = Bodies.rectangle(150, 300, 200, 100, boundary_options);
// add all of the bodies to the world
World.add(engine.world, [
boundary_left,
boundary_right,
boundary_top,
boundary_bottom,
ball
]);
render.options.height = 300;
canvas.height = 300;
Engine.run(engine);
Render.run(render);
Body.applyForce(ball, { x: 0, y: 0 }, { x: 0.2, y: 0.5 });
电脑里的数字不是实数;他们是interests。
'float' 表示 'number like float'。
这就是为什么 x 轴上的速度不会连续减小到 0 的原因。
在代码中,x 轴的初始速度小于 y 轴的 1。
所以 'Discrete effect' 出现在 x 轴上。
当恢复几乎为 1 时,您会感觉像真正的球。
谢谢。
我已经在库创建者的帮助下解决了这个问题。
https://jsfiddle.net/8exLLLv6/55/
将以下内容添加到我的代码中解决了问题:
Matter.Resolver._restingThresh = 0.1;
有关详细信息,请参阅 gibhub 页面。
我正在尝试模拟一个球在游泳池周围弹跳 table 并且遇到了一个问题。 (视图是从上面俯视table)。
我总是希望球能根据反射定律反弹出边界。 Angle of incidence = angle of reflection
在右侧边界的模拟结束时,球似乎沿着它滚动。为什么不遵循反射定律?
示例:https://jsfiddle.net/5sjx7oyw/
var Engine = Matter.Engine,
Render = Matter.Render,
World = Matter.World,
Bodies = Matter.Bodies,
Body = Matter.Body,
Vector = Matter.Vector,
Events = Matter.Events;
// create an engine
var engine = Engine.create();
var canvas = document.getElementById('canvas');
engine.world.gravity.y = 0; // gravity not needed in this app
// create a renderer
var render = Render.create({
element: document.body,
canvas: canvas,
engine: engine,
options: {wireframes: true}
});
var ball_options = {
density: 0.04,
restitution: 1,// 0 = no bouncing, 1 = 100% of kinetic energy bounce back
friction: 0,
frictionAir: 0.05,
inertia: Infinity
};
var boundary_options = {
isStatic: true
};
var ball = Bodies.circle(100, 150, 11, ball_options);
var boundary_left = Bodies.rectangle(10, 160, 100, 200, boundary_options);
var boundary_right = Bodies.rectangle(300, 160, 100, 200, boundary_options);
var boundary_top = Bodies.rectangle(150, 10, 200, 100, boundary_options);
var boundary_bottom = Bodies.rectangle(150, 300, 200, 100, boundary_options);
// add all of the bodies to the world
World.add(engine.world, [
boundary_left,
boundary_right,
boundary_top,
boundary_bottom,
ball
]);
render.options.height = 300;
canvas.height = 300;
Engine.run(engine);
Render.run(render);
Body.applyForce(ball, { x: 0, y: 0 }, { x: 0.2, y: 0.5 });
电脑里的数字不是实数;他们是interests。 'float' 表示 'number like float'。 这就是为什么 x 轴上的速度不会连续减小到 0 的原因。 在代码中,x 轴的初始速度小于 y 轴的 1。 所以 'Discrete effect' 出现在 x 轴上。 当恢复几乎为 1 时,您会感觉像真正的球。 谢谢。
我已经在库创建者的帮助下解决了这个问题。
https://jsfiddle.net/8exLLLv6/55/
将以下内容添加到我的代码中解决了问题:
Matter.Resolver._restingThresh = 0.1;
有关详细信息,请参阅 gibhub 页面。