
-----------------------------------
nemesest
Thu Apr 27, 2006 8:50 pm

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

-----------------------------------
Clayton
Thu Apr 27, 2006 8:53 pm


-----------------------------------
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
Thu Apr 27, 2006 9:08 pm


-----------------------------------
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:

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
Thu Apr 27, 2006 9:14 pm


-----------------------------------
You could also draw one picture and use Pic.Rotate to rotate it.

-----------------------------------
Clayton
Thu Apr 27, 2006 9:23 pm


-----------------------------------
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


fcn Math_Distance (x,y,x2,y2:int):real
    result sqrt((x2-x)**2+(y2-y)**2)
end Math_Distance

simple enuf right?

-----------------------------------
do_pete
Thu Apr 27, 2006 9:33 pm


-----------------------------------
:?: Yes it is...

a^2+b^2=c^2
(a^2+b^2)^0.5=(c^2)^0.5
(a^2+b^2)^0.5=c

-----------------------------------
Clayton
Thu Apr 27, 2006 9:41 pm


-----------------------------------
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
Thu Apr 27, 2006 9:46 pm


-----------------------------------
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

-----------------------------------
do_pete
Thu Apr 27, 2006 10:04 pm


-----------------------------------
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
Fri Apr 28, 2006 8:38 am


-----------------------------------
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
Fri Apr 28, 2006 9:16 am


-----------------------------------
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
Fri Apr 28, 2006 10:59 am


-----------------------------------
or you could do it properly and do it my way.  its not like there's anything hard about it.  :?

-----------------------------------
Cervantes
Fri Apr 28, 2006 2:44 pm

Re: Rotating line
-----------------------------------
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
Fri Apr 28, 2006 3:34 pm


-----------------------------------
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
Fri Apr 28, 2006 7:22 pm


-----------------------------------
 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

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


Very unreliable . . . :withstupid:

-----------------------------------
NikG
Mon May 01, 2006 12:37 am


-----------------------------------
Try this and tell me if it's not buggy (cuz it definitely was for me!):setscreen ("graphics:100;100;nobuttonbar;offscreenonly")

var chars : array char of boolean
var angle : int
angle := 90

loop
    Input.KeyDown (chars)
    if chars (KEY_LEFT_ARROW) then
        angle := min (179, angle + 2)
    elsif chars (KEY_RIGHT_ARROW) then
        angle := max (1, angle - 2)
    end if

    drawfillarc (30, 10, 20, 20, 0, 180, 1)
    drawfillarc (30, 10, 30, 30, angle - 1, angle + 1, 1)

    View.Update
    delay (10)
    cls
end loop

-----------------------------------
jamonathin
Mon May 01, 2006 6:09 am


-----------------------------------
Yes it's "buggy" but that is because you are trying to draw that arc on such a fine degree.  The reason it does this is because the rounding methods - which are required, round the angles with the provided information in order to draw them.  Since the number is so fine, at about 1/3 and 2/3 of every 90 degrees the numbers swap - resulting in a reverse arc.

Technically it is and isn't a bug, but simply change -1 to -2 and vice versa.

- I did like the max/min method for adding to angle.

-----------------------------------
NikG
Tue May 02, 2006 10:15 pm


-----------------------------------
Yes it's "buggy" but that is because you are trying to draw that arc on such a fine degree.  The reason it does this is because the rounding methods - which are required, round the angles with the provided information in order to draw them.  Since the number is so fine, at about 1/3 and 2/3 of every 90 degrees the numbers swap - resulting in a reverse arc.

Technically it is and isn't a bug, but simply change -1 to -2 and vice versa.Ok, so you're right about changing it from "angle-1" to "angle-2"... the "bugginess" seems to disappear, so maybe drawfillarc isn't as unrealiable as I said, EXCEPT if you DO need a very fine degree.  In that case, trig is a better (the best?) choice.
