I am trying to remember how to do something I believe should be quite simple.
I have a slot machine or a carousel, let's focus on one ring. Each ring has five faces, I calculated that each angle is 72deg.
I made a map of each face to the degree it is on the carousel.
const slotMap = {
0: 288,
1: 216,
2: 144,
3: 72,
4: 360
};
My problem is when I have a first rotation everything works fine. I just rotate it to the face I need. For example, if it's face 3 then I rotate by 72deg.
My issue is trying to find an equation that will turn it to the next face.
If I have face 3 and I want it to face 2.
I tried by subtracting the difference in the number of faces from the previous face and the current face and multiplying by 72deg but this did not work.
I believe this has to be either trigonometry or something basic, but it has been bugging me for a long time.
my original equation:
| currentFace - previousFace | * 72deg = nextFace
has not worked out at all.
I must be forgetting something very basic.
(I am doing this in Javascript but I really want to understand the math before the code)
Your equation works when you try to go from a smaller numbered face to a larger numbered face (from 2 to 3), but not when going from a larger numbered face to a smaller numbered face (from 3 to 2). This is because the equation doesn't distinguish between the two.
For example:
If you want to go from face 2 to face 3: $\mid 3-2\mid \times 72=72$ (the correct degree value for face 3)
But, when you try to go from face 2 to 3: $\mid 3-2\mid=\mid 2-3\mid$, so you will get $72$ again.
If you can reassign the degree values for the faces, such that:
You can make the equation:
( currentFace - nextFace ) * 72degwhich gives you the degrees you need to rotate.For example:
To go from face 4 to face 1, you have:
$(4-1) \times 72=216$, which is correct since you need to go $+216^\circ$ from face 4 to get to face 1 ($72^\circ$ to $288^\circ$).
On the other hand, to go from face 1 to 4 you have:
$(1-4) \times 72=-216$, which also holds true.