Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to properly use cos and sin to find angles?
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
H H




PostPosted: Sat Mar 03, 2012 10:24 am   Post subject: How to properly use cos and sin to find angles?

I was wondering how to use cos and sin to find the angles of different objects (ex. numbers on a clock). This might seem more like a math lesson, but any help is appreciated.
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Sat Mar 03, 2012 10:42 am   Post subject: RE:How to properly use cos and sin to find angles?

I would look here to find any information you are looking for.


http://www.khanacademy.org/search?page_search_query=Trigonometry


Their videos are very great and informing.
bl0ckeduser




PostPosted: Sat Mar 03, 2012 11:04 am   Post subject: Re: How to properly use cos and sin to find angles?

H H @ Sat Mar 03, 2012 10:24 am wrote:
I was wondering how to use cos and sin to find the angles of different objects (ex. numbers on a clock). This might seem more like a math lesson, but any help is appreciated.


To find the angle between two lines/vectors you can use a dot product formula.

This page (although full of ads) seems to explain it pretty well:
http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors
Raknarg




PostPosted: Sat Mar 03, 2012 1:00 pm   Post subject: Re: How to properly use cos and sin to find angles?

Here's a simple example:
(of course, this is assuming you've learned trigonometry already)



arctan.png
 Description:
 Filesize:  6.05 KB
 Viewed:  16063 Time(s)

arctan.png


bl0ckeduser




PostPosted: Sat Mar 03, 2012 4:48 pm   Post subject: Re: How to properly use cos and sin to find angles?

Raknarg @ Sat Mar 03, 2012 1:00 pm wrote:
Here's a simple example:
(of course, this is assuming you've learned trigonometry already)


Good idea. If you use the arctan technique, I suggest you use atan2(y, x) rather than atan(y / x).

This suggestion because, as the Wikipedia article for atan2() points out,
Quote:
The one-argument arctangent function does not distinguish between diametrically opposite directions.
Raknarg




PostPosted: Sat Mar 03, 2012 5:59 pm   Post subject: RE:How to properly use cos and sin to find angles?

Exactly, which means you have to state all possible cases, which isnt too difficult. What I do is do arctan (y/x) when the points past the origin and do arctan (y/x) + 180 when it's behind the origin. And you also have to take in account dividing by zero
McKenzie




PostPosted: Sun Mar 11, 2012 11:48 am   Post subject: Re: How to properly use cos and sin to find angles?

H H, the reason you are getting the wrong answers is that you asked the wrong question. atan2 is the right answer if you wanted to "find angles" as you stated but if you are trying to find positions on a clock you "find angles" with basic math then use cos and sin to find the point you need. For example:
If you want to draw the second hand of your clock, I assume you know the center of your clock (x1,y1) and the number of seconds (seconds.) You need to:

1. convert your seconds into an angle:
2. find the offset in x,y (This is where you need cos and sin)
3. draw your line.

1. Convert seconds to angles:
Play with the problem on paper until you find a formula. (If you are stuck on this step ask again.)

2. Find the offset. Given the angle and length of a line we can find how far away from your start the end of your second hand is. The only trig you need for this is the unit circle (you may have heard it called "the winding function"):
Posted Image, might have been reduced in size. Click Image to view fullscreen.

dx = length * cos(radians(angle))
dy = length * sin(radians(angle))

The trig functions is python use radians rather than degrees. I assume you calculated your angle in degrees. You will notice I multiplied my sin & cos by length. The unit circle is called the unit circle because the radius is 1. If you want to use this for longer lines simply multiply be the length.

3. Draw the line.
This is the easy part. (If you get stuck here, again ask for more help)
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: