Public Group

# Help with rotating 2d vectors (C#, SDL.NET)

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

## Recommended Posts

Hi all! I am using SDL.NET with C# and trying to understand 2d vectors. Could someone help me with following or point me to a tutorial for dummies :) I have four vectors/points Vector Location A 10,10 B 10,20 C 20,10 D 20,20 So its a square. How can I rotate all of them n degrees a) from vector A,B,C or D b) from point 15,15 (middle point of square) and still keep the square shape?

##### Share on other sites
A 2D point can be rotated around it's origin using the following formulas, where theta is the number of degrees you want to rotate:

x' = cos(theta) * x - sin(theta) * y
y' = sin(theta) * x + cos(theta) * y

Since 15, 15 is probably not the origin in your case, you can translate the negative point, rotate, and then reverse the translation.

##### Share on other sites
Quote:
 Original post by KuraitouSince 15, 15 is probably not the origin in your case, you can translate the negative point, rotate, and then reverse the translation.

Translate?

The situation is following http://tviljan.kapsi.fi/kuva1.png

On top is the original and below is the situation that I would like to get.

A C

X <- Point of rotation

B D

##### Share on other sites
I think that you will find this thread very helpful. The post by esaint will make it as simple as possible to understand.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013546
×