2d vector dot product and matrix problem,please help

Started by
7 comments, last by TomKQT 11 years, 11 months ago
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;
}
Advertisement
Dn = displacement in normal direction
Dt = displacement in tangential direction
dt = squared length of displacement vector

:)
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

I gets all your texture budgets!

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.smile.png

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)?

[quote name='Radikalizm' timestamp='1338120556' post='4943681']
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)?
[/quote]

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

I gets all your texture budgets!

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 36f8ae4c86b69d52d037a6802d91cc4a.png 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
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 :)

I gets all your texture budgets!


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 smile.png

Hehe, no worries, I haven't either :D

This topic is closed to new replies.

Advertisement