Reputation: 4418
How to get 8 coordinates for octagon? I have the following data regarding octagon -
length of the octagon side.
starting point.
Now I need to know how to get the 8 coordinates of the octagon.
Upvotes: 3
Views: 8948
Reputation: 116160
Fortunately, an octagon can be a relatively easy shape, because the lines are orthogonal or diagonally at 45 degrees (provided you're not going to rotate it over arbitrary angles).
So you don't need very complex calculations. For a triangle with a right angle and two sides of the same length Y
, the hypotenuse of that triangle has a length Y * sqrt(2)
.
That hypotenuse is your side X
, so Y = X / sqrt(2)
.
Picture saying more than 1000 words:
So you can calculate Y for your desired length X, and from there it's just additions and subtractions to get all the coordinates.
Upvotes: 8
Reputation: 382
If you came here just looking for the points, like me, here they are.
These are (x, y) coordinates for an octagon like a stop sign (equal sides and flat on the top). Note that the 0.414
values are actually sqrt(2) - 1
. These coordinates make an octagon with sides of length 2 * (sqrt(2) - 1)
. For an octagon with sides of length S
, multiply each value by S/(2 * (sqrt(2) - 1))
.
( 0.414, 1.000)
( 1.000, 0.414)
( 1.000, -0.414)
( 0.414, -1.000)
(-0.414, -1.000)
(-1.000, -0.414)
(-1.000, 0.414)
(-0.414, 1.000)
Upvotes: 2
Reputation:
Assuming a regular octagon centered at the origin, the starting point is at
(x, y) = (r cos(t), r sin(t))
where t
is the starting angle and r
the radius of the circumscribed circle.
You find them by conversion to polar coordinates,
r = √x²+y², tan(t) = y/x
but this is unnecessary.
The other vertices are at
(x, y) = (r cos(t + k π/4), r sin(t + k π/4))
You can simplify the formula by the angle addition formula. For instance, for the second vertex
(r (cos(t) - sin(t))/√2, r (sin(t) + cos(t))/√2) = ((x - y)/√2, (x + y)/√2)
and for the third
(r (-sin(t)), r cos(t)) = (-y, x)
Upvotes: 5