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

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

## 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 on other sites
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.

##### Share on other sites
Don't forget to check if you need to use radians or degrees for your math functions.

##### 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 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 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 on other sites
How many dimensions are you doing this in?

##### Share on other sites
Provided you have the following information:
p = position of characterv = 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 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 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.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5
• ### Forum Statistics

• Total Topics
633363
• Total Posts
3011510
• ### Who's Online (See full list)

There are no registered users currently online

×