I've Private Messaged you.Originally posted by Silvercord
Do you plan on making a game? I assume you are, but you could also be doing something like a CAD program.
BTW, this is a general class, no specific idea in mind as of yet .
This is a discussion on My 3D Vector class within the C++ Programming forums, part of the General Programming Boards category; Originally posted by Silvercord Do you plan on making a game? I assume you are, but you could also be ...
I've Private Messaged you.Originally posted by Silvercord
Do you plan on making a game? I assume you are, but you could also be doing something like a CAD program.
BTW, this is a general class, no specific idea in mind as of yet .
Do not make direct eye contact with me.
Well, the project I'm working on is extremely complex, and I'm still at the "get stuff to work" phase. I have a lot of organization in the code, but 90% of the effort is going into making sure the algorithms and the incredibly complex mathematics work correctly and are aesthetically pleasing. I'm trying to rely on stl containers as much as possible to avoid bugs (i.e memory management with std::auto_ptrs), and I'm also looking into the boost library. Optimizations and what I consider little things (easy things) will come later, but I actually do fundamentally agree with you cat, peace d00d.
EDIT: lurker, an email with my Vector class and my Quaternion class is on my way. Both of these could be optimized, i.e I know that in both i pass by value a lot which is especially dumb when using quaterinions. Some of the things I just made up, i.e the 'fast homo morphism' function in the quaternion code is something you'll never find on a tutorial. It just cancels calculations when the w component of the quaternion is zero.
Last edited by Silvercord; 11-15-2003 at 06:51 PM.
OK, thanks. BTW, does this look like a good (err....okay ) function to return the angle between 2 vectors?
It will be optimized later, but I mean the basic structure .Code:float angleBetween(const Vector3D &v) const { float temp = length(); if(temp == 1) { return acos((dotProduct(&v) * (3.1415926 / 180))); } return acos((dotProduct(&v) / temp * v.length()) * (3.1415926 / 180)) }
Do not make direct eye contact with me.
Shouldn't you get the angle using acosf, and *then* convert it to degrees?
i.e
return (acos((dotProduct(&v)) * 180) / PI
I normalize all of my vectors, and actually, I keep everything in radians all the time (even in my other code).
Last edited by Silvercord; 11-15-2003 at 07:09 PM.
If you're not going to normalize the vectors first, you have to divide the dot product by the product of their magnitudes before you can take its arccosine.
Code:u dot v = |u||v|cos(x) x = arccos( u dot v / |u||v| )
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
that's what he did
XSquared, you haven't been concentrating on my posts much, have you ?
Do not make direct eye contact with me.
Didn't notice that code at the end there. Heh.
Also, you're missing a set of parentheses, and why are you converting to radians before you pass to acos? Acos returns an angle in radians, its parameter is just a ratio, so you'd actually want to convert to degrees after the call.
Code:return acos((dotProduct(&v) / ( temp * v.length()))) * (180/(4 * atan(1)))
Last edited by XSquared; 11-15-2003 at 07:24 PM.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
shouldn't you be taking the acos, and then converting it to degrees?
Right, thanks. How this:
Code:float angleBetween(const Vector3D &v) const { float temp = length(); float toRads = ((1 / 3.1415926) * 180); if(temp == 1) { return acos((dotProduct(&v) * toRads)); } return acos((dotProduct(&v) / (temp * v.length())) * toRads) }
Do not make direct eye contact with me.
I'm converting it to radians, and then leaving them that way.Originally posted by Silvercord
shouldn't you be taking the acos, and then converting it to degrees?
EDIT: The dot product returns an angle in degrees, right? Or should I not have to even convert them to radians in the firstplace?
Do not make direct eye contact with me.
the dotproduct gives you the cosine in radians. acosf accepts its parameter in radians. No conversion is necessary. If you want to convert to degrees, you have to get an answer from acosf, then convert that to degrees
//if it's normalized already
float radian = acosf(dotproduct(a,b));
float degree = (radian * 180) / PI
EDIT: it wouldn't make sense for it to be in degrees by the way, because degrees doesn't measure any real values, but radians are a real ratio of the distance travelled divided by the radius of a the circle, so just always assume radians are being used. degrees are only for readability, and im such a dork i keep everything in radians anyway.
Duh, I was thinking that the dot product was returning degrees .
Do not make direct eye contact with me.
don't worry about it, mistakes are fun
I suggest you stop implementing things until you are ready to use them, that way you find bugs immediately and know what in the holy hell caused them. If you hadn't posted that code you would have waited a week to use it, had a bug, and had no clue where it was and you would've eaten your neighbor's family.
Lets try this:
Code:float angleBetween(const Vector3D &v) const { float temp = length(); if(temp == 1) { return acosf(dotProduct(&v)); } return acosf(dotProduct(&v) / (temp * v.length())) }
Do not make direct eye contact with me.