Jump to content
  • Advertisement
Sign in to follow this  

Converting Degrees/Radian to Vector2 is messy

This topic is 434 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?





Edited by Kromble

Share this post

Link to post
Share on other sites

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

-4.371139E-08 = -0.00000004371139

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!