question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How to restrict "deflection" of joined bodies

See original GitHub issue

I have the following scenario (also see image):

  • 2 SimulationBody: 1 with “normal” mass (Body B) and the other one is fixed (Body A)
  • They are joined together via RopeJoint so that only a specific area is reachable by Body B

Goal:

  • Body B should be only allowed to take a position in the upper half circle around Body A

Drawing: grafik

Question Is there a Joint already available to accomplish such a behaviour? (AngleLimitation in combination with a RopeJoint)?

My ideas

  1. RevoluteJoint: But this is not applicable in combination with a RopeJoint (at least I couldn’t make it run)
  2. Definition of an angle listener which observes the angle of the RopeJoint after every simulation step --> so far I use the following “calculations” which generates results, which I didn’t expect (from the angle value point of view.
/**
	 * Method call AFTER a SimulationStep is done.
	 */
	@Override
	public void end(Step step, World world)
	{
		// Get the SimulationBodies attached to the Joint
		SimulationBody bodyA = (SimulationBody) this.observedJoint.getBody1();
		SimulationBody bodyB = (SimulationBody) this.observedJoint.getBody2();
		
		
		// Check for JointType
		if(this.observedJoint instanceof RopeJoint)
		{
			// Get the AnchorPoints (current)
			Vector2 anchorA = this.observedJoint.getAnchor1();
			Vector2 anchorB = this.observedJoint.getAnchor2();

			// Calculate the angle in rad
			double currentAngle = anchorA.getAngleBetween(anchorB);
			
			System.out.println("Current Anchor-Angle = " + currentAngle + " (rad) | " + Math.toDegrees(currentAngle) + " (deg).");
			
			// Check if current distance is withhin the maxLength
			if(currentAngle < 0)
			{
				bodyB.setLinearVelocity(new Vector2(0.0, 0.0));
			}
			else
			{
				// Do nothing
			}
		}
	}

There I get values like

  • Current Anchor-Angle = -0.0014672951941631651 (rad) | -0.08406982192537803 (deg).
  • Current Anchor-Angle = 0.16941188466027896 (rad) | 9.706585990391076 (deg).
  • Current Anchor-Angle = 0.007939302723439068 (rad) | 0.4548885383297788 (deg).

But I expected something in-between 0 - 180 deg. Maybe I misunderstood the concept of angle calculation…

  1. Definition of a “repulsion field” grafik (Not tested so far -> I think this is the most “complex” method -> Listener definition and sensor modelling and so on)

But somehow I don’t think that these ideas are target-oriented and easy to maintain.

Is there something I am missing in your library to get the requiered behaviour?

Thank you very much in advance for other ideas or some hints. 😃

I can provide my “test-case” if necessary

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
wnbittlecommented, Jun 3, 2020

If C needs to move with A, things are definitely more complicated. An alternative approach would be to add C as a fixture on the A body and mark it as a sensor. Senors report collisions, but are not resolved. If a collision between the sensor occurs you perform your logic to enforce the constraint.

The Vector2.getAngleBetween(Vector2) method is used to find the angle between two vectors. You are passing two points - the anchor points of the AngleJoint in this case. These are the world space center’s of the bodies A and B.

The output of the Vector2.getAngleBetween(Vector2) method when supplied with points really means that you are getting the angle between the the vectors O->A and O->B where O is the origin. This is because while Vectors and Points use the same Vector2 class in the library, they are two different concepts. In my example below, the green and orange lines represent the O->A and O->B vectors. The angle between the vectors in my example is ~85 degrees.

image

What you really want is the angle between the x-axis of A with the vector from anchorA to anchorB (the purple and black dashed lines in my example). In other words:

// get the world space vector that represents the x-axis of body A
// in local coordinates, A was likely created at the origin so the x-axis vector is (1, 0)
// so we transform that vector into world space
Vector2 xAxisOfA = A.getWorldVector(new Vector2(1.0, 0.0));

// get the world space vector from anchorA to anchorB
Vector2 aToB = angleJoint.getAnchor1().to(angleJoint.getAnchor2());

// get the angle between these two bodies
double theta = xAxisOfA.getAngleBetween(aToB);

// if the angle is negative then we know it's in the region it shouldn't be in
if (theta < 0.0) {
   // do something... 
}
0reactions
NordelDevcommented, Jun 5, 2020

Thany you very much for the help, the very good explanations and your suggestions 😃

The only thing I would avoid is translating/rotating the body manually - I’d rely on velocity and forces/torque.

This is also a very good hit I will keep in mind.

Read more comments on GitHub >

github_iconTop Results From Across the Web

1.7: Deflection of Beams- Geometric Methods
The serviceability requirements limit the maximum deflection that is allowed in a structural element subjected to external loading.
Read more >
Structural deflections : a literature and state-of-the-art survey
Dynamic system deflection is controlled to limit: dynamic whole body vibration audible perception of motion dynamic visual perception to motion.
Read more >
Mechanics of Materials Chapter 6 Deflection of Beams
For this reason, building codes limit the maximum deflection of a beam to about 1/360 th of its spans. double- integration method is...
Read more >
Deflection of Beams - Formula, Methods, Questions
It is very important to limit the deflection of beams as too much deflection might cause damage to other parts of the structures....
Read more >
Structural Beam Stress and Deflection for Non-Engineers
Block and tackle mounted on the beam properly that we are going to use to lift the engine (rated far above 300 lbs)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found