Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 22nd, 2011  |  syntax: C  |  size: 0.59 KB  |  views: 45  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define PI 3.14159265
  6.  
  7. #define DEG2RAD(x) (x*PI/180)
  8. #define RAD2DEG(x) (x*180/PI)
  9.  
  10. #define dt 0.00001
  11. #define w 15
  12. #define maxBoat 5.0
  13. #define riverDrag 3.0
  14.  
  15. int main(void) {
  16.         float t = 0;
  17.         float x = 0, y = 0;
  18.         float vx = -riverDrag, vy = maxBoat;
  19.         float cx = 0, cy = 0;
  20.         float theta = 0;
  21.        
  22.         for(t = 0;y<w;t+=dt) {         
  23.                 x += (vx * dt);
  24.                 y += (vy * dt);
  25.                
  26.                 theta = -atan((w - y) / x);
  27.                 vx = -riverDrag + maxBoat * cos(theta);
  28.                 vy = maxBoat * sin(theta);
  29.                
  30.                 printf("%f,%f,%f\n", t,x, y);
  31.         }
  32.        
  33.         return 0;
  34. }
  35.