Kinematic Chain
A kinematic chain is composed of rigid line segments.
Each segment is represented using two vectors: base
and span
.
base ----------> tip
span
The segment's tip
is the sum of its base
and span
.
Move segment tip to new position:
segment.moveTipTo(position: Vec2)
// rotate span
const difference = position.clone().subtract(this.base);
this.span.copy(difference.normalize().multiply(this.span.length()));
// move segment
this.base.copy(position).subtract(this.span);
Move entire chain to new position:
chain.moveTipTo(position: Vec2)
for (let i = this.segments.length - 1; i >= 0; i--) {
const segment = this.segments[i]!;
segment.moveTipTo(position);
position = segment.base;
}
Anchor chain at a fixed position:
chain.anchorAt(position: Vec2)
const displacement = this.segments[0]!.base.clone().subtract(position);
for (const segment of this.segments) segment.base.subtract(displacement);
See Also: