# Simulate a gear

## Recommended Posts

Hi !

I'm starting with BabylonJS: for information I know simulate the solar system and simulate a bouncing ball in a closed room.

Now I would like to simulate a simple gear with two wheels but I do not know where to start ...

Could you give me the method to make this simulation and what features should be used?

Thank you in advance and good evening

##### Share on other sites

Hi,

I'm still thinking about my problem:
- I drew a wheel with Blender
- I imported and duplicated this wheel with BabylonJS

Now the black wheel turns as you can see below:

But I miss two things:
- Add a constraint on the Y axis of the red wheel
- That the two wheels do not cross.

Someone to help me ?
Thanks a lot !
##### Share on other sites

According to the gears possible theories, you can apply a rotation on both gears but not a the same speed

Like :

`scene.registerBeforeRender(function () {    theBigGear.rotation.y += 0.02;    theLessBigGear.rotation.y += 0.04;});`

Or if you love mathematics : http://www.codecogs.com/library/engineering/theory_of_machines/the-geometry-of-gears.php ^^

##### Share on other sites

Thanks Luaacro !

But the mathematics aren't my problem... I was initially turn the two wheels but it's not a real gear

`BABYLON.SceneLoader.ImportMesh("", "scenes/", "wheel4.babylon", scene, function (newMeshes) {	camera.target = newMeshes[0];	wheel1 = newMeshes[0];	wheel1.position = new BABYLON.Vector3(0, 0, 0);	wheel1.material = materialRed;	//wheel1.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:0, friction:0.5, restitution: 4});	wheel2 = wheel1.clone("wheel2");	wheel2.position = new BABYLON.Vector3(5.3, 0, 0);	wheel2.material = materialBlack;	//wheel2.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:0, friction:0.5, restitution: 4});		scene.registerBeforeRender(function () {		wheel1.rotate(new BABYLON.Vector3(0, 1, 0) , 0.01, BABYLON.Space.LOCAL);		//wheel2.rotate(new BABYLON.Vector3(0, 1, 0) , -0.01, BABYLON.Space.LOCAL);	});});`
If you run my project, you will see that the red wheel crosses the black wheel so now I want:
- That the two wheels are "solid" (do not cross)
- Add a constraint on the Y axis to the black wheel

Thus the black wheel will turn because of the red wheel.

http://1drv.ms/1AzSZpX

Thank you !

##### Share on other sites

Why not creating compound meshes? To try to create a gear from boxes?

##### Share on other sites

Yes exactly, just for fun...

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.