Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. double add_physics_vector(vector<double> v1, vector<double> v2)
  2. {
  3. double horizontal_1 = v1[1] * cos(v1[0]);
  4. double vertical_1 = v1[1] * sin(v1[0]);
  5. double horizontal_2 = v2[1] * cos(v2[0]);
  6. double vertical_2 = v2[1] * sin(v2[0]);
  7.  
  8. double horizontal_total = horizontal_1 + horizontal_2;
  9. double vertical_total = vertical_1 + vertical_2;
  10. double final_magnitude = sqrt(pow(horizontal_total, 2) + pow(vertical_total, 2));
  11. double final_direction = atan2(vertical_total, horizontal_total);
  12. double final_set[2] = {final_direction, final_magnitude};
  13. return final_set;
  14. }
  15.  
  16. error: cannot convert ‘double*’ to ‘double’ in return
  17. warning: control reaches end of non-void function [-Wreturn-type]
  18.  
  19. vector<double> final_set = {final_direction, final_magnitude};
  20. return final_set;
  21.  
  22. vector<double> add_physics_vector(vector<double> v1, vector<double> v2);
  23.  
  24. pair<double, double> add_physics_vector(vector<double> v1, vector<double> v2)
  25. {
  26. // ...as before
  27. return make_pair(final_direction, final_magitude);
  28. }
  29.  
  30. double * make_array()
  31. {
  32. double * array = malloc(sizeof(double) * 2);
  33. if (array == NULL) { /* .. error handling */ }
  34. return array;
  35. }
  36.  
  37. struct Vector
  38. {
  39. double direction;
  40. double magnitude;
  41. }
  42.  
  43. Vector make_vector()
  44. {
  45. vector = (Vector){ 1, 2 };
  46. return vector;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement