Ejemplo n.º 1
0
        List <JacobianConstraint> GetAnguarLimit(
            IShape simulationObjectA,
            IShape simulationObjectB,
            Vector3d sliderAxis,
            double errorReduction)
        {
            var angularConstraints = new List <JacobianConstraint>();

            if (AngularLimitMin.HasValue &&
                AngularLimitMax.HasValue)
            {
                double angle = JacobianCommon.GetAngle(
                    simulationObjectA,
                    simulationObjectB,
                    RelativeOrientation,
                    PistonAxis);

                JacobianConstraint?jContact =
                    JacobianCommon.GetAngularLimit(
                        angle,
                        errorReduction,
                        0.0,
                        simulationObjectA,
                        simulationObjectB,
                        sliderAxis,
                        AngularLimitMin.Value,
                        AngularLimitMax.Value);

                if (jContact != null)
                {
                    angularConstraints.Add(jContact.Value);
                }
            }

            return(angularConstraints);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds the hinge joint.
        /// </summary>
        /// <returns>The hinge joint.</returns>
        /// <param name="simulationObjs">Simulation objects.</param>
        public override List <JacobianConstraint> BuildJacobian()
        {
            var hingeConstraints = new List <JacobianConstraint> ();

            IShape simulationObjectA = ShapeA;
            IShape simulationObjectB = ShapeB;

            #region Init Linear

            Vector3d axisRotated = GetHingeAxis();

            Vector3d t1 = GeometryUtils.GetPerpendicularVector(axisRotated).Normalize();
            Vector3d t2 = axisRotated.Cross(t1).Normalize();

            Vector3d r1 = simulationObjectA.RotationMatrix *
                          StartErrorAxis1;

            Vector3d r2 = simulationObjectB.RotationMatrix *
                          StartErrorAxis2;

            Matrix3x3 skewP1 = Matrix3x3.GetSkewSymmetricMatrix(r1);
            Matrix3x3 skewP2 = Matrix3x3.GetSkewSymmetricMatrix(r2);

            Vector3d p1 = simulationObjectA.Position + r1;
            Vector3d p2 = simulationObjectB.Position + r2;

            Vector3d linearError = p2 - p1;

            #endregion

            #region Init Angular

            Vector3d angularError = JacobianCommon.GetFixedAngularError(
                simulationObjectA,
                simulationObjectB,
                RelativeOrientation);

            #endregion

            #region Jacobian Constraint

            double errorReduction    = ErrorReductionParam;
            double springCoefficient = SpringCoefficient;

            #region Base Constraint

            ConstraintType constraintType = ConstraintType.Joint;

            if (SpringCoefficient > 0)
            {
                constraintType = ConstraintType.SoftJoint;
            }

            //DOF 1

            double constraintLimit = errorReduction * linearError.x;

            hingeConstraints.Add(JacobianCommon.GetDOF(
                                     xVec,
                                     xVecNeg,
                                     new Vector3d(-skewP1.r1c1, -skewP1.r1c2, -skewP1.r1c3),
                                     new Vector3d(skewP2.r1c1, skewP2.r1c2, skewP2.r1c3),
                                     simulationObjectA,
                                     simulationObjectB,
                                     0.0,
                                     constraintLimit,
                                     springCoefficient,
                                     0.0,
                                     constraintType));

            //DOF 2

            constraintLimit = errorReduction * linearError.y;

            hingeConstraints.Add(JacobianCommon.GetDOF(
                                     yVec,
                                     yVecNeg,
                                     new Vector3d(-skewP1.r2c1, -skewP1.r2c2, -skewP1.r2c3),
                                     new Vector3d(skewP2.r2c1, skewP2.r2c2, skewP2.r2c3),
                                     simulationObjectA,
                                     simulationObjectB,
                                     0.0,
                                     constraintLimit,
                                     springCoefficient,
                                     0.0,
                                     constraintType));

            //DOF 3

            constraintLimit = errorReduction * linearError.z;

            hingeConstraints.Add(JacobianCommon.GetDOF(
                                     zVec,
                                     zVecNeg,
                                     new Vector3d(-skewP1.r3c1, -skewP1.r3c2, -skewP1.r3c3),
                                     new Vector3d(skewP2.r3c1, skewP2.r3c2, skewP2.r3c3),
                                     simulationObjectA,
                                     simulationObjectB,
                                     0.0,
                                     constraintLimit,
                                     springCoefficient,
                                     0.0,
                                     constraintType));

            //DOF 4

            double angularLimit = errorReduction *
                                  t1.Dot(angularError);

            hingeConstraints.Add(
                JacobianCommon.GetDOF(
                    -1.0 * t1,
                    1.0 * t1,
                    simulationObjectA,
                    simulationObjectB,
                    0.0,
                    angularLimit,
                    springCoefficient,
                    0.0,
                    constraintType));

            //DOF 5

            angularLimit = errorReduction *
                           t2.Dot(angularError);

            hingeConstraints.Add(
                JacobianCommon.GetDOF(
                    -1.0 * t2,
                    1.0 * t2,
                    simulationObjectA,
                    simulationObjectB,
                    0.0,
                    angularLimit,
                    springCoefficient,
                    0.0,
                    constraintType));

            #endregion

            #region Limit Constraints

            if (AngularLimitMin.HasValue &&
                AngularLimitMax.HasValue)
            {
                double angle = JacobianCommon.GetAngle(
                    simulationObjectA,
                    simulationObjectB,
                    RelativeOrientation,
                    HingeAxis);

                JacobianConstraint?jContact =
                    JacobianCommon.GetAngularLimit(
                        angle,
                        errorReduction,
                        0.0,
                        simulationObjectA,
                        simulationObjectB,
                        axisRotated,
                        AngularLimitMin.Value,
                        AngularLimitMax.Value);

                if (jContact != null)
                {
                    hingeConstraints.Add(jContact.Value);
                }
            }

            #endregion

            #region Motor Contraint

            if (SpeedValue.HasValue &&
                ForceLimit.HasValue)
            {
                hingeConstraints.Add(
                    JacobianCommon.GetDOF(
                        -1.0 * axisRotated,
                        1.0 * axisRotated,
                        simulationObjectA,
                        simulationObjectB,
                        SpeedValue.Value,
                        0.0,
                        0.0,
                        ForceLimit.Value,
                        ConstraintType.JointMotor));
            }

            #endregion

            #endregion

            return(hingeConstraints);
        }