Advertisement

Converting Degrees/Radian to Vector2 is messy

Started by October 04, 2017 12:31 PM
2 comments, last by Kromble 7 years, 4 months ago

Hi Guys,

I was wondering if some one could give me some tips on converting Degrees/Radians to Vector2. Degrees to Radians and vice versa is fine.

Im using "new Vector2((float)Math.Sin(r), (float)Math.Cos(r));" to do my conversion to Vector2. Yes, I get that the equation is usually [cos(r) , -sin(r)] but my equation suits my current orientation and ultimately does not affect my problem.

The problem I'm facing is the conversion of 90° and 180° into Vectors. When converting them I get:

·         90° = [1, -4.371139E-08] - second value should be 0.

·         180° = [-8.742278E-08, -1] - first value should be 0.

I understand that 180° is technically out of range, but just indulge me on that one, the main issue is 90°. What I am missing with those E-numbers? How do I avoid them?

After writing this I thought of just including a lookup table for the 90° and 180° during the conversions, maybe, I guess it would depend on their precision. Assuming I do not change my orientation this should work right?

Thanks

Krom

 

 

Both those values are super tiny. They are essentially 0 -- just floating point inaccuracies. Nothing to worry about.

-4.371139E-08 = -0.00000004371139

Hello to all my stalkers.

Advertisement

Ahh cheers thanks mate...

I guess the compiler can interpret this number fine.

 

Krom

This topic is closed to new replies.

Advertisement