I
I
igossmart2019-10-15 15:19:25
JavaScript
igossmart, 2019-10-15 15:19:25

How to rotate an object around a circle without "reversing"?

Hello everyone, tell me how to correctly rotate an object around a circle without a "turn", if it is from 0 to 360 clockwise, for example, the object is rotated by 10 degrees and you need to rotate it by 340, but along a "small" path, i.e. how jump from 0 to 360 if you use JS JS for this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2019-10-15
@igossmart

const dir = (aFrom, aTo) => (aTo - aFrom + 360) % 360 > 180 ? 'ccw' : 'cw';
// "ccw" – против часовой, 
// "cw" – по часовой

dir(30, 60) // "cw" – из 30° в 60° лучше по часовой стрелке топать
dir(30, 330) // "ccw" – против часовой короче )

T
tsarevfs, 2019-10-15
@tsarevfs

The idea is something like this:

from = 10;
to = 340;
angle = min(to - from, 360 - to + from);

for (t = 0; t != nFrames; ++t)
{
    animationAngle = from + angle * (t / nFrames)
    ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question