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

Started by
2 comments, last by Kuraitou 15 years, 9 months ago
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?
Virallinenvirallinen@googles mail
Advertisement
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.
Quote:Original post by Kuraitou

Since 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
Virallinenvirallinen@googles mail
I think that you will find this thread very helpful. The post by esaint will make it as simple as possible to understand.

This topic is closed to new replies.

Advertisement