For two point {x1,y1}
and {x2,y2}
, at first we locate at {x2,y2}
and toward to the direction {x2,y2}-{x1,y2}
, then turn to a new direction by rotate a angle2 Pi/n
, after n
rotation we go back to {x2,y2}
.
{dx, dy} = {x2, y2} - {x1, y1};
length = Sqrt[{dx, dy} . {dx, dy}];
n = 4;
pts = AnglePath[{{x2, y2}, {dx, dy}},
ConstantArray[{length, 2 Pi/n}, n]] // FullSimplify
RotateRight[Most@pts]

{dx, dy} = {x2, y2} - {x1, y1};
length = Sqrt[{dx, dy} . {dx, dy}];
n = 5;
pts = AnglePath[{{x2, y2}, {dx, dy}},
ConstantArray[{length, 2 Pi/n}, n]];
poly = Polygon[pts];
{x1, y1} = {2, 2};
{x2, y2} = {5, 5};
Graphics[{EdgeForm[Black], FaceForm[], poly, AbsolutePointSize[10],
Red, Point[{{x1, y1}}], Text[{x1, y1}, {x1, y1}, {0, 2}], Blue,
Point[{{x2, y2}}], Text[{x2, y2}, {x2, y2}, {-2, 0}]}]

{x1, y1} = {2, 2};
{x2, y2} = {5, 5};
{dx, dy} = {x2, y2} - {x1, y1};
length = Norm[{dx, dy}];
Graphics[
Table[{EdgeForm[RandomColor[]], FaceForm[],
Polygon[AnglePath[{{x2, y2}, {dx, dy}},
ConstantArray[{length, 2 π/n}, n]]]}, {n, 3, 8}]]

NestList
+ RotationMatrix
.
p[1] = {x1, y1} =N@{2, 2};
p[2] = {x2, y2} =N@{5, 5};
n = 5;
θ = (2 π)/n;
lines = NestList[{#[[2]], #[[2]] +
RotationMatrix[θ] . (#[[2]] - #[[1]])} &, {p[1], p[2]},
n];
poly = Polygon[lines[[;; , 2]]];
Graphics[{EdgeForm[Blue], FaceForm[], poly, Arrow@lines,
AbsolutePointSize[10], Red, Point[p[1]], Blue, Point[p[2]]}]

- Using complex number to rotate the vector.
Clear["Global`*"];
z[1] = {x1, y1} . {1, I};
z[2] = {x2, y2} . {1, I};
n = 5;
θ = (2 π)/n;
ω = Exp[I*θ];
z[k_] := z[k] = z[k - 1] + (z[k - 1] - z[k - 2]) ω;
Table[z[k], {k, n}] // ReIm // ComplexExpand
Block[{x1, y1, x2, y2},
{x1, y1} = {2, 2};
{x2, y2} = {5, 5};
Graphics[{RegionBoundary@Polygon[pts], AbsolutePointSize[10], Red,
Point[{x1, y1}], Blue, Point[{x2, y2}]}]]

n = 5;
{dx, dy} = {x2 - x1, y2 - y1};
length = Sqrt[{dx, dy} . {dx, dy}];
pts = FoldList[AngleVector, {x2, y2},
Table[{length, ArcTan[dx, dy] + k (2 π)/n}, {k, n}]] //
FullSimplify
{x1, y1} = {2, 2};
{x2, y2} = {5, 5};
Graphics[Polygon[pts]]
