cube-rotations

Crates.iocube-rotations
lib.rscube-rotations
version1.0.0
sourcesrc
created_at2024-10-12 23:58:07.515796
updated_at2024-10-12 23:58:07.515796
descriptionModels the rotations that can happen on a cube without changing the set of planes to which its faces are parallel.
homepagehttps://github.com/DoubleHyphen/cube-rotations
repositoryhttps://github.com/DoubleHyphen/cube-rotations
max_upload_size
id1406957
size152,757
(DoubleHyphen)

documentation

https://docs.rs/cube-rotations/

README

Cube Rotations

Introduction

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.

Including the project

Add the following line under the [dependencies] section of your Cargo.toml file:

cube-rotations = "1.0"

Usage

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.

Look-up Tables

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.

Commit count: 5

cargo fmt