Rotation of Tetrahedron by 45 degrees is Incorrect Due to Floating Precision

I am quite stumped on this problem, because I thought this issue was supposed to be resolved with the introduction of Large World Coordinates, but for some reason it’s still applying a problem to my rotation:

Here’s the context - I am generating a voxel grid in the shape of a tetrahedron. I am using this to then produce multiple chunks to fit together into a larger world. I have the grid, it’s come together nicely and I have confirmed it is a perfect tetrahedron by vertex and distance value.

However, upon rotating the tetrahedron by 45 degrees, whether by the editor, by FRotator, by FQuat, or even FTransform, it is not allowing a perfect 45 degree rotation around the axis:

As you can see, the precision is off by a very small margin, however the green lines represent a difference in half a cm. Now obviously, this is an incredibly small value to be off by…however, the problem comes with scale. If I scale this up to the size I need (currently this measures at about 130m tall), by the time I increase the scale up to my planned size, the gap in this rotation will be quite significant, as large as 10, 100 or even 1000cm, which will cause havok in my process.

The reason for this is that eventually I need to stitch together my tetrahedrons to form the larger planet, but if the vertexes are off by a variable amount, it will be very difficult to have to measure the difference between each vertex at different points and then have to account for scale at the same time. It should be possible to just rotate this cleanly, but for some reason, the system will not let me.

I have tried numerous solutions to try and force a more precise rotation, such as FQuats, Matrixes, even just setting the values outright, but for some reason every time it comes to putting this tetrahedron in place, it’s always off. Here’s how my code currently implements this rotation:

Method 1 is the simple approach I started with, Method 2 is my latest implementation to try and force double precision, but to the same result.

Does anyone have some insight on how to solve this problem? Any input would be very helpful, as I have unfortunately run out of ideas.

I think rotating by degrees goes like this:

  • you put 45deg, that is changed to radians
  • then it is applied to rotation

So either find way to use radians (skipping all that conversions)

Or maybe try to use quaternion, that may be more accurate. Just suggestions i am not sure if any of that will be more accurate.

Sadly, that did not work, though there is a slight improvement?

So I tried this in one of two ways:

First was simply taking a Rotator from the FQuat and feeding that into my transform. Then I tried just feeding the FQuat directly into the FTransform. Both managed to rotate the tetrahedron, but both unfortunately are drifting off the axis by the same amount as all the other methods.

Still drifting off base by less than half a centimeter.

However, the improvement comes in that now the editor shows 45.000001 instead of 45, meaning the calculation WAS more accurate. It’s just that the rotation itself isn’t right.

I have also tried setting the actor’s Rotation after spawning and even adding it to their base rotation; both resulted in the same process.

So, because so many different methods are resulting in the same result, my thinking is that while the “value” being entered in is correct, the actual USE of that number, the 45-degree rotation in world space, must be wrong. Either the physics, the rendering, or the translation, whatever the engine is doing with this number to move the tetrahedron as it is, is incorrect.

And I’m not sure how I can address that problem.

I think it is because internally all code changes to same type of variable somewhere and uses that for calculation, so no matter how and what you enter for rotation it always ends in same function (and with same type of variable).

For that voxel grid do you generate all tetrahedrons?
If so you can use “smart” rounding up for vertexes. Just think about method that always rounds up to same location.

Or calculate resulting shape in same scale (size of voxels) then scale and rotate result shape (and this may be faster because multiple sin/cosine functions are slower than just adding vectors.

Sorry for the delayed replay, finally had an opportunity to review your suggestion.

I get what you’re saying here, and yes, I am currently just generating all tetrahedrons. However, the problem with this method arises with the eventual goal, which is to fit all of these together into a icosahedron, or a d20 for reference.

Secondly, I need every “Chunk” to be individually created, thus in this case 20 different tetrahedrons all fitted together.

And thirdly, to make these tetrahedrons fit nicely, they must be “Irregular” tetrahedrons, meaning while the base is equilateral, the others aren’t, so I had to use a custom shape with planes that determined which points would be generated, thus making the custom shape, because otherwise there’s no other way to generate an irregular tetrahedron without just putting in 4 points.

What all of this means is that while I would LOVE to round the values to nice places, it’s not really feasible with the precision I require to ensure the tetrahedrons not only remain individual, but also precise in dimension and scale. The ratio is like .95 to 1 for the short sides of the tetrahedrons in order to make the d20 fit actually work.

As such, adjusting the precision of the vertexes during generation isn’t really possible, because it’s completely determined by the “Size” fed into the scale. And with such a weird ratio, I’m not sure what vertexes would work as nice ones anyway.

So I’ve come up with another possible solution based on your last statement of “calculate resulting shape in same scale THEN scale and rotate result”. I have two ideas to try to implement this:

  1. I will attempt to create a precise tetrahedron at the smallest scale possible, then scale that up to the desired Size entered, which hopefully makes precision easier.

  2. I am thinking of how to generate the tetrahedrons in place already rotated to the position I want them to be in, but finding a way to do this during generation and being custom to how many tetrahedrons are being generated in the first place will be extremely difficult, so if you have any ideas on how to make that easier, I’d love to hear it, because I really don’t want to just hardcode everything for every scenario.

And for clarity, I have attempted the quaternion/radians degree rotation and it HAS improved the precision of the rotation dramatically…but it’s still not correct, as at a radius of around 100 units, it’s still off by at least .1 degrees, which just won’t work at the sizes I’m attempting. So rather then rotation, I do think this has to be handled in an alternative way.

Hmm I don’t this happening here. We use SetActorRotation() and SetActorRelativeRotation() a LOT for interpolations and it always sets them exactly where desired, as far as I can tell.

When inspecting actor in the editor there is never any extra decimals. Always exactly 45.0 degrees (or whatever desired rotation).