Advertisement
Guest User

Sample

a guest
Jun 1st, 2011
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. H file :
  2.  
  3. typedef struct {
  4.     double angle;
  5.     double force;
  6. } PhysicsInput;
  7.  
  8. typedef struct {
  9.     double airTime;
  10.     double travelDistance;
  11. } SimulationOutput;
  12.  
  13. typedef struct {
  14.     double targetDistance;
  15.     double distanceWeight;
  16.     double airtimeWeight;
  17. } ObjectiveParams;
  18.  
  19. SimulationOutput simulatePhysics(const PhysicsInput& input);
  20. double objectiveFunc(const PhysicsInput& input, const ObjectiveParams& target);
  21.  
  22.  
  23. C file :
  24.  
  25. #include <math.h>
  26. #include "func.h"
  27.  
  28. SimulationOutput simulatePhysics(const PhysicsInput& input)
  29. {
  30.     SimulationOutput output;
  31.     output.airTime = sin(input.angle) * input.force * 9.8 / 2;
  32.     output.travelDistance = output.airTime * cos(input.angle);
  33.     return output;
  34. }
  35.  
  36. double objectiveFunc(const PhysicsInput& input, const ObjectiveParams& target)
  37. {
  38.     SimulationOutput out = simulatePhysics(input);
  39.     double retVal = 0;
  40.     double distanceFromTarget = (out.travelDistance - target.targetDistance);
  41.     retVal += distanceFromTarget * distanceFromTarget * target.distanceWeight;
  42.     retVal += target.airtimeWeight * out.airTime;
  43.     return retVal;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement