| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to make the programme work??
Hi everyone,
I copy a C programme from a test book. And I compile and run the programme, I found that there is something I cannot understand. The KneeX and hipX should be zero ( from simple calculation ) but the programme doesn't calculate them as zero. ( in fact, a long double very close to zero ). Why?? Also, how to make the programme to calculate them to zero?? Thank you for your attention. Code:
/* This is "lifter.c", written to accompany Introduction to
Scientific Programming.*/
/* This program solves the kinematics of a weightlifting robot
*/
#include <stdio.h>
#include <math.h>
main ( )
{
int shin, /* The lengths of the shin, thigh, and */
thigh, /* torso in millimeters. m is to end programme */
torso,
m ;
double kneeX, /* The x-y coordinates of the knee and hip, and */
kneeY, /* the y-coordinate of the shoulder. The origin */
hipX, /* of the coordinate system is at the ankle, and */
hipY, /* the x-coordinate of the shoulder is */
shoulderY; /* constrained to be zero. */
double ankleAngle, /* The angles in degrees formed by ground and */
kneeAngle, /* shin (ankle), shin and thigh (knee), and thigh */
hipAngle; /* and torso (hip). */
double alpha, /* The measurements in radians of the angles from */
beta, /* Figure 11.2 of the text. */
gamma;
double pi; /* The value of pi. */
/* We begin by prompting for "kneeAngle" and "torso". */
printf("Enter knee angle (deg): ");
scanf("%lf", &kneeAngle);
printf("Enter torso length (mm): ");
scanf("%d", &torso);
/* We calculate pi using arccos. This works because cos(pi) = -1. */
pi = acos (-1);
/* We assumed these relationships when developing the model in
Chapter 11. */
ankleAngle = kneeAngle / 2;
thigh = 0.67 * torso;
shin = 0.59 * torso;
/* We calculate "alpha" and the knee coordinates ... */
alpha = (ankleAngle / 180) * pi;
kneeX = shin * cos(alpha);
kneeY = shin * sin(alpha);
/* ... "beta" and the hip coordinates ... */
beta = (kneeAngle / 180) * pi - alpha;
hipX = kneeX - thigh * cos(beta);
hipY = kneeY + thigh * sin(beta);
/* ... and "gamma", "hipAngle", and the shoulder coordinate. */
gamma = acos(-hipX/torso);
hipAngle = ((gamma + beta) / pi) * 180;
shoulderY = hipY + torso * sin(gamma);
/* Finally, we display our results. */
printf("\nTorso = %d mm\n", torso);
printf("Thigh = %d mm\n", thigh);
printf("Shin = %d mm\n", shin);
printf(" pi = %g \n", pi);
printf("\nAnkle angle = %g deg\n", ankleAngle);
printf(" X = %g mm\n", 0.0);
printf(" Y = %g mm\n", 0.0);
printf("\nKnee angle = %g deg\n", kneeAngle);
printf(" X = %g mm\n", kneeX);
printf(" Y = %g mm\n", kneeY);
printf("\nHip angle = %g deg\n", hipAngle);
printf(" X = %g mm\n", hipX);
printf(" Y = %g mm\n", hipY);
printf("\nShoulder X = %g mm\n", 0.0);
printf(" Y = %g mm\n\n\n\n", shoulderY);
printf("press x to exit :");
scanf("%d", m);
}
Last edited by B-Con : July 16th, 2005 at 02:27 PM. Reason: Don't forget your [code] tags ;) |
|
#2
|
|||
|
|||
|
When compile and run the programme .....
We input Knee angle = 180 torso length = 686 the result is show knee angle = 180 X = 2.4737e-014 mm Y = 404 mm Hip angle = 180 X = -3.36767e-015 mm Y = 863 mm Why ??? KneeX and HipX not equal to zero??? |
|
#3
|
||||
|
||||
|
Based on the math that I looked at, it looks like kneeX and hipX don't necessarily have to be 0.... why do you think they should?
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
|
#4
|
|||
|
|||
|
Well, my question is when I input the knee Angle = 180 degree (the beginning position ) , the KneeX and HipX should be zero. But, the programme calculate a small value which is not zero.
So, I don't know why this happen? Is that the pi is not correctly definite? And I don't know how to make the programme work ( i.e. input knee angle = 180, the calculated KneeX and HipX is 0 ) By the way, the KneeY, and HipY, and shoulderY is correctly calculated. only the X co-ordinate is not work when knee angle = 180. I am puzzled?? Thank you so much for your attention. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > How to make the programme work?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|