Game Development Reference
In-Depth Information
double beta_dot = 0.0;
double beta_dotdot = 0.0;
double J = 1.15; // kg m^2
double I = 0.08; // kg m^2
double Mc = 0.4; // kg
double R = 0.62; // m
double L = 1.1; // m
double S = 0.4*1.1*0.75; // kg m
double g = 9.8; // m/s^2
double theta = gamma - alpha;
double SA = 7.3*0.62*0.5; // kg m
double Qalpha = 100; // N m
double Qbeta = −10; // N m
double a = 0.1*g; // m/s^2
double dt = 0.0025; // s
double time = 0; // s
double Vc = 0;
Next we define two functions that we will use to compute the second time derivatives
of α and β (i.e., ¨ and ¨ ). These functions simply use Equations 1 and 2 solved for ¨ and
¨ , respectively.
ComputeAlphaDotDot , which solves for ¨ , is shown here:
{
double A, B, C, D, F, G;
double num, denom;
A = (J + I + Mc * R * R + 2 * R * S * cos(beta));
B = -(I + R * S * cos(beta));
F = Qalpha - (beta_dot * beta_dot - 2 * alpha_dot * beta_dot) * R * S *
sin(beta) + S * (g * sin(theta + beta) - a * cos(theta + beta))
+ (SA + Mc * R) * (g * sin(theta) - a * cos(theta));
C = B;
D = I;
G = Qbeta - alpha_dot * alpha_dot * R * S * sin(beta) −
S * (g * sin(theta + beta) - a * cos(theta + beta));
num = (F - (B * G / D));
denom = (A-(B*C/D));
return (F - (B * G / D)) / (A-(B*C/D));
}
The local variables A , B , C , D , F , and G are convenience variables used to organize the
terms in Equation 1. This function returns the second derivative of α.