Public Group

Stupid Vector question

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

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 on other sites
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 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 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

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

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

• Total Topics
633298
• Total Posts
3011259
• Who's Online (See full list)

There are no registered users currently online

×