Quote:Original post by RigidBody
Surely the operator should only be used for one thing, and that thing should be multiplication.
Because in the minds of many mathematicians, dot product is the vector equivalent of multiplication extended into multiple dimensions. When written down on paper, dot product is even sometimes represented in the same manner as regular multiplication -- it isn't a new practice to C++ operator overloading. Convention, however, is not the reason that I prefer to use operator*.
Before going into exactly why I believe multiplication is an application of dot product, observe some of the likenesses -- in terms of math, dot-product is commutative, distributive, associative, and it has several common logical operations which parallel those of multiplication of scalars, such as, most-notably, the fact that the dot product is the multiplication of the signed magnitudes of the vectors when projected along one of their associated lines and the related fact that a vector dot-producted by itself gives you the square of its magnitude.
All of these properties hold true for multiplication of scalars. The difference is that some people think of multiplication as a scalar operation not extending to other dimensions, whereas others think of scalar multiplication as the equivalent of the dot-product in 1-dimensional space (which it actually rationally is). Take, for example, generalizing projections into 1-dimensional space, aka the number line. The projection of a scalar value, rationalized as a vector in 1-dimension, onto the number line is always itself, since the vector and the number line are always going to be colinear to begin with. The magnitude of a componentized vector in 1-dimensional space, is of course, just it's own value (pythagorean in 1-dimension -- sqrt( v.x^2 )). In turn, the dot product of two scalar values is the multiplication of their signed magnitudes when one is projected onto the other, which in 1-dimensional space is just their values multiplied together. This is equivalent the simple multiplication that we know today, only now it is applicable to any number of dimensions as the dot product (inner product). The fact that the dot product of two vectors always gives you a scalar is just a generalization that is easily unnoticeable when working in 1-dimension with the number line, since 1-dimensional vectors always have just one dimensional component anyway.
So, while some people claim that multiplication of scalars and the dot-product are completely different, since multiplication of scalars yields you an object having the same type as the operands, others will acknowledge the fact that multiplication of scalars is just the dot-product of two vectors applied to vectors in 1-dimension. When you look at multiplication as the latter, it is obvious that the dot-product and multiplication should be represented in the same manner and it makes perfectly logical sense that you can (and, in my opinion
should) represent them with the same operator. Since the operations can be generalized the same way, they can in turn be used in generic programming with templates the same way, since using operator* as a generalization of the dot product can apply to multiplication as well without problem.
Aside from that, it makes much more logical sense to use operator * for multiplication than it would, for example, to have the addition operator concatenate strings or the left shift operator to output text to a stream, although I personally will not argue against either one. If you argue against operator* for dot product since it's not multiplication, I'd expect you to have even bigger gripes with the latter two examples.
I don't expect to change your opinion, neither do I want to, as it is mostly subjective unless you wish to take advantage of the generalizations I've mentioned. You should, however, know that overloading operator* for dot-product is not as obscure as you might think.
[Edited by - Polymorphic OOP on March 4, 2005 4:34:18 AM]