Various operations on 2D vectors naturally generalise to 3D vectors simply by including the $z$-coordinate. The ones that come to mind are:

  • Vector sum and difference
  • Dot product
  • Magnitude (Euclidean norm)

Various graphics programming tasks also use 4D vectors, usually(?) to represent points in 3D projective space (AKA homogeneous coordinates). Given this, it would seem that the above operations should not use the $w$-coordinate.

For example, the magnitude of a 4D vector would be calculated in exactly the same way as the equivalent 3D vector:

$\lVert \mathbf{v} \rVert = \sqrt{x^2+y^2+z^2}$

...and not with the inclusion of the $w$-coordinate:

$\lVert \mathbf{v} \rVert = \sqrt{x^2+y^2+z^2+w^2}$

(For a point at infinity, where $w=0$, there wouldn't be a difference, but for finite points, there would. I'm also assuming that a finite 4D homogeneous vector is in canonical form, with $w=1$.)

Is this always the case? Is there any situation in graphics programming where calculations on 4D vectors should not treat them as their 3D equivalents, but should actually make use of the $w$-coordinate?

  • $\begingroup$ Projective, homogeneous; homogeneous, projective. I'll include both names in the question. $\endgroup$ – Tim Pederick Dec 23 '19 at 15:40
  • $\begingroup$ I'm confused by your vector magnitude example. If you are using homogenous coordinates then surely all vectors of the form ${W.V_x, W.V_y, W.V_z, W}$ are "equivalent" and so wouldn't the magnitude thus be $\frac{\sqrt{V_x^2+V_y^2+V_z^2} }{W}$ $\endgroup$ – Simon F Dec 23 '19 at 15:45
  • $\begingroup$ @SimonF: That's why I specified that I'm assuming vectors are in canonical form, with $w=1$. $\endgroup$ – Tim Pederick Dec 23 '19 at 16:04
  • $\begingroup$ Oops. Sorry, missed that! FWIW you do get use cases, however, where $w\neq1$ in graphics e.g. extruding shadow volumes to infinity or doing rational splines. $\endgroup$ – Simon F Dec 23 '19 at 16:11
  • $\begingroup$ Yes, when your 4D vector is not just a projective extension of your 3D one. Some examples off the top of my head: spatio-temporal vector, 4d rendering, quadric surfaces, quaternions. $\endgroup$ – lightxbulb Dec 23 '19 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.