C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 16th, 2005, 11:07 AM
Sun Sun is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 24 Sun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 19 sec
Reputation Power: 0
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 ;)

Reply With Quote
  #2  
Old July 16th, 2005, 11:12 AM
Sun Sun is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 24 Sun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 19 sec
Reputation Power: 0
Unhappy Supplmentary information.

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???

Reply With Quote
  #3  
Old July 16th, 2005, 02:54 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 1 m 43 sec
Reputation Power: 4
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.



Reply With Quote
  #4  
Old July 16th, 2005, 08:36 PM
Sun Sun is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 24 Sun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 19 sec
Reputation Power: 0
Red face Further interpretation

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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > How to make the programme work??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT