#### Archived

This topic is now archived and is closed to further replies.

# Names of vector operations

## Recommended Posts

I am making a 2D game with physically accurate object movement and collisions. I managed to make it work, but I have one small problem - since using scalars, like object.x += object.vx; object.y += object.vy; was boring, I decided to create my own vector library and now I can write vector_add(&object.position, &object.velocity); I''m rewriting all my game to use vectors and now I have a problem - what names should I give to my vector functions. For example, if there is float value = a.x * b.x + a.y * b.y; in my code, then I put a vector_dot_product(&a, &b) function there. But what to do with this: float value = a.y * b.x - a.x * b.y; I want to do: float value = vector_operation_with_some name_that_other_people_can_understand_and_not_laugh_at_me(&a, &b); but does this operation have some special name? Another example: c.x = a.x * b.y + a.y * b.x; c.y = a.y * b.y - a.x * b.x; I searched the web, but found only vector sums, dot products and cross products. Are there some special names for other vector operations or should I invent my own terminology?

##### Share on other sites
quote:

c.x = a.x * b.y + a.y * b.x;
c.y = a.y * b.y - a.x * b.x;

This is called complex product, where .y is the real part and .x is the imaginary part.

quote:

float value = a.y * b.x - a.x * b.y;

This can be called something like dot_product_rotating_one_of_the_vectors_90_degrees_first, but it''s a pretty long name.
You can also think of it as evaluating a vector internal product which is not the standard dot product and whose matrix is
[0 +1]
[-1 0]

This means that you compute vector_a * M * vector_b_transposed.

##### Share on other sites
quote:
float value = a.y * b.x - a.x * b.y;

This is the z component of CrossProduct(b,a).

##### Share on other sites
Thanks for the replies. At least now I have some idea what should I search for .

##### Share on other sites
While you''re at it, look for "operator overloading", if you''re using C++. It makes vectorial operations look much nicer.

Cédric

##### Share on other sites
Just to expand what cedricl said, a little;
It makes operations like...

Vector A, B, C;
...
//Init A, B & C
...
A = B + C;
A += B;
A /= C;
C = A * B;

... possible

##### Share on other sites
And how exactly do you define division of a vector by a vector?

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

##### Share on other sites
What makes you think /= must denote division? It''s just a symbol. Use it for whatever you like.

##### Share on other sites
quote:
Original post by Anonymous Poster
What makes you think /= must denote division? It''s just a symbol. Use it for whatever you like.

No. Don''t do that. The whole point of operator overloading is to make the code clearer. Sure, you can map operator+ to the substraction of two vectors, but it defeats the purpose of operator overloading.

Cédric

##### Share on other sites
What makes you believe someone would like to use + to denote subtraction?

##### Share on other sites
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

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites

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

##### Share on other sites
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

##### Share on other sites
quote:
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?

##### Share on other sites
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...

##### Share on other sites
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]

##### Share on other sites
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]

##### Share on other sites
my eyes hurt. blah blah blah blah blah.

"We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle

##### Share on other sites
quote:
Can we all agree that vector / vector doesn''t make sense?

Depends on what kind of algebra you''re talking about. In geometric algebra, it''s all good.

---- --- -- -

##### Share on other sites
We can simply define 1 / Vector as the reciprocal (say, Vector'') of that vector. Then Vector / Vector = Vector * Vector'' = Scalar.

Personnally, I''d use the ^ operator to represent what you call cross-product or whatever, and * for the scalar product.

As a side question, which one do you use most:

A.B = ||A|| * ||B|| * cos(A, B) or
A^B = k * ||A|| * ||B|| * sin(A, B)
(k being normal to the plane defined by A and B)

And C.x = A.x * B.x is what I would call "scaling a vector by a different along each axis"...

Cheers, ToohrVyk

Extatica is coming soon!
Check it out on:
http://www.extatica.com02.com
Nexeruza Studios:
http://nexeruza.ionichost.com/home.html

##### Share on other sites
quote:
Original post by Anonymous Poster
I do? Interesting interpretation...

Then, what are you doing here, except pointing out that my examples are *dumb*?

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

I do

Cédric

##### Share on other sites
I think a component-wise division or multiplication would be useful in doing vector space conversion (i.e. ellipsoid collision detection)

• ### Forum Statistics

• Total Topics
628326
• Total Posts
2982086

• 22
• 9
• 9
• 13
• 11