Quote: "x1 = sin(theta+45)*radius
y1 = cos(theta+45)*radius
x2 = sin(theta+135)*radius
y2 = cos(theta+135)*radius
x3 = sin(theta+225)*radius
y3 = cos(theta+225)*radius
x4 = sin(theta+315)*radius
y4 = cos(theta+315)*radius"
(Don't forget to add your center values)
And to speed up your game a little([edit] sorry, this isn't for a game is it?), you can calculate only 2 points, and base the rest on them (CX and CY are the center of your square, radius is the distance from the center to each point):
`----------------------------
vx1 = cos(theta + 45)*radius
vy1 = sin(theta + 45)*radius
vx2 = cos(theta - 45)*radius
vy2 = sin(theta - 45)*radius
`-->
x1 = CX + vx1
y1 = CY + vy1
x2 = CX + vx2
y2 = CY + vy2
x3 = CX - vx1
y3 = CY - vy1
x4 = CX - vx2
y4 = CY - vy2
`----------------------------
And at last, how to calculate the radius with only a side given:
side = 2 * (sin(45)*radius)
<=> side/2 = (sqrt(2)/2)*radius
<=> radius = (side/2) / (sqrt(2)/2)
<=> radius = side / sqrt(2)
or also radius = sqrt(2)*side/2
It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.