我已经从this Javascript回答修改了这个答案。
他们有“null”,我将其替换为零。
但是,它有很多故障。
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;
}