Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

rotating problem

Posted on 1998-10-07
3
Medium Priority
?
248 Views
Last Modified: 2010-04-16
I want to rotate an object.
I have found a way to do that but I need a
formula that gets an angle out of the sin() or cos()
of it.
( I have the angle (a) and I want to find the X ->  
  sin(X) = a )
0
Comment
Question by:yyyannag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 400 total points
ID: 1215759
For each coordinate of the old image, the new coordinate can be found by using this formula:

OldImageX = NewImageX * cos(theta) - NewImageY * sin(theta)
OldImageY = NewImageX * sin(theta) + NewImageY * cos(theta)

(theta is angle in radians)


NewImageX and Y is the new, rotated image coordinates.  OldImage is the coordinates to extract the pixel from the old image.

Example:


  for i := 0 to NewSprite.Width - 1 do
    for j := 0 to NewSprite.Height - 1 do begin
      nx := (round(x*Cos(A)-y*Sin(A)));
      ny := (round(x*Sin(A)+y*Cos(A)));
      Sprite[i,j] := OldSprite[nx,ny];
    end;


Note that A must be in radians.  To convert from degrees to radians, you multiply by (pi/180).

Example:  the sin of 45 degrees would be

sin(45*pi/180);

In your question, you said you wanted to find X if sin(x) = a.  This would entail finding the inverse sin of a.  I don't know why you would want to find this.  But if you really need to know how to calculate an inverse sin in pascal:

function arcsin(x:real):real;
begin
  arcsin := arctan(x/sqrt(1-sqr(x)));
end;


If you send the function a real value (from -1 to 1 inclusive, the range of the sin function), it will return an angle in radians.

This function will have no practical purpose in rotating something, so consider looking over calculations again.

But your question also says you have the angle.  If you want to find the sin of the angle (which is probably what you want to do) you simply use the sin function:

X := sin(a);  {a is in radians; see note above}


Your formula, sin(x) = angle, would NEVER be used in any practical calculation anywhere.

Try using the formulas I gave you above (OldImageX..etc.) and if that is not what you want let me know.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215760
I made I typo in my answer!! Change this line:


      Sprite[i,j] := OldSprite[nx,ny];

to this:


      NewSprite[i,j] := OldSprite[nx,ny];
0
 
LVL 2

Author Comment

by:yyyannag
ID: 1215761
Thanks for the formula, it was very helpful
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Shawn
IT teams define success as solving problems quickly. To enable ITSM modernization we have to think of adopting the tools and methods that will enable resolution of ITSM issues more quickly.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question