Advertisement

Names of vector operations

Started by November 01, 2002 05:41 AM
25 comments, last by Advanced Bug 22 years, 3 months ago
It was an extreme example of what the OP (you?) said:
quote:
What makes you think /= must denote division? It''s just a symbol. Use it for whatever you like.

/= should be used for division, just as += should be used for addition. They are symbols. The mathematical division of a vector by another vector is not defined, so unless /=(vector) is really intuitive to you, you should not use it, as it will confuse everyone else.

Cédric
Just a word of caution about using * and / for vector operations. If A and B are vectors, you don''t just take A*B. You could have the dot product or the cross product, and the * symbol cannot convey that. The same thing goes for the / operator. It must be made clear that when you have C*D, one of them should be a scalar. Hope I can clear some things up.
Brendan
Advertisement
Cedric, interesting that you think doing what you like means doing the insane. I think most people like their code to be clear, so doing what they like would imply doing something useful. Comparing doing something useful with an undefined symbol, with switching the meaning of two already well defined symbols, I find kind of dumb.
quote:
Comparing doing something useful with an undefined symbol, with switching the meaning of two already well defined symbols, I find kind of dumb.

Ok, my example was a little too extreme. So what? / is a symbol that means "division". It makes semantical sense to use it for any class that can be divided by another class. If you decided to name your cross-product function "divide", it wouldn''t be ok, would it?

So, what do you, Anonymous Poster, suggest as a valid operation for VectorA / VectorB? You keep "arguing" that it''s a great thing to make code clear.

Cédric

There are at least 3 vector-vector operations which could be denoted by the * operator: Multiplication of a vector by a vector (r.x = a.x * b.x); The dot product and the cross product.

The use of the ''|'' operator (binary or) as the dot product, for example, is extremely confusing for readers who don''t know the classes. (That is not some idea I just had, I really had to work with such code)

I also think that there is another point to think of: Having, for example matrix multiplication, defined as the ''*''-operator is a kind of euphemism it seems: Such a simple symbol for a comparetively complex operation?
Perhaps one could use the binary NOT for matrix inversion... Making matters worse, operators cannot always return error values, which might occur for example with matrix inversion.

Greetz,
Synopsis
quote:
Original post by synopsis

There are at least 3 vector-vector operations which could be denoted by the * operator: Multiplication of a vector by a vector (r.x = a.x * b.x); The dot product and the cross product.

The use of the ''|'' operator (binary or) as the dot product, for example, is extremely confusing for readers who don''t know the classes. (That is not some idea I just had, I really had to work with such code)

I also think that there is another point to think of: Having, for example matrix multiplication, defined as the ''*''-operator is a kind of euphemism it seems: Such a simple symbol for a comparetively complex operation?
Perhaps one could use the binary NOT for matrix inversion... Making matters worse, operators cannot always return error values, which might occur for example with matrix inversion.

Greetz,
Synopsis


I''ve never heard of a vector-vector multiplication being defined as you do (i.e. multiply the components to get the resultant vector). I don''t think it has much geometrical significance.

I do agree with your point about not defining matrix multiplication with operator overloading, for one thing, when maths people see ABC (multiply 3 matrices), it means "multiply B by C, and then multiply the result on the left by A", i.e. the operator is evaluated from right to left, like composition of functions (which is what matrices sprang out of - combs of linear funcs).

I''ll also note that the Maya API defines * for vector-vector mults as the dot product and also for the normal vector-scalar operation (for 1 vector, 1 scalar forms). It also defines ^ as the cross-product, because XORing vectors together doesn''t make much sense. Still no vector by vector division though, just vector / scalar.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Advertisement
quote:
Original post by Paradigm Shifter
I do agree with your point about not defining matrix multiplication with operator overloading, for one thing, when maths people see ABC (multiply 3 matrices), it means "multiply B by C, and then multiply the result on the left by A", i.e. the operator is evaluated from right to left, like composition of functions (which is what matrices sprang out of - combs of linear funcs).


For matrices, A(BC) = (AB)C. What difference does it make?
quote:
Original post by cedricl
Ok, my example was a little too extreme. So what? / is a symbol that means "division". It makes semantical sense to use it for any class that can be divided by another class. If you decided to name your cross-product function "divide", it wouldn''t be ok, would it?

Another equally dumb example.
quote:
So, what do you , Anonymous Poster, suggest as a valid operation for VectorA / VectorB? You keep "arguing" that it''s a great thing to make code clear.

I do? Interesting interpretation...
You are correct (Miserable). I wasn't thinking there for a moment.

Can we all agree that vector / vector doesn't make sense? Only vector / scalar.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

[edited by - Paradigm Shifter on November 5, 2002 12:23:20 PM]
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
AP, It's blatently odvious you've never worked on a project with more than person, because otherwise you would value the importance of making operators clear and clean-cut. Sure, /= is an operator can be overloaded to do anything, but if you overload it to do something that makes no sense, then not only is it going to be more difficult for someone else looking at the code to have to remember, "Hey /= means ", but if you leave the project for Unknown Reasons, and then come back a month or too later, it's nice to be able to glance at your project on the fly and figure out what it means. For vectors, division with two vectors doesn't make sense, but it's equally as odd to have it mean anything else.

[edited by - Zipster on November 5, 2002 1:11:31 PM]

This topic is closed to new replies.

Advertisement