#### Archived

This topic is now archived and is closed to further replies.

# turning a vector 90 degrees

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

## Recommended Posts

I have an asteriod and when you shoot it. I have 2 smaller asteriods appear. What I am tryinig to do is to make 2 smaller asteriods appear to the side and move in opposite direction of the large asteriod. The large asteriod has a position vector, velocity vector and a direction vector. I was wondering when I shoot the asteriod how do I make the 2 smaller asteriods appear 90 from the direction vector of the large asteriod. I have tried the following and they don't seem to work right: newAstrDir.x = (largeAstrDir.x) * cos(D3DX_PI/2) -largeAstrDir.y* sin(D3DX_PI/2); newAstrDir.y = (largeAstrDir.x) *sin(D3DX_PI/2) + largeAstrDir.y * cos(D3DX_PI/2); and newAstrDir.x = sqrt((largeAstrDir.x) * (largeAstrDir.x) + (largeAstrDir.y) * (largeAstrDir.y)) * cos(D3DX_PI/2); newAstrDir.y = sqrt((largeAstrDir.x) * (largeAstrDir.x) + (largeAstrDir.y) * (largeAstrDir.y)) *sin(D3DX_PI/2); Thanks for the help [edited by - l3arknight on March 6, 2004 7:15:03 PM]

##### Share on other sites
The great thing about rotating 2D vectors by 90 degrees is that all you have to do is switch some components. Given a direction vector (x,y), two vectors perpendicular to it are (y,-x) and (-y, x). This can be proven knowing the dot product between orthogonal vectors is 0. xy + y(-x) = x(-y) + yx = 0. Normalize as/if necessary.

##### Share on other sites
Thanks worked like a charm..

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 12
• 17
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633358
• Total Posts
3011511
• ### Who's Online (See full list)

There are no registered users currently online

×