Jump to content
  • Advertisement
Sign in to follow this  
babarorhum

3D vectors; Rotating one vector , expecting the other to "follow"

This topic is 2565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone,

This might a very trivial question for many of you :)

There are two 3D vectors A and B. The angle Alpha is between Vector A and B.
B origin is in fact the end point of Vector A.

By a rotation of Vector A, i would like vector B to "follow" and share with Vector B the same angle as before.

To give you a concrete example:

Originally :
[font="Menlo"][font="arial, verdana, tahoma, sans-serif"] [/font][/font]
Vector A is from : x = 1 , y= 4 z = 0 to x = 3.82 y =1.17 z = 0
Vector B is from : x = 3.82 , y = 1.17 z = 0 to x= 3.82 , y = 1.17 and z = -3

Vector A rotates 90 degrees And reach the following position from x = 1 y = 4 z = 0 to x = 5 y = 4 z = 0

And i get Vector B being : from x = 5 , y = 4 , z = 0 to x = 3.5 , y = 5.5 and z = -2.12

However, i would expected the Vector B to be in the following position : x = 5 y = 4 z = 0 to x = 5 , y = 4 and z = -3


I tried various options with a rotation matrix;sometimes ending it up in null cross products; other times having a unit vector which explain the "unwished rotation".
Now i am going to some translation of vectors on a same plane but i am meeting some issues in specific situation, where the Vector A and B are both on 2 dimensions instead of 3...

In other words, I am open to your wisdom :)

Would anyone know how to solve this problem ?

Many thanks in advance for any pointer or help you can provide :)

Babarorhum

Share this post


Link to post
Share on other sites
Advertisement
Hidden
If I follow correctly, you have two vectors A and B, B is on the tip of A, so you have positions for these vectors. So A and B both have a position, direction and length. Save this info, rotate A direction to get a new A direction.

Old A Position = known
Old A Direction = A end - A Start (normalize after length)
Old A Length = Length(OldADirection)

Old B... = Same as A

New A Position = old A Position
New A Direction = rotate old A Direction (vector rotation)
New A Length = old A Length

New B Position = old A position + New A Direction * old A Length
New B Direction = old B Direction
New B Length = old B Length

Share this post


Link to post
If I follow correctly, you have two vectors A and B, B is on the tip of A, so you have positions for these vectors. So A and B both have a position, direction and length. Save this info, rotate A direction to get a new A direction.

Old A Position = known
Old A Direction = A end - A Start (normalize after length)
Old A Length = Length(OldADirection)

Old B... = Same as A

New A Position = old A Position
New A Direction = rotate old A Direction (vector rotation)
New A Length = old A Length

New B Position = old A position + New A Direction * old A Length
New B Direction = old B Direction
New B Length = old B Length

New A Start = Old A Start
New A End = Old A Start + New A Direction * Old A Length

New B Start = New A End
New B End = New B Start + Old B Direction * Old B Length

Share this post


Link to post
Share on other sites
Hello,

Thanks for your reply. It's exactly what i am looking for. I have tried it before; however i have met an issue when the New Vector A and old Vector B share the same direction on a 2D plane.

For example, let's imagine:

  • 'old' Vector A still have the coordinates (x,y,z ) : from 1, 4, 0 to 1,0,0
  • 'old' Vector B is from 1,0,0 to 4,0,0

    A rotation happens on Vector A , it gives:
    • 'New' Vector A from 1,4,0 to 5,4,0.
    • and with the solution below, it would give: new Vector B : 5,4,0 to 8,4,0.
      However, it would be expected new Vector B to be 5,4,0 to 5,7,0 if the angle alpha is kept between Vector A and B.

      Perhaps i misinterpreting the solution, or this is a special case. So far, i have been able to handle it as a special case, but i am looking for a generic solution if it exists of course.

      Babarorhum


      If I follow correctly, you have two vectors A and B, B is on the tip of A, so you have positions for these vectors. So A and B both have a position, direction and length. Save this info, rotate A direction to get a new A direction.

      Old A Position = known
      Old A Direction = A end - A Start (normalize after length)
      Old A Length = Length(OldADirection)

      Old B... = Same as A

      New A Position = old A Position
      New A Direction = rotate old A Direction (vector rotation)
      New A Length = old A Length

      New B Position = old A position + New A Direction * old A Length
      New B Direction = old B Direction
      New B Length = old B Length

      New A Start = Old A Start
      New A End = Old A Start + New A Direction * Old A Length

      New B Start = New A End
      New B End = New B Start + Old B Direction * Old B Length

Share this post


Link to post
Share on other sites
Hello,
Thanks NumberXaero. I went for the initial solution you have proposed and combined it with a rotation when the vectors are either on the same plane or are co-linears.
After couple of testing rounds, i've found an interesting case ; and would not mind having your insight :

Vectors are defined as follow:

  • "Old Vector A": Begin: [font=Menlo][size=2]1.000000,4.000000,0.000000 , End:3.828427,1.171573,0.000000[/font]
  • [font="Menlo"][size=2][font=arial, verdana, tahoma, sans-serif]

    "Old Vector B : Begin: [/font][/font][font=Menlo][size=2]3.828427,1.171573,0.000000 , End:2.328427,2.671573,-2.121320[/font]
  • [font="Menlo"][size=2][font=arial, verdana, tahoma, sans-serif]

    New Vector A : Begin : [/font][/font][font=Menlo][size=2]1.000000,4.000000,0.000000 , End:5.000000,4.000000,0.000000[/font]
    [font=Menlo][size=2][font=arial, verdana, tahoma, sans-serif]

    and following the initial solution i obtained:[/font][/font]
    • [font=Menlo][size=2][font=arial, verdana, tahoma, sans-serif]

      New Vector B : Begin[/font][/font][font=Menlo][size=2][font=arial, verdana, tahoma, sans-serif]

      3.500000,5.500000,-2.121320 , End:2.085787,6.914214,-0.121320

      [/font][/font]
      i would say it works precisely according to the calculation: taking the end of new Vector A ; and calculate the end of new vector B based on its direction * length.

      However, it doesn't seem to align completely with the movement of these two vectors: originally old Vector B has known a rotation of 90 degrees around Old Vector A and a 45 degrees against old Vector A. Therefore i would have expected a New Vector B inclined of 45 degrees against new Vector B with a Y coordinates in value 4.

      The thing is that the direction of old Vector B always define an increase of y coordinates; therefore the solution doesn't seem to apply to this situation (as keeping a y = 4 from end point of new vector A to end point Vector B ; would require to have an old vector B y-direction equal to 0) .
      Or am i totally off-track and it's the actual result is correct but the expected one which is incorrect ?


      Any help , insights are super welcome :)

      Babarorhum

Share this post


Link to post
Share on other sites
Am I correct in assuming that what you have is like an arm, where vector A goes from shoulder to elbow, and vector B goes from elbow to wrist, and what you want is to
lock the elbow and rotate at the shoulder. The locked elbow, B's, position would move, but its angle with vector A remains locked? I just want to make sure I understand the problem.

Share this post


Link to post
Share on other sites
All you need to do is input your 3 points A, End A, End B, mulitply those by your rotation matrix, and you have what you want. To get the new vector subtract the transfromed versions of those. You don't need to transform points and add vectors and multiply all that stuff. If you treat them as 3 points, and you rotate them as 3 points, then they are held together still and geometrically identical.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!