Skip to main content

Class: RotarySpringConstraint

physics/constraints/rotarySpring.RotarySpringConstraint

Represents a damped rotary spring joint between two CollisionObjects or a CollisionObject and itself.

This joint will aim to maintain the provided angle between the 2 bodies.

When the joint only consists of one body it will aim to keep that bodies rotation at the specified angle.

Setting anchor points for this constraint will have no affect.

Hierarchy

Constructors

constructor

โ€ข new RotarySpringConstraint(a, b, angle, stiffness, damping?)

Creates a new RotarySpringConstraint between two bodies.

Parameters

NameTypeDescription
aCollisionObjectThe first body
bCollisionObjectThe second body
anglenumberThe resting angle of the spring
stiffnessnumberThe stiffness of the spring
damping?numberThe damping of the spring

Overrides

Constraint.constructor

Defined in

src/physics/constraints/rotarySpring.ts:40

โ€ข new RotarySpringConstraint(opts)

Creates a new SpringConstraint with the given options.

Parameters

NameTypeDescription
optsRotarySpringConstraintOptionsThe constraint options

Overrides

Constraint.constructor

Defined in

src/physics/constraints/rotarySpring.ts:47

โ€ข new RotarySpringConstraint(a, angle, stiffness, damping?)

Creates a new RotarySpringConstraint between a body and a point.

Parameters

NameTypeDescription
aCollisionObjectThe body to constrain
anglenumberThe resting angle of the spring.
stiffnessnumberThe stiffness of the spring
damping?numberThe damping of the spring

Overrides

Constraint.constructor

Defined in

src/physics/constraints/rotarySpring.ts:57

Properties

a

โ€ข a: CollisionObject

Inherited from

Constraint.a

Defined in

src/physics/constraints/constraint.ts:22


anchorA

โ€ข anchorA: vec2

Inherited from

Constraint.anchorA

Defined in

src/physics/constraints/constraint.ts:23


anchorB

โ€ข anchorB: vec2

Inherited from

Constraint.anchorB

Defined in

src/physics/constraints/constraint.ts:27


angle

โ€ข angle: number

Defined in

src/physics/constraints/rotarySpring.ts:22


b

โ€ข b: CollisionObject

Inherited from

Constraint.b

Defined in

src/physics/constraints/constraint.ts:26


damping

โ€ข damping: number

Defined in

src/physics/constraints/rotarySpring.ts:24


errorBias

โ€ข errorBias: number

Inherited from

Constraint.errorBias

Defined in

src/physics/constraints/constraint.ts:32


inertiaSum

โ€ข inertiaSum: number

Defined in

src/physics/constraints/rotarySpring.ts:26


jAcc

โ€ข jAcc: number

Defined in

src/physics/constraints/rotarySpring.ts:29


maxBias

โ€ข maxBias: number = Infinity

Inherited from

Constraint.maxBias

Defined in

src/physics/constraints/constraint.ts:33


maxForce

โ€ข maxForce: number = Infinity

Inherited from

Constraint.maxForce

Defined in

src/physics/constraints/constraint.ts:35


point

โ€ข point: vec2

Inherited from

Constraint.point

Defined in

src/physics/constraints/constraint.ts:30


rotA

โ€ข rotA: number = 0

Inherited from

Constraint.rotA

Defined in

src/physics/constraints/constraint.ts:24


rotB

โ€ข rotB: number = 0

Inherited from

Constraint.rotB

Defined in

src/physics/constraints/constraint.ts:28


stiffness

โ€ข stiffness: number

Defined in

src/physics/constraints/rotarySpring.ts:23


targetWrn

โ€ข targetWrn: number

Defined in

src/physics/constraints/rotarySpring.ts:27


wCoef

โ€ข wCoef: number

Defined in

src/physics/constraints/rotarySpring.ts:28

Methods

applyImpulses

โ–ธ Protected applyImpulses(impulse, direction): void

Parameters

NameType
impulsenumber
directionvec2

Returns

void

Inherited from

Constraint.applyImpulses

Defined in

src/physics/constraints/constraint.ts:111

โ–ธ Protected applyImpulses(impulse): void

Parameters

NameType
impulsevec2

Returns

void

Inherited from

Constraint.applyImpulses

Defined in

src/physics/constraints/constraint.ts:113


biasCoef

โ–ธ Protected biasCoef(dt): number

Calculates the velocity bias coefficient.

Parameters

NameTypeDescription
dtnumberThe time since the last update

Returns

number

Inherited from

Constraint.biasCoef

Defined in

src/physics/constraints/constraint.ts:182


calcTorque

โ–ธ Private calcTorque(): number

Calculates the torque required to correct the spring.

Returns

number

The torque required to correct the spring

Defined in

src/physics/constraints/rotarySpring.ts:140


calculateRelativeVelocity

โ–ธ Protected calculateRelativeVelocity(pointA, pointB): vec2

Calculate the relative velocity of the bodies in the constraint.

Parameters

NameTypeDescription
pointAvec2The anchor point on body a
pointBvec2The anchor point on body b

Returns

vec2

The relative velocity between body a and b or body a and the anchor point

Inherited from

Constraint.calculateRelativeVelocity

Defined in

src/physics/constraints/constraint.ts:164


isBodyToPoint

โ–ธ isBodyToPoint(): boolean

Determines wether or not the constraint is between a body and a point.

Returns

boolean

Wether or not the constraint is between a body and a point.

Inherited from

Constraint.isBodyToPoint

Defined in

src/physics/constraints/constraint.ts:107


kScalar

โ–ธ Protected kScalar(n): number

Computes the k scalar value for the constraint.

Parameters

NameTypeDescription
nvec2The constraint's delta normal

Returns

number

The k scalar value for the constraint

Inherited from

Constraint.kScalar

Defined in

src/physics/constraints/constraint.ts:205


kScalarBody

โ–ธ Protected kScalarBody(body, r, n): number

Computes the k scalar value for the given body.

Parameters

NameTypeDescription
bodyCollisionObjectThe body to calculate for
rvec2The anchor point on the body
nvec2The constraint's delta normal

Returns

number

The k scalar value for the given body

Inherited from

Constraint.kScalarBody

Defined in

src/physics/constraints/constraint.ts:194


kTensor

โ–ธ Protected kTensor(): mat2

Computes the k tensor matrix for the constraint.

see Chipmunk2D kTensor

Returns

mat2

k tensor matrix

Inherited from

Constraint.kTensor

Defined in

src/physics/constraints/constraint.ts:220


postSolve

โ–ธ postSolve(): void

Performs post solve operations.

Returns

void

Overrides

Constraint.postSolve

Defined in

src/physics/constraints/rotarySpring.ts:133


preSolve

โ–ธ preSolve(dt): void

Prepares the spring for solving.

Parameters

NameTypeDescription
dtnumberThe time since the last update

Returns

void

Overrides

Constraint.preSolve

Defined in

src/physics/constraints/rotarySpring.ts:95


solve

โ–ธ solve(dt): void

Applies the spring forces to the attached bodies.

see Chipmunk2D Damped Spring

see Constraints and Solvers

Parameters

NameTypeDescription
dtnumberThe time since the last update

Returns

void

Overrides

Constraint.solve

Defined in

src/physics/constraints/rotarySpring.ts:118


updateAnchors

โ–ธ Protected updateAnchors(): void

Updates the constraint's anchor points to match the rotations of their bodies.

Returns

void

Inherited from

Constraint.updateAnchors

Defined in

src/physics/constraints/constraint.ts:141