• Advertisement
Sign in to follow this  

How to find a new vector which lies 60 degrees away from an existing one?

This topic is 3231 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

I would like to find a point which lies 60 degrees away from the forward facing vector and is at some distance in front of a character. Are the following steps correct? 1) Find the normalized forward facing vector of the character 2) For the x and z components, multiply each of them by cos 60 3) Multiply the new vector by a value and then add the vector to the position of the character to find the new point which lies 60 degrees away and is at a distance in front of the character Also, how do I specify if the point lies in a clockwise or anticlockwise direction away from the character's forward facing vector?

Share this post


Link to post
Share on other sites
Advertisement
Multiplying by cos 60 is not enough, that will simply change the magnitude of the vector and not the direction. Instead you need to do the following:

newx = x * cos(angle) - z * sin(angle)
newz = z * cos(angle) + x * sin(angle)

Depending on your coordinate system and transformation matrix, you might want to switch places for the + and -. Usually, increasing a positive angle gives a counter-clockwise movement.
To move in the other direction, simply set angle to -60 instead of +60.

Your other steps are correct.

Share this post


Link to post
Share on other sites
I personally find it more practical to express that kind of transformation with more high-level tools, such as quaternions or matrices.

Doing such operations directly is prone to error.

Share this post


Link to post
Share on other sites
I used the following to find the new vector which lies 60 degrees away from the current normalized forward facing vector.

newx = x * cos(60) - z * sin(60)
newz = z * cos(60) + x * sin(60)

However, it looks like the new vector's orientation is not correct. Sometimes, the new vector points behind the character, even though the angle is less than 180.

Whether I used x and z as the character position's x and z components or as the character forward facing vector's components, the problem is still the same.

What could be wrong with the method?

Or is there a better method like using matrices?

I have checked that the angle is correctly converted to radians in the code and also tried swapping the - and + signs.

Share this post


Link to post
Share on other sites
I don't understand what you're trying to get.
Express it with actual mathematical terms (60 degrees away from a vector doesn't mean anything to me) and its relation with the first vector in terms of vector operatins, quaternions and/or matrices will come naturally.

Share this post


Link to post
Share on other sites
Provided you have the following information:

p = position of character
v = forward facing direction of character, normalized

and want to find a target point pt, at some distance d from p, in a direction a radians from the forward facing direction, as in the following image:


You can achieve this the following way:

dir.x = v.x * cos(a) - v.y * sin(a);
dir.y = v.y * cos(a) + v.x * sin(a);

pt = p + dir * d;

Share this post


Link to post
Share on other sites
Wouldn't it be better if you did the following instead:-

1. Get the transformation matrix.(I think we need inverse in this case - not sure though)
2. Multiply it by a 60 degree rotation matrix(-60 for cw).
3. Get the forward direction
4. Normalize the forward direction.
5. Then do NewPosition = currentPosition + (fowardDirection * someFactor)

This way you don't have to worry about what kind of coordinate system you are using i.e. if UP is y or z etc.

Share this post


Link to post
Share on other sites
rotate v 60 degrees and multiply it by your distance.
There you go, you've got the vector that goes from p to pt.

You just need to code the function that takes a vector and an angle and returns the new rotated vector.

Share this post


Link to post
Share on other sites
Yes, finally it's working correctly.

Thank you to all for the help :D

Share this post


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

  • Advertisement