Necro’ed! In case in the future anyone else wants to know how to place hexagons around a sphere, this is how to do it.
First you start off deciding where the pentagons are going to be. From the center, you’ll want one straight up (to be the north pole), one straight down (the south pole), five in a ring 26.56 degrees up from the center and separated from each other 72 degrees around a circle (the northern ring, kind of like our planet’s Tropic of Cancer), then five more in a ring 26.56 degrees down from the center (the southern ring, kind of our own Tropic of Capricorn), also 72 degrees apart from each other around a circle, but offset 36 degrees from the northern ring.
Then in general, this is what you do to fill in the sphere. You push the pentagons out a certain radius from the center (exact distance will be determined by the size of your hexagons and how many you want between each pentagon). Then you’ll need 4 quaternions:
FQuat StartQuat1 = FQuat::FindBetweenVectors((TargetLocation1 - this->GetActorLocation()), (StartLocation - this->GetActorLocation()));
FQuat StartQuat2 = FQuat::FindBetweenVectors((TargetLocation2 - this->GetActorLocation()), (StartLocation - this->GetActorLocation()));
FQuat Edge1Quat = (TargetLocation1 - this->GetActorLocation()).ToOrientationQuat();
FQuat Edge2Quat = (TargetLocation2 - this->GetActorLocation()).ToOrientationQuat();
StartQuat1 *= Edge1Quat;
StartQuat2 *= Edge2Quat;
In that code, “this” is the actor that I move around to set the center of the sphere and which has a function for building the sphere. StartLocation, Target1Location, and Target2Location are the locations of 3 adjacent pentagons. Their locations are the equivalent of the points of a triangle on a D20-shaped dodecahedron. When we have our three vectors, and we get our quaternions from them, then we use FQuat::Slerp. Slerping is basically taking two rotations (represented by quaternions), and you give it a number between 0 and 1, and it returns the quaternion at that point in an interpolation from Quat1 to Quat2. We make a for-loop to slerp along the surface of the sphere from Start1 to Edge1 and Start2 to Edge2*, placing hexagons at regular intervals, and then a nested for-loop to slerp from one side of the triangle to the other, placing hexagons inside the triangle.
Do that 20 times to fill in each of the 20 triangles between pentagons.
There’s a little more to it than that to figure out the rotation for each hexagon/pentagon, and also pentagons take up slightly less space than hexagons, so you have to account for that too, but that’s basically how it works.
- (Note: Start1 and Start2 are quaternions that both point in the same forward direction, for example from the center of the earth toward the north pole. But they are rotated so that as you slerp them, Start1 will head toward Target1 and Start2 will head toward Target2.)