Jump to content
  • Advertisement
Sign in to follow this  
Virallinen

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

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

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!