Joint's Current Distance or angle

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Syntax
Posts: 19
Joined: Wed Jan 05, 2011 6:40 pm

Joint's Current Distance or angle

Post by Syntax »

Hello again. Is there any way to easily and consistently calculate the current distance or angle of an item in respect to a joint?

For example, lets say I have an item with a LineSliderJoint and I have the limits enabled with a minimum of 0 and a maximum of 40, and then I have a motor with a servo activated and it has a goal of 35. I would like to know at any point what the current position of the item is on that line. So that if it starts at 0 I could output the current position in real time as the servo takes it from 0 to 35.

Or let's say I have an item with a RevoluteJoint and I have a similar joint and servo situation as above. I would like to know at any time what the angle is for the joint.

I suppose this calculation could be done by comparing the position or orientation of objectA to the position or orientation of objectB and offset it by the starting position or orientation, but I'm hoping that an easier and neater way to do this is built in to the physics engine.

Thanks!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Joint's Current Distance or angle

Post by Norbo »

Is there any way to easily and consistently calculate the current distance or angle of an item in respect to a joint?
The engine exposes the values it needs for constraint solving, but these aren't always very helpful. For example, the revolute limit is actually implemented using planes and never calculates an angle. The revolute joint angular portion computes things about the restricted degrees of freedom, which aren't the DOF's you care about.

Usually, the best way to compute the desired information is to do it manually using the various constraint data properties. For a LinearAxisMotor, for example, you can compute the position along the line using:

Code: Select all

            float position = Vector3.Dot(motor.AnchorB - motor.AnchorA, motor.Axis);
For a revolute joint, you can get a good approximation of the angle by using:

Code: Select all

            var angle = Math.Acos(Vector3.Dot(Vector3.Normalize(revoluteJoint.BallSocketJoint.OffsetA), Vector3.Normalize(revoluteJoint.BallSocketJoint.OffsetB)));
Or use projections and Atan2 if it's a weirder configuration.
Post Reply