Class PrismaticJoint
- Namespace
- Alis.Core.Physic.Dynamics.Joints
- Assembly
- Alis.dll
A prismatic joint. This joint provides one degree of freedom: translation along an axis fixed in bodyA. Relative rotation is prevented. You can use a joint limit to restrict the range of motion and a joint motor to drive the motion or to model joint friction.
public class PrismaticJoint : Joint
Inheritance
Inherited Members
Remarks
Linear constraint (point-to-line) d = p2 - p1 = x2 + r2 - x1 - r1 C = dot(perp, d) Cdot = dot(d, cross(w1, perp)) + dot(perp, v2 + cross(w2, r2) - v1 - cross(w1, r1)) = -dot(perp, v1) - dot(cross(d + r1, perp), w1) + dot(perp, v2) + dot(cross(r2, perp), v2) J = [-perp, -cross(d + r1, perp), perp, cross(r2,perp)] Angular constraint C = a2 - a1 + a_initial Cdot = w2 - w1 J = [0 0 -1 0 0 1] K = J * invM * JT J = [-a -s1 a s2] [0 -1 0 1] a = perp s1 = cross(d + r1, a) = cross(p2 - x1, a) s2 = cross(r2, a) = cross(p2 - x2, a) Motor/Limit linear constraint C = dot(ax1, d) Cdot = = -dot(ax1, v1) - dot(cross(d + r1, ax1), w1) + dot(ax1, v2) + dot(cross(r2, ax1), v2) J = [-ax1 -cross(d+r1,ax1) ax1 cross(r2,ax1)] Block Solver We develop a block solver that includes the joint limit. This makes the limit stiff (inelastic) even when the mass has poor distribution (leading to large torques about the joint anchor points). The Jacobian has 3 rows: J = [-uT -s1 uT s2] // linear [0 -1 0 1] // angular [-vT -a1 vT a2] // limit u = perp v = axis s1 = cross(d + r1, u), s2 = cross(r2, u) a1 = cross(d + r1, v), a2 = cross(r2, v) M * (v2 - v1) = JT * df J * v2 = bias v2 = v1 + invM * JT * df J * (v1 + invM * JT * df) = bias K * df = bias - J * v1 = -Cdot K = J * invM * JT Cdot = J * v1 - bias Now solve for f2. df = f2 - f1 K * (f2 - f1) = -Cdot f2 = invK * (-Cdot) + f1 Clamp accumulated limit impulse. lower: f2(3) = max(f2(3), 0) upper: f2(3) = min(f2(3), 0) Solve for correct f2(1:2) K(1:2, 1:2) * f2(1:2) = -Cdot(1:2) - K(1:2,3) * f2(3) + K(1:2,1:3) * f1 = -Cdot(1:2) - K(1:2,3) * f2(3) + K(1:2,1:2) * f1(1:2) + K(1:2,3) * f1(3) K(1:2, 1:2) * f2(1:2) = -Cdot(1:2) - K(1:2,3) * (f2(3) - f1(3)) + K(1:2,1:2) * f1(1:2) f2(1:2) = invK(1:2,1:2) * (-Cdot(1:2) - K(1:2,3) * (f2(3) - f1(3))) + f1(1:2) Now compute impulse to be applied: df = f2 - f1
Constructors
PrismaticJoint()
Initializes a new instance of the Alis.Core.Physic.Dynamics.Joints.PrismaticJoint class
internal PrismaticJoint()
PrismaticJoint(Body, Body, Vector2, Vector2, Vector2, bool)
This requires defining a line of motion using an axis and an anchor point. The definition uses local anchor points and a local axis so that the initial configuration can violate the constraint slightly. The joint translation is zero when the local anchor points coincide in world space. Using local anchors and a local axis helps when saving and loading a game.
public PrismaticJoint(Body bodyA, Body bodyB, Vector2 anchorA, Vector2 anchorB, Vector2 axis, bool useWorldCoordinates = false)
Parameters
bodyA
Body-
The first body.
bodyB
Body-
The second body.
anchorA
Vector2-
The first body anchor.
anchorB
Vector2-
The second body anchor.
axis
Vector2-
The axis.
useWorldCoordinates
bool-
Set to true if you are using world coordinates as anchors.
PrismaticJoint(Body, Body, Vector2, Vector2, bool)
Initializes a new instance of the Alis.Core.Physic.Dynamics.Joints.PrismaticJoint class
public PrismaticJoint(Body bodyA, Body bodyB, Vector2 anchor, Vector2 axis, bool useWorldCoordinates = false)
Parameters
bodyA
Body-
The body
bodyB
Body-
The body
anchor
Vector2-
The anchor
axis
Vector2-
The axis
useWorldCoordinates
bool-
The use world coordinates
Fields
_a1
The
private float _a1
Field Value
_a2
The
private float _a2
Field Value
_axis
The perp
private Vector2 _axis
Field Value
_axis1
The axis
private Vector2 _axis1
Field Value
_enableLimit
The enable limit
private bool _enableLimit
Field Value
_enableMotor
The enable motor
private bool _enableMotor
Field Value
_impulse
The impulse
private Vector3 _impulse
Field Value
_indexA
The index
private int _indexA
Field Value
_indexB
The index
private int _indexB
Field Value
_invMassA
The inv mass
private float _invMassA
Field Value
_invMassB
The inv mass
private float _invMassB
Field Value
_limitState
The limit state
private LimitState _limitState
Field Value
_localCenterA
The local center
private Vector2 _localCenterA
Field Value
_localCenterB
The local center
private Vector2 _localCenterB
Field Value
_localXAxis
The local axis
private Vector2 _localXAxis
Field Value
_localYAxisA
The local axis
private Vector2 _localYAxisA
Field Value
_lowerTranslation
The lower translation
private float _lowerTranslation
Field Value
_maxMotorForce
The max motor force
private float _maxMotorForce
Field Value
_motorMass
The motor mass
private float _motorMass
Field Value
_motorSpeed
The motor speed
private float _motorSpeed
Field Value
_perp
The perp
private Vector2 _perp
Field Value
_s1
The
private float _s1
Field Value
_s2
The
private float _s2
Field Value
_upperTranslation
The upper translation
private float _upperTranslation
Field Value
invIa
The inv ia
private float invIa
Field Value
invIb
The inv ib
private float invIb
Field Value
k
The
private Mat33 k
Field Value
Properties
Axis1
The axis at which the joint moves.
public Vector2 Axis1 { get; set; }
Property Value
JointSpeed
Get the current joint translation speed, usually in meters per second.
public float JointSpeed { get; }
Property Value
JointTranslation
Get the current joint translation, usually in meters.
public float JointTranslation { get; }
Property Value
LimitEnabled
Is the joint limit enabled?
public bool LimitEnabled { get; set; }
Property Value
LocalAnchorA
The local anchor point on BodyA
public Vector2 LocalAnchorA { get; set; }
Property Value
LocalAnchorB
The local anchor point on BodyB
public Vector2 LocalAnchorB { get; set; }
Property Value
LocalXAxis
The axis in local coordinates relative to BodyA
public Vector2 LocalXAxis { get; }
Property Value
LowerLimit
Get the lower joint limit, usually in meters.
public float LowerLimit { get; set; }
Property Value
MaxMotorForce
Set the maximum motor force, usually in N.
public float MaxMotorForce { get; set; }
Property Value
MotorEnabled
Is the joint motor enabled?
public bool MotorEnabled { get; set; }
Property Value
MotorImpulse
Get the current motor impulse, usually in N.
public float MotorImpulse { get; set; }
Property Value
MotorSpeed
Set the motor speed, usually in meters per second.
public float MotorSpeed { get; set; }
Property Value
ReferenceAngle
The reference angle.
public float ReferenceAngle { get; set; }
Property Value
UpperLimit
Get the upper joint limit, usually in meters.
public float UpperLimit { get; set; }
Property Value
WorldAnchorA
Gets or sets the value of the world anchor a
public override Vector2 WorldAnchorA { get; set; }
Property Value
WorldAnchorB
Gets or sets the value of the world anchor b
public override Vector2 WorldAnchorB { get; set; }
Property Value
Methods
GetMotorForce(float)
Gets the motor force.
public float GetMotorForce(float invDt)
Parameters
invDt
float-
The inverse delta time
Returns
GetReactionForce(float)
Gets the reaction force using the specified inv dt
public override Vector2 GetReactionForce(float invDt)
Parameters
invDt
float-
The inv dt
Returns
- Vector2
-
The vector
GetReactionTorque(float)
Gets the reaction torque using the specified inv dt
public override float GetReactionTorque(float invDt)
Parameters
invDt
float-
The inv dt
Returns
- float
-
The float
InitVelocityConstraints(ref SolverData)
Inits the velocity constraints using the specified data
internal override void InitVelocityConstraints(ref SolverData data)
Parameters
data
SolverData-
The data
Initialize(Vector2, Vector2, Vector2, bool)
Initializes the local anchor a
private void Initialize(Vector2 localAnchorA, Vector2 localAnchorB, Vector2 axis, bool useWorldCoordinates)
Parameters
localAnchorA
Vector2-
The local anchor
localAnchorB
Vector2-
The local anchor
axis
Vector2-
The axis
useWorldCoordinates
bool-
The use world coordinates
SetLimits(float, float)
Set the joint limits, usually in meters.
public void SetLimits(float lower, float upper)
Parameters
SolvePositionConstraints(ref SolverData)
Describes whether this instance solve position constraints
internal override bool SolvePositionConstraints(ref SolverData data)
Parameters
data
SolverData-
The data
Returns
- bool
-
The bool
SolveVelocityConstraints(ref SolverData)
Solves the velocity constraints using the specified data
internal override void SolveVelocityConstraints(ref SolverData data)
Parameters
data
SolverData-
The data