# How can I select all pair of two points A and B has integer coordinates and length of AB is also integer?

I have sphere $$(x-1)^2 + (y-2)^2 + (z-3)^2 = 81$$. To select two points $$A$$, $$B$$ on sphere so that coordinates of $$A$$, $$B$$ are six different integer numbers and $$AB = 18$$, $$xyz \neq 0$$ I tried.

ClearAll[a, b, r, c];
a = 1;
b = 2;
c = 3;
r = 9; ss = Subsets[{x, y, z} /.
Solve[{(x \[Minus] a)^2 + (y \[Minus] b)^2 + (z \[Minus] c)^2 ==
r^2, x y z != 0}, {x, y, z}, Integers], {2}];
t = Select[ss, And @@ Unequal @@@ Subsets[Flatten[#], {2}] &];
Select[t, Apply[EuclideanDistance, #] == 18 &]


My question: besides $$AB = 18$$, are there any other integers of $$AB$$?

• Solve[{(x [Minus] 2)^2 + (y [Minus] 4)^2 + (z [Minus] 6)^2 == 81}, {x, y, z}, PositiveIntegers] Commented Aug 9 at 6:33
• @Ghoster Thank you very much. Commented Aug 10 at 2:43

## 3 Answers

Yes. You can find many other integral points using FindInstance[]:

ClearAll[x,y,z];
intpoints={x,y,z}/.FindInstance[(x-1)^2+(y-2)^2+(z-3)^2==81,
{x,y,z},Integers,999999];
Short[intpoints]

(* {{-8,2,3},{-7,-2,2},{-7,-2,4},{-7,1,-1},{-7,1,7},{-7,3,-1},{-7,3,7},
{-7,6,2},{-7,6,4},{-6,-2,-1},{-6,-2,7},{-6,6,-1},{-6,6,7},{-5,-4,0},
{-5,-4,6},{-5,-1,-3},{-5,-1,9},<<68>>,{7,5,-3},{7,5,9},{7,8,0},
{7,8,6},{8,-2,-1},{8,-2,7},{8,6,-1},{8,6,7},{9,-2,2},{9,-2,4},{9,1,-1},
{9,1,7},{9,3,-1},{9,3,7},{9,6,2},{9,6,4},{10,2,3}} *)


Then it is easy to see there are other integers of 𝐴𝐵:

Union[EuclideanDistance @@@ Tuples[intpoints, {2}]]


Select[%, IntegerQ]

(* {0, 2, 6, 8, 12, 14, 16, 18} *)


To select AB=18 pairs,

ans = Select[Tuples[intpoints, {2}], (EuclideanDistance @@ #) == 18 &];
Short[ans]

(* {{{-8,2,3},{10,2,3}},{{-7,-2,2},{9,6,4}},{{-7,-2,4},{9,6,2}},{{-7,1,-1},{9,3,7}},{{-7,1,7},{9,3,-1}},{{-7,3,-1},{9,1,7}},{{-7,3,7},{9,1,-1}},{{-7,6,2},{9,-2,4}},<<86>>,{{9,-2,4},{-7,6,2}},{{9,1,-1},{-7,3,7}},{{9,1,7},{-7,3,-1}},{{9,3,-1},{-7,1,7}},{{9,3,7},{-7,1,-1}},{{9,6,2},{-7,-2,4}},{{9,6,4},{-7,-2,2}},{{10,2,3},{-8,2,3}}}*)


First, find all 102 points on the surface of the sphere that have only integer coordinates, then select end-points of the 40 lines with length 18 and no duplicated coordinates.

\[ScriptCapitalR] = Sphere[{1, 2, 3}, 9];
pts = {x, y, z} /. Solve[RegionMember[\[ScriptCapitalR], {x, y, z}] /.
Reals -> Integers, {x, y, z}];
lines = Pick[##, Unequal @@@ Flatten/@##] &@
Cases[Subsets[pts,{2}], pp_ /;
Apply[EuclideanDistance, pp] == 18]


Find other values of AB that have solutions:

Pick[Range[18],
Table[
Length[Pick[##, Unequal @@@ Flatten /@ ##] &@
Cases[Subsets[pts, {2}],
pp_/; Apply[EuclideanDistance, pp] == d]] > 0,
{d, Range[18]}]]
(* {6, 12, 18} *)

• My question: besides AB=18 , are there any other integers of AB ? Commented Aug 9 at 7:18

Find all integer-valued points on the sphere excluding $$x y z \ne 0$$, then choose pairs with no duplicate values and distance of 18:

SolveValues[
Element[{x, y, z}, Sphere[{1, 2, 3}, 9]] && x y z != 0,
{x, y, z}, Integers] //
Subsets[#, {2}] & // Select[Unequal @@ Flatten@# &] //
Select[EuclideanDistance @@ # == 18 &]

(* ... *)


Measure distances of point pairs with unique coordinate values and find those which are integer-valued, deduplicating and sorting the result:

SolveValues[
Element[{x, y, z}, Sphere[{1, 2, 3}, 9]] && x y z != 0,
{x, y, z}, Integers] //
Subsets[#, {2}] & // Select[Unequal @@ Flatten@# &] //
MapApply@EuclideanDistance // Select@IntegerQ //
DeleteDuplicates // Sort

(*  {6, 12, 18} *)