Just some terminology that seems different from when I learnt vectors at Uni.
In my mind, This:
double Nv=sqrt( pow(v.x,2) + pow(v.y,2) + pow(v.z,2));
calculates the magnitude or length of vector v.
and this:
double Scal_prod=v.x*w.x+v.y*w.y+v.z*w.z;
is a dot product, not a scalar product. Scalar product is when you multiply each member of the vector by one number - the scalar, it has the effect of "scaling up" the vector.
Never mind, I have just read the wiki page. However I still think my descriptions of scalar, dot, magnitude, unit vector & normal are easier to understand.
I have heard people use the term "normalise", but from context I took it to mean unit vector or otherwise a magnitude. I find this confusing because it is too near to the meaning of a "normal vector", which means "at right angles to" as in a normal to a plane.
Does your naming of the variable Nv refer to the normal of vector v? It is the magnitude of v at the moment.
after all that, to your problem:
The variable prod is not initialised to anything in the function get_theta - did you mean Scal_prod? Probably just a typo.
I can't see anything really wrong with your code, so you should try firstly to use known values rather than random ones.
Next, use the debugger with a watchlist of variables to see where it goes wrong - this is by far the easiest way.
Failing that, put loads of cout statements to check on the variable values.
Interested to see how you go. Cheers
Edit: when I wrote some code to deal with vector I had functions that calculated scalar, dot, magnitude, unit vector & normal, because these functions are used all the time with vector operations.
Edit2:
This is from the reference page:
If the argument is out of this interval, a domain error occurs, setting the global variable errno to the value EDOM. |
Can you make use of this to see if the acos function worked?