Public Group

# vectors and the articles

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

## 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 on other sites
Quote:
 Original post by gussoI'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 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 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 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

1. 1
Rutin
35
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633340
• Total Posts
3011421
• ### Who's Online (See full list)

There are no registered users currently online

×