Guest User

Untitled

a guest
Oct 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. preprocessing:
  2. input: pts, an array of N points indicating a piecewise
  3. linear path.
  4.  
  5. distances[0] = 0.0;
  6. for i = 1 to N-1
  7. distances[i] = distances[i-1] + dist(pts[i], pts[i-1]);
  8.  
  9. L = lengths[N-1]; // total length of the path.
  10.  
  11. main program:
  12. input:
  13. input: pts, an array of N points indicating a piecewise
  14. linear path.
  15. f, a fraction between 0 and 1.
  16. L, the total length of the path
  17. distances, an array of distances along the path.
  18.  
  19. output: q, a point along the path that's f of the way from
  20. pts[0] to pts[N-1].
  21.  
  22. target = f * L; // the distance we want to go.
  23. i = 0;
  24. while (lengths[i] < target) i = i + 1;
  25.  
  26. // Now lengths[i-1] < target <= lengths[i]
  27. u = pts[i-1];
  28. v = pts[i];
  29. h = lengths[i] - lengths[i-1]; // distance between the pts
  30. r = target - lengths[i-1]; // distance still to be covered.
  31. t = r/h; // fraction of the distance from u to v we have to go.
  32. q = (1-t) * u + t * v;
Add Comment
Please, Sign In to add comment