Represents a spring attached between two MassObjects, generates a Force which depends on how the Spring is stretched. Damping is proportional to the relative velocity of the two objects.

To attach one end to a fixed point you can attach to an infinite mass MassObject or a Scrim.

Compress-only mode

The compressOnly argument of the constructor sets the spring to compress only mode which behaves normally if the spring is in compression (the length is less than the rest length) but it temporarily disconnects from the second attachment point during extension (when the length is more than rest length). During extension, the Spring's start point is at the first attachment point on body1, but the end point is rest-length away from start point in the direction of the second attachment point.

Hierarchy (view full)

Implements

Constructors

  • Parameters

    • name: string

      language-independent name of this object

    • body1: MassObject

      body to attach to start point of the Spring

    • attach1_body: GenericVector

      attachment point in body coords of body1

    • body2: MassObject

      body to attach to end point of the Spring

    • attach2_body: GenericVector

      attachment point in body coords of body2

    • restLength: number

      length of spring when it has no force

    • Optional stiffness: number

      amount of force per unit distance of stretch

    • Optional compressOnly: boolean

      Sets the spring to 'compress only mode' which behaves normally if the spring is in compression but disconnects from the second attachment point during extension.

    Returns Spring

Properties

attach1_: Vector

attachment point in body coords for body1

attach2_: Vector

attachment point in body coords for body2

body1_: MassObject

body to attach point1 to

body2_: MassObject

body to attach point2 to

ID: number = 1

Counter used for naming SimObjects.

Methods

  • 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 attachment point for body 1, in body coordinates of body 1.

    Returns Vector

    attachment point for body 1, in body coordinates of body 1.

  • Returns attachment point for body 2, in body coordinates of body 2.

    Returns Vector

    attachment point for body 2, in body coordinates of body 2.

  • Returns the amount of damping for this spring. Damping is proportional to the relative velocity of the two points.

    Returns number

    amount of damping for this spring

  • Returns the distance between start and end points of this spring

    Returns number

    the distance between start and end points of this spring

  • Name of this SimObject, either the language-independent name for scripting purposes or the localized name for display to user.

    The language-independent name should be the same as the English version but capitalized and with spaces and dashes replaced by underscore, see Util.toName, nameEquals.

    The name should give an idea of the role of the SimObject in the simulation. This allows us to to treat an object in a special way depending on its name. For example, we might use the name to decide what type of DisplayObject to create to represent the SimObject.

    Parameters

    • Optional opt_localized: boolean

      true means return the localized version of the name; default is false which means return the language independent name.

    Returns string

    name of this SimObject

  • Returns the length of this spring when no force is applied.

    Returns number

    rest length of this spring

  • Returns stiffness of this spring.

    Returns number

    stiffness of this spring.

  • Positive stretch means the spring is expanded, negative stretch means compressed.

    Returns number

    the amount that this line is stretched from its rest length

  • Sets the value of damping for this spring. Damping is proportional to the relative velocity of the two points.

    Parameters

    • damping: number

      the value of damping for this spring

    Returns Spring

    this Spring to allow chaining of setters

  • Sets the rest length of this spring, which is used for calculating the stretch. When length of spring is the rest length, then no force is applied at either end.

    Parameters

    • value: number

      the rest length of this spring

    Returns void

  • Sets stiffness of this spring

    Parameters

    • stiffness: number

      the stiffness of this spring

    Returns void

  • Returns true if the given SimObject is similar to this SimObject for display purposes. SimObjects are similar when they are the same type and nearly the same size and location. Mainly used when showing forces - to avoid adding too many objects to the display. See SimList.getSimilar.

    Parameters

    • obj: SimObject

      the SimObject to compare to

    • Optional _opt_tolerance: number

      the amount the object components can differ by

    Returns boolean

    true if this SimObject is similar to obj for display purposes

  • 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