Help with a formula / maths please! via /r/learnprogramming


Help with a formula / maths please!

Not sure if this is the right place or I should post in a maths subreddit.

I'm trying to make a simple algorithm / formula that takes x values (rotation) and returns a number that goes up then down in a sequence. For example:

0 -> 1 22.5 -> 2 45 -> 3 67.5 -> 4 90 -> 5 112.5 -> 4 135 -> 3 157.5 -> 2 180 -> 1

And for forth to loop back to 360/0 returning 1.

The lower number from the range of expected values is 1 and the upper value is 5.

The distribution should be linear so the value changes by 1 every 22.5 degrees.

Done something very dirty in code that works using a whole load of ifs but would appreciate if there's a simple / known formula that does all this, or that to search for to learn more about this.

Submitted July 16, 2017 at 06:48PM by milesred
via reddit http://ift.tt/2uyszfG

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s