Yay math
782
1
Advertisement
So, as promised, today's entry is about dodecahellspawn. I find it useful for any project bigger than "Hello World" to lay out as much as possible on paper before actually coding. And since I'm such a nice guy, I'll spare you my handwriting and put up nice pretty versions drawn up in gimp instead.
For dodecahellspawn, this phase is particularly painful because of the nature of the beast. A dodecahedron has tweleve faces, so when using the faces for rotation, this means six independent rotational axes. Additionally, the model itself falls in the non-trivial category. Fortunately, a lot of the details can be faked. (You'll see what I mean later.)
In any case, the biggest chunk of functionality that really could have used comments in the first version of dodecahellspawn was the initialization of the model. I'll spend a bit of time on that, so that when I look at this project again five years down the line I won't ask myself what the heck I was thinking. (I'll probably still ask myself that, but hopefully for different reasons.)
Easing in to things, we have one face of the dodecahellspawn. In this diagram we have a pentagon inscribed in a circle inscribed in a square. Given this diagram, it's pretty basic trig to determine the coordinates of each of the significant points in the diagram: the corners of the pentagon, the mid points and the corners of the inner pentagon. Even better the mid points and the corners of the inner pentagon can be determined easily from the coordinates of the corners of the outer pentagon. By itself it doesn't mean much, though we'll keep coming back to it later.
The next diagram has a bit more bite to it. If you remember my previous comment about sawing a d12 in half, this is what the cross section would be like. In this case, the cross section is determined by the plane going through two directly opposite edges on a dodecahedron, which would correspond to the line segments AK and EG on the diagram. The other outside edges would be bisecting the faces of the dodecahedron. Thus, the proportions of the line segments can be determined be referencing the first diagram. The length of AB in the second diagram corresponds with the distance from the center to one of the corners of the pentagram in the first diagram. The length of BC in the second diagram corresponds with the distance from the center to one of the midpoints in the first diagram. The length of AK would corresond with the length of one of the pentagon's edges in the first diagram.
Given all that, determining the angles becomes straight forward, if rather annoying. Gamma works out to be .5 asin( (2 cos 36) / (1 + cos 36) ); alpha, atan( (tan gamma) / (cos 36) ) and beta, atan( tan 36 sin gamma ). Yes, this is in degrees, not radians. If you want to work it out yourself (and that means you, me-from-five years-in-the-future), it will save you time if you note that CI and FL are equal in length and perpendicularly bisect each other.
Now for the point behind this diagram: every vertex of the dodecahedron can be found by taking one of A, C, E, G, I or K and rotating around the BH axis by a multiple of 72 degrees. That means once we know alpha, beta and gamma, we can determine the coordinates for every vertex on the dodecahedron. And once we have the coordinates for the vertices, we can figure out the midpoints and the star points on each face. And once we know those coordinates, we can render the whole thing in OpenGL. Yay math!
For dodecahellspawn, this phase is particularly painful because of the nature of the beast. A dodecahedron has tweleve faces, so when using the faces for rotation, this means six independent rotational axes. Additionally, the model itself falls in the non-trivial category. Fortunately, a lot of the details can be faked. (You'll see what I mean later.)
In any case, the biggest chunk of functionality that really could have used comments in the first version of dodecahellspawn was the initialization of the model. I'll spend a bit of time on that, so that when I look at this project again five years down the line I won't ask myself what the heck I was thinking. (I'll probably still ask myself that, but hopefully for different reasons.)Easing in to things, we have one face of the dodecahellspawn. In this diagram we have a pentagon inscribed in a circle inscribed in a square. Given this diagram, it's pretty basic trig to determine the coordinates of each of the significant points in the diagram: the corners of the pentagon, the mid points and the corners of the inner pentagon. Even better the mid points and the corners of the inner pentagon can be determined easily from the coordinates of the corners of the outer pentagon. By itself it doesn't mean much, though we'll keep coming back to it later.
The next diagram has a bit more bite to it. If you remember my previous comment about sawing a d12 in half, this is what the cross section would be like. In this case, the cross section is determined by the plane going through two directly opposite edges on a dodecahedron, which would correspond to the line segments AK and EG on the diagram. The other outside edges would be bisecting the faces of the dodecahedron. Thus, the proportions of the line segments can be determined be referencing the first diagram. The length of AB in the second diagram corresponds with the distance from the center to one of the corners of the pentagram in the first diagram. The length of BC in the second diagram corresponds with the distance from the center to one of the midpoints in the first diagram. The length of AK would corresond with the length of one of the pentagon's edges in the first diagram.
Given all that, determining the angles becomes straight forward, if rather annoying. Gamma works out to be .5 asin( (2 cos 36) / (1 + cos 36) ); alpha, atan( (tan gamma) / (cos 36) ) and beta, atan( tan 36 sin gamma ). Yes, this is in degrees, not radians. If you want to work it out yourself (and that means you, me-from-five years-in-the-future), it will save you time if you note that CI and FL are equal in length and perpendicularly bisect each other.Now for the point behind this diagram: every vertex of the dodecahedron can be found by taking one of A, C, E, G, I or K and rotating around the BH axis by a multiple of 72 degrees. That means once we know alpha, beta and gamma, we can determine the coordinates for every vertex on the dodecahedron. And once we have the coordinates for the vertices, we can figure out the midpoints and the star points on each face. And once we know those coordinates, we can render the whole thing in OpenGL. Yay math!
Advertisement
Advertisement
Advertisement
Discussion