My 3D Vector class

This is a discussion on My 3D Vector class within the C++ Programming forums, part of the General Programming Boards category; Yeah, looks better. I still think you ought to be checking for v being 0 though, and dividing by it's ...

  1. #91
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Yeah, looks better. I still think you ought to be checking for v being 0 though, and dividing by it's magnitude... I haven't looked at the new version of the class, so I may be reading things a bit incorrectly (my apologies if I am). Are all vectors automatically normalized?
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  2. #92
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Thanks .

    BTW, Silvercord, do you actually believe this :

    void main is totally sweet
    Do not make direct eye contact with me.

  3. #93
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    naw I don't

    I kind of forgot I had that up there. I was hoping more people would get ........ed at me for it

  4. #94
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Originally posted by Zach L.
    Are all vectors automatically normalized?
    No, but don't look at previous ones. I'm uploading a zip right now.
    files.zip:
    Attached Files Attached Files
    Last edited by Lurker; 11-15-2003 at 08:42 PM.
    Do not make direct eye contact with me.

  5. #95
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You have to normalize both vectors and also check whether v's length is 0.
    Code:
    float angleBetween(const Vector3D &v) const {
     normalize();
     v.normalize( )
     float temp = length();
     if(temp == 0.0f || v.length( ) == 0.0f ) {
      return;
     }
     acosf(dotProduct(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

  6. #96
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    There are a couple problems I found with that particular function. The trivial ones: a missing semi-colon, and a return statement with no value.

    There are a couple of other problems, however. You call normalize. This cannot be done from the angleBetween function because that function is const, and you can't modify the class from a const function. Regardless, you really don't want to change the user's vector without their knowledge (i.e. determining the angle between two vectors should not change either).

    The other thing still relates to the vector dot product. The dot product is:

    u*v = |u| |v| cos a
    cos a = u*v / (|u| |v|)

    Therefore, you have to divide by both their magnitudes to get the angle (which requires checking to see if both are 0 magnitude vectors).

    Cheers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  7. #97
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Originally posted by Zach L.
    There are a couple problems I found with that particular function. The trivial ones: a missing semi-colon, and a return statement with no value.

    There are a couple of other problems, however. You call normalize. This cannot be done from the angleBetween function because that function is const, and you can't modify the class from a const function. Regardless, you really don't want to change the user's vector without their knowledge (i.e. determining the angle between two vectors should not change either).

    The other thing still relates to the vector dot product. The dot product is:

    u*v = |u| |v| cos a
    cos a = u*v / (|u| |v|)

    Therefore, you have to divide by both their magnitudes to get the angle (which requires checking to see if both are 0 magnitude vectors).
    Already fixed all of the problems .
    Try the zip again, I changed it before you posted .
    Last edited by Lurker; 11-15-2003 at 08:36 PM.
    Do not make direct eye contact with me.

  8. #98
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Uhh... Seems to be the same file that was there a few minutes ago.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  9. #99
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Try again - I've changed a few things. You may have to delete some temporary files .
    Do not make direct eye contact with me.

  10. #100
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Hmm... Odd thing is I did. Is this still current?
    Code:
    float Vector3D::angleBetween(const Vector3D &v) const {
    	normalize();
    	float temp = length();
    	if(temp == 0.0f) {
    		return;
    	}
    	acosf(dotProduct(v))
    }
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  11. #101
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Nevermind, cache problem with my browser.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  12. #102
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Yes, it is annoying, isn't it? I can never tell when I have actually uploaded something .
    Do not make direct eye contact with me.

  13. #103
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Indeedy... One thing I noticed when testing... Just a minor bug: dotProduct(v) needs to be vn.dotProduct(v2n).

    Something else is a bit screwy with it at the moment (its not returning the right value), but I can't pinpoint why right now... It looks correct. I'll get back to you when I figure it out.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  14. #104
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Umm... I have no clue what was going on, but it is working now.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  15. #105
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Hey Silvercord - it seems kind of interesting your vector class is EXACTLY the same as another one on NeHe .
    Do not make direct eye contact with me.

Page 7 of 8 FirstFirst 12345678 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3D Network Analysis Tool
    By durban in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 11-08-2005, 05:33 PM
  2. A 3D Program for my 3D models...?
    By Rune Hunter in forum C++ Programming
    Replies: 26
    Last Post: 08-19-2004, 10:04 AM
  3. 3D starfield
    By VirtualAce in forum Game Programming
    Replies: 6
    Last Post: 06-26-2003, 12:40 PM
  4. 3D SDK for C++ programmers
    By chand in forum Game Programming
    Replies: 2
    Last Post: 05-20-2003, 07:38 AM
  5. 3d engines
    By Unregistered in forum Game Programming
    Replies: 7
    Last Post: 12-17-2001, 10:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21