Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- preprocessing:
- input: pts, an array of N points indicating a piecewise
- linear path.
- distances[0] = 0.0;
- for i = 1 to N-1
- distances[i] = distances[i-1] + dist(pts[i], pts[i-1]);
- L = lengths[N-1]; // total length of the path.
- main program:
- input:
- input: pts, an array of N points indicating a piecewise
- linear path.
- f, a fraction between 0 and 1.
- L, the total length of the path
- distances, an array of distances along the path.
- output: q, a point along the path that's f of the way from
- pts[0] to pts[N-1].
- target = f * L; // the distance we want to go.
- i = 0;
- while (lengths[i] < target) i = i + 1;
- // Now lengths[i-1] < target <= lengths[i]
- u = pts[i-1];
- v = pts[i];
- h = lengths[i] - lengths[i-1]; // distance between the pts
- r = target - lengths[i-1]; // distance still to be covered.
- t = r/h; // fraction of the distance from u to v we have to go.
- q = (1-t) * u + t * v;
Add Comment
Please, Sign In to add comment