Crates.io | cube-rotations |
lib.rs | cube-rotations |
version | 1.0.0 |
source | src |
created_at | 2024-10-12 23:58:07.515796 |
updated_at | 2024-10-12 23:58:07.515796 |
description | Models the rotations that can happen on a cube without changing the set of planes to which its faces are parallel. |
homepage | https://github.com/DoubleHyphen/cube-rotations |
repository | https://github.com/DoubleHyphen/cube-rotations |
max_upload_size | |
id | 1406957 |
size | 152,757 |
The cube-rotations
crate offers the functionality needed to model the 24 different rotations that can be performed on a cube while keeping its faces parallel to the same set of planes. It's been built to help program smart building blocks, and is meant to run on the cheapest microcontrollers currently available on the market.
Add the following line under the [dependencies]
section of your Cargo.toml
file:
cube-rotations = "1.0"
Say you have three points, x
, y
, and z
. Each of them has a default orientation:
let x = NegThreePosOnePosTwo;
let y = PosTwoPosThreeNegOne;
let z = PosThreePosOneNegTwo;
But now you realise that x
's actual orientation is different:
let x_actual = PosThreePosTwoPosOne;
How do we find which rotation needs to be performed, such that x
ends up
coïnciding with x_actual
?
All it takes is one division:
let rotation = x_actual / x;
And then, the rotation can simply be applied to each point:
let x_actual = x * rotation;
let y_actual = y * rotation;
let z_actual = z * rotation;
Please note that (x_actual / x) * x
yields just x_actual
, exactly as one would suppose from the notation.
There's also a luts
module that performs all operations using Look-up Tables:
let x = luts::CubeSurfacePoint(NegThreePosOnePosTwo);
let y = luts::CubeSurfacePoint(PosTwoPosThreeNegOne);
let z = luts::CubeSurfacePoint(PosThreePosOneNegTwo);
let x_actual = luts::CubeSurfacePoint(PosThreePosTwoPosOne);
let rotation = x_actual / x;
let x_actual = x * rotation;
let y_actual = y * rotation;
let z_actual = z * rotation;
There are more things to mention, but this is enough for a first glance.