Advertisement Jump to content


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


2D Rotation

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

I''ve been working on this for a little while not, and can''t figure out to do it. Currently, I''ve written a simple graphics program, and would like to add the ability to rotate an array to a given angle (radians, degrees, whatever) and then draw that image to the screen (using data from the arrays) Problem is, obviously, I can''t do it My system now is really weird, and I''m probably the only person on the planet who would do it in a strange way (it made sense to me at the time) I take the sin() of the angle, and plot that many pixels in the y direction. Then I take cos() of the same angle, and plot that many pixels in the x direction. I repeat this until the edge of the array, then repeat with the next line. Unfortunately, this doesn''t work (go figure... lol) I did manage to get a somewhat rotated version on the screen, but it was terribly skewed. I''m sure there is a better way to do this, probably using sin/cos to a greater extent. I''m pretty sure I''ve seen a method to do it before on one of the forums, but without the search feature, its quite difficult to find any of the old posts. Any suggestions as to how I could display a rotated version of an array''s contents (through pixel plotting) would be greatly appreciated.

Share this post

Link to post
Share on other sites
Sorry to bump, won''t do this again :D We really need to get that search feature back up... it''s really helped in the past

Share this post

Link to post
Share on other sites
Guest Anonymous Poster

Share this post

Link to post
Share on other sites
This is for quadratic equations, if not then reading this is a waste of time. Hopefully that isnt the case.

Rotation Invariants:

The rotation of the coordinates axes through an angle theta that transforms the equation:

Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0

into the form:

A'(x')^2 + C'(y')^2 + D'x' + E'y' + F' = 0

by rotating with:

cot2(Theta) = (A - C)/B

so your rotation variants are:

1. F = F'
2. A + C = A' + C'
3. B^2 - 4AC = (B')^2 - 4A'C'

Notice the discrimanent in #3
You can use that for classification, if you need to.

1. Ellipse or circle: B^2 - 4AC < 0
2. Parabola: B^2 - 4AC = 0
3. Hyperbola: B^2 - 4AC > 0

Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0
This equation is probably what you are looking for since it can be graphed on a 2D plane or axis.
(NOTE) NOT ALL VARIABLES HAVE TO BE USED, ONLY THE ONES THAT APPLY. I dont' ever remember having variables all the way to F.

Hopefully I helped


[edited by - JYoung on January 20, 2003 11:07:55 AM]

Share this post

Link to post
Share on other sites
maybe this will help,

to find the coordinates of point A rotated about B for any angle you can use this formula:

x1 = ((Ax-Bx)*Cos(angle) - (Ay-By)* Sin(angle))+Bx;
y1 = ((Ax-Bx)* Sin(angle) + (Ay-By)* Cos(angle))+By;

x1,y1 = your new x and y coordinates for point A.

Also you are need to resize or catch any rotated points that go out of bounds in your array.

I haven''t tried it this way but it should do the job.

Anime:Drugs would be cheaper.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!