Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- H file :
- typedef struct {
- double angle;
- double force;
- } PhysicsInput;
- typedef struct {
- double airTime;
- double travelDistance;
- } SimulationOutput;
- typedef struct {
- double targetDistance;
- double distanceWeight;
- double airtimeWeight;
- } ObjectiveParams;
- SimulationOutput simulatePhysics(const PhysicsInput& input);
- double objectiveFunc(const PhysicsInput& input, const ObjectiveParams& target);
- C file :
- #include <math.h>
- #include "func.h"
- SimulationOutput simulatePhysics(const PhysicsInput& input)
- {
- SimulationOutput output;
- output.airTime = sin(input.angle) * input.force * 9.8 / 2;
- output.travelDistance = output.airTime * cos(input.angle);
- return output;
- }
- double objectiveFunc(const PhysicsInput& input, const ObjectiveParams& target)
- {
- SimulationOutput out = simulatePhysics(input);
- double retVal = 0;
- double distanceFromTarget = (out.travelDistance - target.targetDistance);
- retVal += distanceFromTarget * distanceFromTarget * target.distanceWeight;
- retVal += target.airtimeWeight * out.airTime;
- return retVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement