# When should operations on 4D (homogeneous/projective) vectors use the w-coordinate?

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?

• Projective, homogeneous; homogeneous, projective. I'll include both names in the question. – Tim Pederick Dec 23 '19 at 15:40
• 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}$ – Simon F Dec 23 '19 at 15:45
• @SimonF: That's why I specified that I'm assuming vectors are in canonical form, with $w=1$. – Tim Pederick Dec 23 '19 at 16:04
• 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. – Simon F Dec 23 '19 at 16:11
• 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. – lightxbulb Dec 23 '19 at 19:42