Java API中似乎沒有任何東西讓Bresenham算法的用戶可見。 So I wrote a class that iterates over a line.
您可以使用它像這樣:
List<Point2D> points = new ArrayList<Point2D>();
Line2D line = new Line2D.Double(0, 0, 8, 4);
Point2D current;
for (Iterator<Point2D> it = new LineIterator(line); it.hasNext();) {
current = it.next();
points.add(current);
}
assertThat(points.toString(),
is("[Point2D.Double[0.0, 0.0], Point2D.Double[1.0, 0.0], " +
"Point2D.Double[2.0, 1.0], Point2D.Double[3.0, 1.0], " +
"Point2D.Double[4.0, 2.0], Point2D.Double[5.0, 2.0], " +
"Point2D.Double[6.0, 3.0], Point2D.Double[7.0, 3.0], " +
"Point2D.Double[8.0, 4.0]]"));
非常感謝你,讓你的所有觀點符合要求的邏輯都很棒。而且它對我來說工作得非常好。 – Jay 2012-08-22 10:49:33
謝謝!你救了我幾個小時! – rpax 2014-11-28 10:09:19