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

Username:   Password: 
 RegisterRegister   
 how do you draw a line and make it swing in a full circle while one end of it is fixed on the screen?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tianxiao




PostPosted: Fri Jan 09, 2009 7:33 pm   Post subject: how do you draw a line and make it swing in a full circle while one end of it is fixed on the screen?

i tried making the program with a line fixed at one point and the line would swing in a circle. Not much success so far. any suggestions?
Sponsor
Sponsor
Sponsor
sponsor
Laplace's Demon




PostPosted: Fri Jan 09, 2009 7:35 pm   Post subject: Re: how do you draw a line and make it swing in a full circle while one end of it is fixed on the screen?

What grade are you in? Doing this requires trigonometry.

That said, if the line itself is not important and trigonometry scares you, then you could use the procedure "drawarc". You can use this to create a small indicator at the end of an imaginary line, so it can be used to indicate values on a gauge for example.
Tony




PostPosted: Fri Jan 09, 2009 7:41 pm   Post subject: RE:how do you draw a line and make it swing in a full circle while one end of it is fixed on the screen?

To draw a line, you need to know the two points. One of the points is fixed, making that part very easy. The other point follows the circumference of a circle. What is the formula for the circle?

(Alternatively, and perhaps easier if you know the math, you could treat the line as a ray of fixed length and find it's end position using angles (via trigonometry)).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
tianxiao




PostPosted: Fri Jan 09, 2009 7:41 pm   Post subject: RE:how do you draw a line and make it swing in a full circle while one end of it is fixed on the screen?

grade 10, love math, love trig.
tianxiao




PostPosted: Fri Jan 09, 2009 7:42 pm   Post subject: RE:how do you draw a line and make it swing in a full circle while one end of it is fixed on the screen?

yes but how can i put that in a program and make a full circle?
tianxiao




PostPosted: Fri Jan 09, 2009 7:43 pm   Post subject: RE:how do you draw a line and make it swing in a full circle while one end of it is fixed on the screen?

like i need one end of the line free and spinning around the other end of that line.
Laplace's Demon




PostPosted: Fri Jan 09, 2009 7:45 pm   Post subject: Re: how do you draw a line and make it swing in a full circle while one end of it is fixed on the screen?

Allright then. In trig we know that:

sin gives you the Y value on the unit circle

cos gives you the X value on the unit circle.

So you want to use the first point of the line as the origin of a circle, and keep track of an "angle" variable and use sin and cos to find the y and x values of the other end of your line. The sin and cos values will give you points on the unit circle based on your angle, you want to then multiply those values by the desired radius of your circle to find the end of your line.

Try working with that.
Display posts from previous:   
   Index -> Programming, Turing -> Turing 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: