Posted: Thu Apr 27, 2006 8:50 pm Post subject: Rotating line
Hi, I'm a grade 11 computers student and I'd like to know:
how would I make a line, outside a circle and touching it, go around the circle.
/
O
O--
etc..
So the line would rotate around the circle.
It's for making a radar program that I plan to use for history presentation.
Thanks
Sponsor Sponsor
Clayton
Posted: Thu Apr 27, 2006 8:53 pm Post subject: (No subject)
you could use trig to find the angle you want it to move to next, or you could use the equation of a circle somehow to find all points on your circle (x^2+y^2=r^2) and draw lines around your central point to the point on that circle
Delos
Posted: Thu Apr 27, 2006 9:08 pm Post subject: (No subject)
I would suggest sticking with the Trig concepts. Incorporating loci is just a little too complicated for as simple a task as this.
Base your programme on triangles and the Pythagoras theorem. At any given point, you'll be drawing the hypotenuse of a triangle whose length will be the radius of the circle. Cycle through all 360 degrees of that circle, using Trig to determine the Opp and Adj lengths; which will allow you to calculate coordinates.
You might need these commands:
code:
sind ()
cosd ()
tand ()
Math.Distance ()
If the version of Turing you're using does not have Math.Distance (), it's a sinch to make. It's just Pythagoras theorem, nothing more.
do_pete
Posted: Thu Apr 27, 2006 9:14 pm Post subject: (No subject)
You could also draw one picture and use Pic.Rotate to rotate it.
Clayton
Posted: Thu Apr 27, 2006 9:23 pm Post subject: (No subject)
actually Delos, the Math.Distance isnt pythagorean theorem(idk how to spell that lol), its more the distance of a line, if you dont have it you can make it like this
Turing:
fcn Math_Distance (x,y,x2,y2:int):real resultsqrt((x2-x)**2+(y2-y)**2) end Math_Distance
simple enuf right?
do_pete
Posted: Thu Apr 27, 2006 9:33 pm Post subject: (No subject)
Posted: Thu Apr 27, 2006 9:41 pm Post subject: (No subject)
ah but the distance formula is the change in x and y, not just a point you have (which is what you are trying to say in your above eqn) so you have to use the distance formula (or at least it is more handy, and works in exactly the same way as Math.Distance
zylum
Posted: Thu Apr 27, 2006 9:46 pm Post subject: (No subject)
code:
View.Set ("offscreenonly")
const r := 20
const R := 100
const rotationSpeed := 1
var theta : int := 0
loop
Draw.Oval (maxx div 2, maxy div 2, r, r, black)
Draw.Line (round (cosd (theta) * r + maxx div 2), round (sind (theta) * r + maxy div 2), round (cosd (theta) * R + maxx div 2), round (sind (theta) * R + maxy div 2), black)
theta += rotationSpeed
View.Update
delay (20)
cls
end loop
just need sin and cos
Sponsor Sponsor
do_pete
Posted: Thu Apr 27, 2006 10:04 pm Post subject: (No subject)
SuperFreak82 wrote:
ah but the distance formula is the change in x and y, not just a point you have (which is what you are trying to say in your above eqn) so you have to use the distance formula (or at least it is more handy, and works in exactly the same way as Math.Distance
Um... the distance formula is Pythagorean's Therom, it just uses x1-x2 as a y1-y2 as b. And it is not the change in x and y but the difference between the two values.
codemage
Posted: Fri Apr 28, 2006 8:38 am Post subject: (No subject)
How about just doing a Draw.FillArc?
If you make it only a few degrees wide, it'll look like a line, and then all of the trig is done for you, and it's automatically centred on your circle's coordinates. (You just put in the angles, and it draws).
Albrecd
Posted: Fri Apr 28, 2006 9:16 am Post subject: (No subject)
Or you could draw the line first from (maxx div 2, maxy div 2) to points that gradually move around the perimeter of the screen (preferably roughly a circle beyond the edges of the screen. [The circle formula as stated by SuperFreak82 would be useful for this]). You could then just draw the circle overtop in the centre of the screen.
zylum
Posted: Fri Apr 28, 2006 10:59 am Post subject: (No subject)
or you could do it properly and do it my way. its not like there's anything hard about it.
Cervantes
Posted: Fri Apr 28, 2006 2:44 pm Post subject: Re: Rotating line
nemesest wrote:
how would I make a line, outside a circle and touching it, go around the circle.
...
It's for making a radar program that I plan to use for history presentation.
I'm confused. The first line suggests to me that you want to draw a line tangent to the circle, and move that line around the circle, keeping it always tangent. But the second line (the word "radar" in particular) suggests to me that you want to draw the line from the centre of the circle to the edge of the circle, and move that point on the edge of the circle around the circle.
NikG
Posted: Fri Apr 28, 2006 3:34 pm Post subject: (No subject)
codemage wrote:
How about just doing a Draw.FillArc?
If you make it only a few degrees wide, it'll look like a line, and then all of the trig is done for you, and it's automatically centred on your circle's coordinates. (You just put in the angles, and it draws).
I'm not sure how much difference there is between Draw.FillArc and drawfillarc but don't do it that method! It's very unrealiable (sometimes, it fills all angles except the ones you want for no reason).
jamonathin
Posted: Fri Apr 28, 2006 7:22 pm Post subject: (No subject)
NikG wrote:
don't do it that method! It's very unrealiable (sometimes, it fills all angles except the ones you want for no reason).
I'd like you to show me what you mean. Oh wait here's an example
code:
setscreen ("offscreenonly")
var angle1, angle2 : int := 0
angle2 := 2
loop
angle1 += 1
angle2 += 1
if angle1 > 360 then
angle1 := 1
end if
if angle2 > 360 then
angle2 := 1
end if
cls
Draw.FillArc (maxx div 2, maxy div 2, 100, 100, angle1, angle2, black)
View.Update
exit when hasch
end loop