
Untitled
By: a guest on
Aug 6th, 2012 | syntax:
None | size: 0.60 KB | hits: 14 | expires: Never
Solved, Java, Generate a direct path of points between two points
f(start,end,nPoints) -> (path)
delta = (end-start) / nPoints //Find the best difference vector.
current = start //Set the current point to the start.
i = 0
while(|current-end| < epsilon)
current += delta
path[i] = current
i = i + 1
float ratio = (y2 - y1) / (x2 - x1);
width = x2 - x1;
for(int i = 0; i < width; i++) {
float x = x1 + i;
float y = y1 + (ratio * i);
points.add(new Point(x,y));
}
double dist = Math.sqr((x2 - x1)^2 + (y2 - y1)^2); //obviously wont compile but you get the idea.