• Create Account

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

### #1tracegame  Members   -  Reputation: 127

Like
0Likes
Like

Posted 26 May 2012 - 07:08 PM

Dear sirs,
I have a very silly question about 2d vector dot product and matrix multiply problem
this is a piece of code from 2d Polygon collision tutorial

the vector and matrix are defined like this

class Vector
{
public:
float x,y;
inline float operator * (const Vector &V) const { return (x*V.x) + (y*V.y); } // dot product
inline Vector operator * (float s) const { return Vector(x*s, y*s); }
...
...
}


here is what i don't understand

// two objects collided at time t. stop them at that time
void CBody::ProcessCollision(CBody& xBody, const Vector& N, float t)
{
//N is direction to push polyA away from polyB,D is relative velocity i think
Vector D = m_xDisplacement - xBody.m_xDisplacement;

//what is the following three line calculating?
float n = D * N;
Vector Dn = N * n;
Vector Dt = D - Dn;

if (n > 0.0f) Dn = Vector(0, 0);
//what does a vector dot product itself stand for?square of its length?
float dt = Dt * Dt;
float CoF = s_fFriction;

if (dt < s_fGlue*s_fGlue) CoF = 1.01f;
D = -(1.0f + s_fRestitution) * Dn - (CoF) * Dt;

float m0 = GetInvMass();
float m1 = xBody.GetInvMass();
float m = m0 + m1;
float r0 = m0 / m;
float r1 = m1 / m;

m_xDisplacement += D * r0;
xBody.m_xDisplacement -= D * r1;
}


Edited by tracegame, 27 May 2012 - 04:19 AM.

### #2wildbunny  Members   -  Reputation: 550

Like
0Likes
Like

Posted 27 May 2012 - 04:30 AM

Dn = displacement in normal direction
Dt = displacement in tangential direction
dt = squared length of displacement vector

### #3Radikalizm  Crossbones+   -  Reputation: 2766

Like
0Likes
Like

Posted 27 May 2012 - 06:09 AM

If I may make a small note on the use of the * operator within your vector class:
In my experience the * operator is used for scalar products between two vectors, not dot products, and I assume this could lead to some confusion later on when using scalar products, or when you're using another library which uses * for scalar products

It might be worth thinking about implementing a separate dot(...) method for doing dot-products, as to avoid any confusion

### #4tracegame  Members   -  Reputation: 127

Like
0Likes
Like

Posted 27 May 2012 - 07:56 PM

thank you wildbunny.
and thank you Radikalizm,i know what you mean,this tutorial is not written by me,you're right,it did confuse me the first time,and i will never override it like this.

### #5Tom KQT  Members   -  Reputation: 1496

Like
0Likes
Like

Posted 28 May 2012 - 04:13 AM

In my experience the * operator is used for scalar products between two vectors, not dot products, and I assume this could lead to some confusion later on when using scalar products, or when you're using another library which uses * for scalar products

It might be worth thinking about implementing a separate dot(...) method for doing dot-products, as to avoid any confusion

Dot product between two vectors and scalar product between two vectors is the same thing. Aren't you confusing dot product (also called scalar product) with cross product (also called vector product)?

### #6Radikalizm  Crossbones+   -  Reputation: 2766

Like
0Likes
Like

Posted 28 May 2012 - 04:21 AM

In my experience the * operator is used for scalar products between two vectors, not dot products, and I assume this could lead to some confusion later on when using scalar products, or when you're using another library which uses * for scalar products

It might be worth thinking about implementing a separate dot(...) method for doing dot-products, as to avoid any confusion

Dot product between two vectors and scalar product between two vectors is the same thing. Aren't you confusing dot product (also called scalar product) with cross product (also called vector product)?

I might have been getting my names mixed up, sorry for that
I meant to say per-component multiplication as in the case in which A would be defined as (a1, a2, a3) and B as (b1, b2, b3), and where a resulting vector C = A*B would become (a1*b1, a2*b2, a3*b3)

Maybe my view on math libraries is completely off, but in most implementations I've seen the * operator was reserved for this multiplication, while the dot product and cross product had their own respective functions

Again sorry for the confusion of the names

Edited by Radikalizm, 28 May 2012 - 04:21 AM.

### #7Tom KQT  Members   -  Reputation: 1496

Like
0Likes
Like

Posted 28 May 2012 - 04:54 AM

Oh so you meant component-wise multiplication. That really isn't a common vector operation in vector calculus.
You can see this operation in computer math libraries or in math applications (for example in MATLAB etc.), but I personaly don't think that's the typical operation you'd expect from the * operator between two vectors. But that's just my opinion.

Anyway, what I said earlies still applies, these are three different operations:
• scalar or dot product - the result is a scalar, typical notation is a b
• vector or cross product - the result is a vector (only in 3D space), typical notation is a × b
• component-wise multiplication - the result is a vector, in any space, but this is rather an "array" operation than a "vector" one, also afaik doesn't have any common notation, I've seen few different

Edited by Tom KQT, 28 May 2012 - 04:58 AM.

### #8Radikalizm  Crossbones+   -  Reputation: 2766

Like
0Likes
Like

Posted 28 May 2012 - 05:13 AM

Yes, it is in fact more of an array operation, but when it comes down to games it is used quite frequently.
Shader languages used this notation too if I'm not mistaken.

By the way, I'm fully aware of the different vector operations, it was more of a confusion since I've never had any linear algebra classes in english, so I mix up the names quite easily

### #9Tom KQT  Members   -  Reputation: 1496

Like
0Likes
Like

Posted 28 May 2012 - 05:40 AM

Shader languages used this notation too if I'm not mistaken.

Yea, that's right, it works that way in HLSL. That didn't come to my mind.

it was more of a confusion since I've never had any linear algebra classes in english, so I mix up the names quite easily

Hehe, no worries, I haven't either

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS