• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
MylesEvans

Slope of a line after a rotation. Help.

7 posts in this topic

I made a similar thread but I worded it weird and didnt really get the answer I was looking for. So here is a better worded question that I hope someone can help me with solving.


Given a line with slope m, if the line is rotated 90? clockwise the slope of the resulting figure is ? 1/m, how can I determine the slope if the line is rotated 30? or 60? clockwise. What if its rotated 210 degrees, or 350?

I need to come up with a formula that will factor in the original slope, take/apply the amount I want to rotate, and give me the new slope. Edited by GDsnakes
0

Share this post


Link to post
Share on other sites
If a line has slope m, then it advances m units in the y direction for each 1 unit advanced in the x direction. Therefore we can represent the direction of the line using the 2D vector v=(1, m).

When we rotate the line by an angle d, we apply [url="http://en.wikipedia.org/wiki/Rotation_matrix"]a 2D rotation matrix[/url] M(d) = [ (cos(d), -sin(d)) (sin(d), cos(d)) ] to the line direction vector. This means that the rotated line has the direction vector v' = M(d)*v = ( cos(d) - m*sin(d), sin(d) + m*cos(d) ).

The slope of the rotated line with the direction vector v' is then ( sin(d) + m*cos(d) ) / ( cos(d) - m*sin(d) ). Be sure to handle the special case when cos(d) - m*sin(d) = 0, i.e. when the line is vertical and the slope is essentially "infinite".
0

Share this post


Link to post
Share on other sites
I also get (m*cos(d)+sin(d))/(cos(d)-m*sin(d)) .

May I suggest using a better representation for a direction than the slope of the line? My favorite is a unit-length vector (which can be interpreted as a complex number to make rotations easier).
1

Share this post


Link to post
Share on other sites
I second the idea of ditching slopes.

Slope is calculated as rise over run. m=y/x. However, if x==0, then you have a problem. In vector form, you can represent a vertical line as (x=0, y=1) whereas in slope form you would have to represent it as (1/0) which is undefined.

If you really need to know the actual slope of a line (for whatever reason) you can perform the division after the fact, just be prepared to deal with the edge cases.
0

Share this post


Link to post
Share on other sites
(m*cos(d)+sin(d))/(cos(d)-m*sin(d))

What is this? Does this (m*cos(d)+sin(d)) give me the rise and this (cos(d)-m*sin(d)) the run?

I don't want this in vector form.

My code goes something like this. Object A is always wherever the base object is, but moved Y units up (rise) and X units over (run).
Now when I want to rotate the "slope" (Object A's position relative to the base Object) so the slope is not going to be constant. Which is why I made this thread asking for a formula to represent the change in the slope. So now my code needs to work like this.

Object A is draw wherever the base object is drawn but up *Y units determined by formula that accounts for rotation* and over *X units determined by formula that accounts for rotation* So I basically need to know how rotation affects the rise and the run, but not in vector form.
0

Share this post


Link to post
Share on other sites
You really, really don't want to work directly with slope if you are allowing rotation. You want to work with vector form, because eventually your slope is likely to become undefined, if the "run" is ever equal to 0. Working in vector form essentially means that instead of keeping track of "slope", you keep track of "rise" and "run" instead. It's just that if object A is directly above the base object, if you are working with vector form then things won't crash and burn, but if you are working with slope you will suddenly end up with a divide-by-zero exception.

Just remember that in vector form, the x component equals "run" and the y component="rise".

That being said, the general form for 2D rotation about a point is:

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

Where A is the angle by which to rotate.
0

Share this post


Link to post
Share on other sites
[quote name='GDsnakes' timestamp='1350933720' post='4992867']
(m*cos(d)+sin(d))/(cos(d)-m*sin(d))

What is this?
[/quote]

That's exactly what you asked for. It is the slope after rotation by an angle d of a line that used to have slope m.
0

Share this post


Link to post
Share on other sites
[quote name='FLeBlanc' timestamp='1350936150' post='4992881']
You really, really don't want to work directly with slope if you are allowing rotation. You want to work with vector form, because eventually your slope is likely to become undefined, if the "run" is ever equal to 0. Working in vector form essentially means that instead of keeping track of "slope", you keep track of "rise" and "run" instead. It's just that if object A is directly above the base object, if you are working with vector form then things won't crash and burn, but if you are working with slope you will suddenly end up with a divide-by-zero exception.

Just remember that in vector form, the x component equals "run" and the y component="rise".

That being said, the general form for 2D rotation about a point is:

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

Where A is the angle by which to rotate.
[/quote]

Thank you very much. This is exactly what I was looking for. Also don't worry about the run equaling zero because my code is written in a way where that wont be a problem. There will be no 0 in any denominators.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0