matter-js icon indicating copy to clipboard operation
matter-js copied to clipboard

Angle constraints

Open liabru opened this issue 4 years ago • 4 comments

angle-constraints

Work in progress, this feature and API is subject to change.

Features

  • builds on Matter.Constraint
  • distance or pin supported
  • angles for one or both constraint points
  • angle stiffness, angle-min and angle-max bounds
  • global-relative angle for world points
  • body-relative angle for body points

Usage

See the Angle Constraints example for usage. The new constraint properties are:

  • constraint.angleA the target angle at point A (body-relative or world-relative depending on usage) (default 0 or initial angle between points and x-axis)
  • constraint.angleAMin min bound, anti-clockwise relative to angleA (radians, default 0)
  • constraint.angleAMax max bound, clockwise relative to angleA (radians, default 0)
  • constraint.angleAStiffness the angle stiffness (0 to 1, default 1)
  • constraint.angleB...
  • constraint.render.angles boolean to render angles when using Matter.Render (default true)

Angles are either relative to the body, or to the world (x-axis), depending on what the constraint is connected to. For example:

  • if constraint.bodyA is set, then constraint.angleA is relative to the body angle
  • if constraint.pointA is set, then constraint.angleA is relative to the world

Requesting reviewers, testers and comments

If anybody has any time to help me test this update out further and feedback any issues and test cases, it would be greatly appreciated.

You can try out this feature by using the alpha build on this branch.

Known issues

  • chains of angle constraints have issues
  • some configurations can build up extra energy when moving around rapidly
    • possibly a mouse constraint issue only

Breaking changes

  • the original internal property constraint.angleA is now constraint.angleAPrev (same for B)

Changes

  • adds angle properties to Matter.Constraint objects
  • adds angle constraints example
  • adds angle constraint solving to Matter.Constraint module
  • adds angle constraint rendering to Matter.Render
  • adds Common.angleDiff, Common.clampAngle

liabru avatar Mar 11 '20 22:03 liabru

Awesome!!!

While trying this out I ran into a small problem, if I try to make a pin constraint (length=0, stiffness>0.1) constrained by angles, the debug renderer breaks in Render.constraints as it's unable to draw a line to end.x, end.y as end is never set.

Prokos avatar Apr 03 '20 07:04 Prokos

@Prokos good catch, I couldn't reproduce the issue as I'm not sure on the setup required for it but I've accounted for that

liabru avatar Dec 30 '20 14:12 liabru

Hi @liabru is this one dead? What is missing? This would be a killer feature.

CarstenHoyer avatar Dec 05 '23 20:12 CarstenHoyer

Gonna have to bump this. This allows for axels and pins which were previously missing

SollyBunny avatar Dec 31 '23 22:12 SollyBunny