# Class DampingLaw

Applies damping forces to a set of MassObject's. Damping is a friction force like air resistance, or the surface friction of objects sliding on a table.

The set of objects can be specified with the addBody method, or the DampingLaw can observe a SimList and automatically add all bodies that have mass to the set of objects.

The damping force slows both the translational velocity and rotational velocity of a MassObject. The translational force is `(-k*vx, -k*vy)` where

• `k` is the damping constant
• `(vx, vy)` is the translational velocity of the body

The torque is `-k*rotateRatio*vw` where

• `k` is the damping constant
• `rotateRatio` is a constant used to calculate rotational damping
• `vw` is the angular velocity of the body

The reason to have `rotateRatio` is so that it is easy to modify both translational and rotational damping by adjusting only the damping constant.

## Parameters Created

• ParameterNumber named `DAMPING`, see setDamping

• ParameterNumber named `ROTATE_RATIO`, see setRotateRatio

## Constructors

• #### Parameters

• ##### damping: number

translational damping factor

• ##### `Optional`rotateRatio: number

the ratio used to calculate rotational damping, as a fraction of translational damping

• ##### `Optional`opt_simList: SimList

optional SimList to observe for when objects are added; also adds all existing bodies on that SimList.

## Properties

rotateRatio_: number

rotational damping is this fraction of damping

## Methods

• Adds the SimObjects to list of objects that DampingLaw applies forces to, but only those with mass.

#### Parameters

• ##### bodies: SimObject[]

set of SimObjects to possibly add

#### Returns void

• Adds the SimObject to list of objects that DampingLaw applies forces to, but only if it has positive finite mass.

#### Returns void

• Adds the given Observer to this Subject's list of Observers, so that the Observer will be notified of changes in this Subject. An Observer may call `Subject.addObserver` during its `observe` method.

#### Returns void

• Adds the Parameter to the list of this Subject's available Parameters.

#### Throws

if a Parameter with the same name already exists.

• Notifies all Observers that the Parameter with the given name has changed by calling observe on each Observer.

#### Parameters

• ##### name: string

the language-independent or English name of the Parameter that has changed

#### Throws

if there is no Parameter with the given name

• Connect to the given SimList, so that the force applies to all objects in the SimList. Also adds all existing bodies on that SimList.

#### Parameters

• ##### simList: SimList

the SimList to connect with

#### Returns void

• Ensures this ForceLaw is not connected to anything and so can be garbage collected. For example, if this ForceLaw is an Observer, this will stop observing its Subject.

#### Returns void

• Returns the strength of the damping force.

#### Returns number

the strength of the damping force.

• Returns the Parameter with the given name.

#### Parameters

• ##### name: string

the language-independent or English name of the Parameter

#### Returns Parameter

the Parameter with the given name

#### Throws

if there is no Parameter with the given name

• Returns the ParameterNumber with the given name.

#### Parameters

• ##### name: string

the language-independent or English name of the ParameterNumber

#### Returns ParameterNumber

the ParameterNumber with the given name

#### Throws

if there is no ParameterNumber with the given name

• Returns the ParameterString with the given name.

#### Parameters

• ##### name: string

the language-independent or English name of the ParameterString

#### Returns ParameterString

the ParameterString with the given name

#### Throws

if there is no ParameterString with the given name

• Returns the ratio used to calculate rotational damping, as fraction of translational damping.

#### Returns number

ratio used to calculate rotational damping

• Notifies this Observer that a change has occurred in the Subject.

#### Parameters

• ##### event: SubjectEvent

contains information about what has changed in the Subject: typically either a one-time GenericEvent, or a change to the value of a Parameter

#### Returns void

• Removes the Observer from this Subject's list of Observers. An Observer may call `removeObserver` during its `observe` method.

#### Parameters

• ##### observer: Observer

the Observer to detach from list of Observers

#### Returns void

• Removes the Parameter from the list of this Subject's available Parameters.

#### Parameters

• ##### parameter: Parameter

the Parameter to remove

#### Returns void

• Sets whether this Subject will broadcast events, typically used to temporarily disable broadcasting. Intended to be used in situations where a subclass overrides a method that broadcasts an event. This allows the subclass to prevent the superclass broadcasting that event, so that the subclass can broadcast the event when the method is completed.

#### Parameters

• ##### value: boolean

whether this Subject should broadcast events

#### Returns boolean

the previous value

• Sets the strength of the damping force.

#### Parameters

• ##### value: number

strength of the damping force

#### Returns void

• Sets the ratio used to calculate rotational damping, as fraction of translational damping.

#### Parameters

• ##### value: number

ratio used to calculate rotational damping

#### Returns void

• Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.

For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling `toStringShort` on that other object. For example, calling `toStringShort()` on a DisplayShape might return something like this:

``````DisplayShape{polygon:Polygon{'chain3'}}
``````

#### Returns string

a minimal string representation of this object.

Generated using TypeDoc