Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

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