Previous topic TOC

Create user-defined forces

Next topic

Force Besides joints, you can also define forces between two objects. This is done by using the Force object. Example:
//use some material
factory.material = Material(1e-6, .2, .9, 0.1);  

var A = Box({10,10,10},{0,100,0}); // create two objects
var B = Box({10,10,10}, {0,50,0});
A.color = RGB(255,0,0);            // assign some colors
B.color = RGB(255,255,0);

A .static = true;                  // topmost object is static

// create a force between A and B, it is attached to the local 
// origin of both objects
var f = Force(A, {0,0,0}, B , {0,0,0});

// create a function that will calculate the amount of force
// to be applied by 'f'.
function f_func()
	return norm(A.position - B.position)-70;
f.force = f_func;  //assign the function to 'f'

// simulate scene
while (simulator.time < 1)
	WaitFrame(); );
Each end of the force object is attached to an object at a local position on that object. The expressed force is directed along the line between the two endpoints and has a size equal to the force property of the Force instance.
Spring, Damper The Spring and Damper classes are two specializations of the Force class. These classes implement the linear spring and damper, and do not make use of the force property. See documentation for further information.
AbsForce, RelForce There is yet another type of force to be introduced: the AbsForce and RelForce classes implement a force that is attached to one object at a given local position, and apply a force to the attached object. This force is directed in absolute coordinates (AbsForce), or relative to the objects orientation (RelForce). For example, a rocket propulsion could be modeled using the RelForce class, whereas a vector field could be modeled using the AbsForce.