c++ - Position percentage to degree -
c++ - Position percentage to degree -
double x = ...; // -1.0 1.0 double y = ...; // -1.0 1.0 int deg = (int) ((atan(x / y) * 57.2958) + (y > 0 ? 540 : 360)) % 360;
some basic geometry can't seem figure out right now. spent while on it. above code works ok-ish seems mirrored wrong , i'm pretty sure mod isn't required here.
i have aa rather odd scenario, need grade outputs when reddish dot @ position. mirrored unit circle.
looking easy implementation (and maybe geometry refresher).
you need:
degrees = atan2(x, y) * 360.0 / (2.0 * m_pi) + 180.0;
note utilize of atan2 valid 4 quadrant result. need add together π radians (180 degrees) since atan2
returns values in range -π π.
note x , y transposed compared more conventional usage (atan2(y, x)
).
live demo
c++ math geometry
Comments
Post a Comment