-1
I’m writing a code, for making decisions on an 8bit microcontroller, an AVR.
I get 8 range of double values, limited by Vf_max and Vf_min, I don’t know which will be the biggest in each track. As in the example below, it is perceived that coordinates are distributed in their quadrants:
const double LIMIT_NORTE[] = { -1, 1}; // 0x14
const double LIMIT_NORDESTE[] = { 1, 89}; // 0x11
const double LIMIT_LESTE[] = { 89, 91}; // 0x12
const double LIMIT_SUDESTE[] = { 91, 179}; // 0x22
const double LIMIT_SUL[] = { 179, 180}; // 0x23
const double LIMIT_SUDOESTE[] = {-180, -91}; // 0x33
const double LIMIT_OESTE[] = { -91, -89}; // 0x34
const double LIMIT_NOROESTE[] = { -89, -1}; // 0x44
So, if I receive a value for example 45, I know that this value is in the first quadrant and is equivalent to the Northeast range, 1 to 89, if I receive a value for example -130, I know it is in the southwest, and so on.
But I need to convert that received value into a percentage of the track that it belongs to, and I’m not able to find a formula that makes such a conversion possible in general, since in the program, such tracks can change when parameterized, in other words, the limits of what is considered the South strip, can be expanded, reducing the limits of the Southeast and Southwest.
For example receiving 45 know intuitively that will be 50% of the Northeast range.
Can anyone help me with a generic formula for such a calculation? Remembering the map() function widely publicized in Arduino does not work, and I’ve tried what is proposed in https://stackoverflow.com/a/5732390/2766598
https://pt.wikipedia.org/wiki/Regra_de_tr%C3%AAs_simples
– ramaral