How do I find points on the line segment joining {-4, 11}
and {16, -1}
whose coordinates are positive integers?
Answer
Is this what you are searching for?
a = {-4, 11};
b = {16, -1};
dy = (b[[2]] - a[[2]])/(b[[1]] - a[[1]]);
offset = u /. Solve[a[[2]] == dy*a[[1]] + u, u][[1]];
coords = {x,
y} /. {Reduce[y == dy*x + offset && x > 0 && y > 0, {x, y},
Integers] // ToRules}
(* {{1, 8}, {6, 5}, {11, 2}} *)
Graphics[{PointSize[Large], Point[{a, b}], Red, Point[coords],
Line[{a, b}]}, Axes -> True, GridLines -> {Range[16], Range[16]},
ImageSize -> 640]
Comments
Post a Comment