A regular octagon is inscribed in the circle x² + y² = 2, with four of its vertices lying on the coordinate axes. What are the equations of the lines containing the eight sides of the octagon?
r = Sqrt[2];
angles = Table[\[Theta], {\[Theta], 0, 2 \[Pi] - \[Pi]/4, \[Pi]/4}];
vertices =
Table[{r Cos[\[Theta]], r Sin[\[Theta]]}, {\[Theta], angles}];
lines = Table[
With[{p1 = vertices[[i]],
p2 = vertices[[Mod[i, 8] +
1]]}, (y - p1[[2]]) (p2[[1]] - p1[[1]]) == (x -
p1[[1]]) (p2[[2]] - p1[[2]]) // Expand // Simplify], {i, 1,
8}]
The code above is one way to solve the problem using parametric equations in polar coordinates. What other methods could be used?
You could useCirclePoints[{Sqrt[2], 0}, 8] to generate the vertices:
vertices = CirclePoints[{Sqrt[2], 0}, 8];
sides = Partition[vertices, 2, 1, 1];
equations = couples /. {p1_List, p2_} :>
({x, y} - p1) . RotationMatrix[Pi/2] . (p2 - p1) == 0
ContourPlot[equations, {x, -2, 2}, {y, -2, 2},
Epilog -> Circle[{0, 0}, Sqrt[2]]]
mroge02
(Michael Rogers)
August 26, 2025, 12:12am
3
More alternatives for the steps:
Maybe this:
RegularPolygon[{1, Pi/4}, 8] //
CanonicalizePolygon //
Apply@Part //
Partition[#, 2, 1, 1] & //
Map[y == InterpolatingPolynomial[#, x] &]
Or this if have one with vertical and horizontal sides:
RegularPolygon[8] //
CanonicalizePolygon //
Apply@Part //
Partition[#, 2, 1, 1] & //
Map[
Quiet[Check[
y == InterpolatingPolynomial[#, x],
x == InterpolatingPolynomial[Reverse /@ #, y],
InterpolatingPolynomial::ipdup],
InterpolatingPolynomial::ipdup] &
](*//
ToRadicals//
FullSimplify*)
Leveraging built-in functions to extract vertex coordinates is indeed the most efficient approach. Excellent method—thanks!
This approach works perfectly for addressing this issue—thank you!