int multiplier = 4;
int initial_position = 7;
int new_position = multiplier * (initial_position / multiplier);
Note however that if the multiplier does not evenly divide 180, this might not work the way you intended.
multiplier = (int)(1.0/rotation_speed + .5) // rounds
if(initial_position%multiplier > multiplier/2)
new_position = initial_position - initial_position%multiplier + multiplier
else
new_position = initial_position - initial_position%multiplier
You have a big problem however if the multiplier is not a factor of 180 (7,8,11,etc)if abs(current_position) <= multiplier/2
current_position = 0
if current_position <= multiplier/2 or current_position >= 180 - multiplier/2
current_position = 0
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
How to print into std::string like sprintf using C++11? | 12 | 48 | |
operator overload: incompatible type and too many params | 5 | 62 | |
MacOS and programming in React | 7 | 27 | |
How many living descendants from a 23 years old in 1838? | 7 | 37 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
21 Experts available now in Live!