Jump to content
  • Advertisement
Sign in to follow this  
abcdefg

Stupid Vector question

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

Okay Lets say you are working in 2D space. Lets say I have 2 entities like a player and ship. Why cant I just subtract the x and y coordinates from each other. What is the purpose of using vectors? Why go through the trouble of using a Sqrt and all the other hassles. I just dont understand the point in using them in 2d when I can just subtract and add x and y which is essentially a vectors components anyway right?

Share this post


Link to post
Share on other sites
Advertisement
Using a 2d vector class is often more convenient than passing around than 2 separate variables everywhere, and will make your code more readable in the long run. I don't really understand your issue with sqrt, but if you don't need to use it nobody is forcing you...

Share this post


Link to post
Share on other sites
Well, sure, you could.

Programatically, it's better to use a vector because it's then easier to move from 2d to 3d [you only have to edit vector functions, not everywhere the x and y are done] or to use the vector in various applications [since vector is generic, ship and player are not].

Realistically, vectors are more commonly used as velocities or accelerations or forces. You don't say your car is going 15mph west and 45mph north... you say it's going 55mph along such and such road. In physics problems you'll often need to place the vectors before knowing the angle or how the vector splits into dimensions.

Though that's not really applicable in the problem you describe.

Share this post


Link to post
Share on other sites
Quote:
Okay Lets say you are working in 2D space. Lets say I have 2 entities like a player and ship. Why cant I just subtract the x and y coordinates from each other. What is the purpose of using vectors? Why go through the trouble of using a Sqrt and all the other hassles. I just dont understand the point in using them in 2d when I can just subtract and add x and y which is essentially a vectors components anyway right?

From a mathematical perspective, the distance between two objects on a 2d plane is not the slope, e.g. if you have a spaceship at (4, 3) and a person at (2, 0) then the distance between them is sqrt( (4 - 2)^2 + (3 - 0)^2 ), not simply ( (4 - 2), (3 - 0) ). Although that's not vector mathematics, that's just simple trig.

Furthermore, vectors represent both a line (what you refer to as a "x and a y") and a direction. The latter is important when doing 2d collisions, especially where an angle is involved. Vectors allow you to accurately deduce describe the relationships between objects in 2d space.

In short, vectors make life in any dimension (2d+) easier.

<edit :: And what Telastyn said

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!