我已经从这个Javascript 答案修改了这个答案。
他们有“空”,我用零代替。
但是,它有很多小故障。
public ArrayList<Point> getListOfIntermediatePoints(Point A, Point B ){
float m = slope(A, B);
int C = (int) intercept(A, m);
ArrayList<Point> coordinates = new ArrayList<Point>();
for (int i = A.x; i <= B.x; i++) {
float j = m * i + C; //y = mx + c;
coordinates.add(new Point(i,(int) j));
}
Log.d("coordinates", coordinates+"");
return coordinates;
}
public float slope(Point a, Point b) {
if (a.x == b.x) {
return 0;
}
return (b.y - a.y) / (b.x - a.x);
}
float intercept(Point A, float slope) {
if (slope == 0) {
// vertical line
return A.x;
}
return A.y - slope * A.x;
}