Sign in to follow this  

vectors and the articles

This topic is 3317 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

I've been starting to code a vector library just for fun and I stumbled upon an article here in gamedev that mentions the use of 4 fields for just a vec2, I'm still trying to understand why... The guy uses x, y, angle, length << isn't a vector just angle and length??? Could someone please explain me what's going on, I'm a little blurry on this. Thanks PS: I couldn't find the link right now but it's on the articles section

Share this post


Link to post
Share on other sites
Quote:
Original post by gusso
I've been starting to code a vector library just for fun and I stumbled upon an article here in gamedev that mentions the use of 4 fields for just a vec2, I'm still trying to understand why...

The guy uses x, y, angle, length << isn't a vector just angle and length???
In a cartesian (rectangular) coordinate system, you represent vectors as x and y, while in a polar (circular) coordinate system you represent vectors as an angle and a length. Since it is trivial to convert between the two representations (with a little trigonometry), I can't see an advantage to storing both.

Share this post


Link to post
Share on other sites
From the author:

Quote:
You'll notice that I included the endpoint in my class while I said earlier that you only need an angle and length to specify a vector. I chose to include the endpoint because of efficiency. You need a cosine and sine function to calculate the endpoint. By storing the endpoint we only have to do this calculation once every time the endpoint changes instead of every time we want to use the endpoint. The length of the vector is specified in amount of pixels but that could easily be modified to anything you want

Share this post


Link to post
Share on other sites
Personally I would say that's a horrible design decision :) Just recalculate the values when they're needed. It's not worth increasing the space requirements for something like this; if you find that you calculate length/angle much more often than you change the values, maybe you should be storing length/angle and calculating x/y from them instead? :)

Share this post


Link to post
Share on other sites

Alright, it's starting to make sense now. What doesn't make sense is why most of the articles are so weird? (I know, I should write something better and prove them wrong --- but I can't, I'm still learning and now that I think about it, probably the author of the article still was)

Not that you ever 'stop' learning new things...

But anyway, could someone point me toward a 'better' article instead?
Thanks

Share this post


Link to post
Share on other sites

This topic is 3317 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this