# Should I Include the W-component of a vector when calculating it's length or dot product?

The reason I'm asking this is because I saw an implementation which did it that way but I don't quiet understand it. I mean, usually I want to get the distance between two points in 3d space and if W is something other than 0 the result is not correct. The same when calculating lighting using the dot product.

float Vector::Length() const{
return sqrtf(X * X + Y * Y + Z * Z + W * W);    //W necessary?
}

float Vector::Dot(const Vector& other) const{
return X * other.X + Y * other.Y + Z * other.Z + W * other.W;
}


Edit: There are suggestions that my question is a duplicate of already existing ones. But the questions referred to are about whether you need the W component at all and for what. I know what I need it for, I'm just not sure about it's role in the operations I specified.

• Possible duplicate of Do I need the 'w' component in my Vector class? – Vaillancourt Apr 2 '16 at 15:30
• Or even this... – Vaillancourt Apr 2 '16 at 15:33
• @AlexandreVaillancourt I don't think so. As you can read in my edit above, these questions are not the same as mine... – Leon2806 Apr 2 '16 at 15:43
• All right! I'll leave the link there just as a reference. – Vaillancourt Apr 2 '16 at 15:45
• @aslg I think you have enough content there to make an answer :) – Vaillancourt Apr 2 '16 at 16:25

The only reason you need to extend a vector to 4 dimensions (homogeneous coordinates, not 4-Dimensional space) is so that you can apply transforms or matrices (model, etc) to it. Unless you're explicitly making a game in a 4-Dimensional space you don't need to include the w component in the calculations you mentioned.