class SpringForce


Spring Force defines the characteristics of the spring being used in the animation.

By configuring the stiffness and damping ratio, callers can create a spring with the look and feel suits their use case. Stiffness corresponds to the spring constant. The stiffer the spring is, the harder it is to stretch it, the faster it undergoes dampening.

Spring damping ratio describes how oscillations in a system decay after a disturbance. When damping ratio >1* (i.e. over-damped), the object will quickly return to the rest position without overshooting. If damping ratio equals to 1 (i.e. critically damped), the object will return to equilibrium within the shortest amount of time. When damping ratio is less than 1 (i.e. under-damped), the mass tends to overshoot, and return, and overshoot again. Without any damping (i.e. damping ratio = 0), the mass will oscillate forever.

Summary

Constants

const Float

Damping ratio for a very bouncy spring.

const Float

Damping ratio for a spring with low bounciness.

const Float

Damping ratio for a medium bouncy spring.

const Float

Damping ratio for a spring with no bounciness.

const Float
STIFFNESS_HIGH = 10000.0f

Stiffness constant for extremely stiff spring.

const Float
STIFFNESS_LOW = 200.0f

Stiffness constant for a spring with low stiffness.

const Float

Stiffness constant for medium stiff spring.

const Float

Stiffness constant for a spring with very low stiffness.

Public constructors

Creates a spring force.

SpringForce(finalPosition: Float)

Creates a spring with a given final rest position.

Public functions

Float

Returns the damping ratio of the spring.

Float

Returns the rest position of the spring.

Float

Gets the stiffness of the spring.

SpringForce!
setDampingRatio(dampingRatio: @FloatRange(from = 0.0) Float)

Spring damping ratio describes how oscillations in a system decay after a disturbance.

SpringForce!
setFinalPosition(finalPosition: Float)

Sets the rest position of the spring.

SpringForce!
setStiffness(stiffness: @FloatRange(from = 0.0, fromInclusive = false) Float)

Sets the stiffness of a spring.

Constants

DAMPING_RATIO_HIGH_BOUNCY

Added in 1.0.0
const val DAMPING_RATIO_HIGH_BOUNCY = 0.2f: Float

Damping ratio for a very bouncy spring. Note for under-damped springs (i.e. damping ratio <1), the lower the damping ratio, the more bouncy the spring.

DAMPING_RATIO_LOW_BOUNCY

Added in 1.0.0
const val DAMPING_RATIO_LOW_BOUNCY = 0.75f: Float

Damping ratio for a spring with low bounciness. Note for under-damped springs (i.e. damping ratio <1), the lower the damping ratio, the higher the bounciness.

DAMPING_RATIO_MEDIUM_BOUNCY

Added in 1.0.0
const val DAMPING_RATIO_MEDIUM_BOUNCY = 0.5f: Float

Damping ratio for a medium bouncy spring. This is also the default damping ratio for spring force. Note for under-damped springs (i.e. damping ratio <1), the lower the damping ratio, the more bouncy the spring.

DAMPING_RATIO_NO_BOUNCY

Added in 1.0.0
const val DAMPING_RATIO_NO_BOUNCY = 1.0f: Float

Damping ratio for a spring with no bounciness. This damping ratio will create a critically damped spring that returns to equilibrium within the shortest amount of time without oscillating.

STIFFNESS_HIGH

Added in 1.0.0
const val STIFFNESS_HIGH = 10000.0f: Float

Stiffness constant for extremely stiff spring.

STIFFNESS_LOW

Added in 1.0.0
const val STIFFNESS_LOW = 200.0f: Float

Stiffness constant for a spring with low stiffness.

STIFFNESS_MEDIUM

Added in 1.0.0
const val STIFFNESS_MEDIUM = 1500.0f: Float

Stiffness constant for medium stiff spring. This is the default stiffness for spring force.

STIFFNESS_VERY_LOW

Added in 1.0.0
const val STIFFNESS_VERY_LOW = 50.0f: Float

Stiffness constant for a spring with very low stiffness.

Public constructors

SpringForce

Added in 1.0.0
SpringForce()

Creates a spring force. Note that final position of the spring must be set through setFinalPosition before the spring animation starts.

SpringForce

Added in 1.0.0
SpringForce(finalPosition: Float)

Creates a spring with a given final rest position.

Parameters
finalPosition: Float

final position of the spring when it reaches equilibrium

Public functions

getDampingRatio

Added in 1.0.0
fun getDampingRatio(): Float

Returns the damping ratio of the spring.

Returns
Float

damping ratio of the spring

getFinalPosition

Added in 1.0.0
fun getFinalPosition(): Float

Returns the rest position of the spring.

Returns
Float

rest position of the spring

getStiffness

Added in 1.0.0
fun getStiffness(): Float

Gets the stiffness of the spring.

Returns
Float

the stiffness of the spring

setDampingRatio

Added in 1.0.0
fun setDampingRatio(dampingRatio: @FloatRange(from = 0.0) Float): SpringForce!

Spring damping ratio describes how oscillations in a system decay after a disturbance.

When damping ratio >1 (over-damped), the object will quickly return to the rest position without overshooting. If damping ratio equals to 1 (i.e. critically damped), the object will return to equilibrium within the shortest amount of time. When damping ratio is less than 1 (i.e. under-damped), the mass tends to overshoot, and return, and overshoot again. Without any damping (i.e. damping ratio = 0), the mass will oscillate forever.

Default damping ratio is DAMPING_RATIO_MEDIUM_BOUNCY.

Parameters
dampingRatio: @FloatRange(from = 0.0) Float

damping ratio of the spring, it should be non-negative

Returns
SpringForce!

the spring force that the given damping ratio is set on

Throws
java.lang.IllegalArgumentException

if the {@param dampingRatio} is negative.

setFinalPosition

Added in 1.0.0
fun setFinalPosition(finalPosition: Float): SpringForce!

Sets the rest position of the spring.

Parameters
finalPosition: Float

rest position of the spring

Returns
SpringForce!

the spring force that the given final position is set on

setStiffness

Added in 1.0.0
fun setStiffness(stiffness: @FloatRange(from = 0.0, fromInclusive = false) Float): SpringForce!

Sets the stiffness of a spring. The more stiff a spring is, the more force it applies to the object attached when the spring is not at the final position. Default stiffness is STIFFNESS_MEDIUM.

Parameters
stiffness: @FloatRange(from = 0.0, fromInclusive = false) Float

non-negative stiffness constant of a spring

Returns
SpringForce!

the spring force that the given stiffness is set on

Throws
java.lang.IllegalArgumentException

if the given spring stiffness is not positive