I can't seem to get the correct output when overloading the *operator to find the dot product.
Would appreciate if anyone could help.
Correct output:
38.45
My output:
9.84
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <complex>
class fvector2D: public std::complex<float>
{
public:
fvector2D(float x=0, float y=0) : std::complex<float>(x, y)
{
}
float X()const
{
return realm();
}
float Y()const
{
return imagm();
}
float operator* (fvector2D& factor)
{
float result3;
result3 = X() * factor.X();
result3 += X() * factor.Y();
return result3;
}
};
int main()
{
fvector2D v(3, 4.1f);
fvector2D u(1.2f, 8.5f);
std::cout << (a * d) << std::endl; //Finding of the dot product
}
|
Last edited on
You state that the dot product a*b is aX * bX + aX * bY
Why did you choose that a 2D vector IS-A complex number?
I think you should see it if you use simpler tests
for example, try u = (2, 100)
v = (1, 0)
v = (0, 1)
v = (0, 0)
v = (1, 1)