Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+13 votes

So Vector2/Vector2i are 2D and Vector3/3i are 3D. So Vector4/4i would be 4D? I'm just curious how and in what situation this would be used, any ideas?

asked in CSC380Jan2024 by (1 point)

1 Answer

+4 votes

The components to a Vector4 include an x, y, z, and w component. That w component is used to scale the x, y, and z components of the vector up or down by a proportional amount. When w == 1.0, it’s considered normalized, and acts just like a vector3D. When w == 0.0, all matrix operations on the vertex ignore translations. Ignoring translations is important when you’re only concerned about describing direction, and acts to optimize things like lighting calculations.

Here’s an example I’ve borrowed from OpenGL’s Programming Guide, which I highly recommend should you want to pursue the topic in depth.

"homogeneous vertex (x, y, z, w)T corresponds to the three-dimensional point (x/w, y/w,z/w)T" and that "the sequence of points (1, 2, 0, 1), (1, 2, 0, 0.01), and (1, 2.0, 0.0, 0.0001), corresponds to the euclidean points (1, 2), (100, 200), and (10000, 20000)"

To come back to the question, Vector4’s can be useful for when you need to calculate the projection of a model within 3D space. The w component also offers a good means for the creation of precise positions that would otherwise suffer from floating point rounding errors.

answered by (1 point)
...