Computer Science Canada

[Tutorial] Simple arc movement

Author:  mwachna [ Sat Mar 05, 2005 5:52 pm ]
Post subject:  [Tutorial] Simple arc movement

This is a fairly easy way of moving in an arc, and it allows you to control the shape of the arc.

Remember simple math and parabolas?...well that's just an arc.

this will move a circle with centre point x,y, with a radius of 2.

code:

var y:real:=0
var: Start, End:int            %these are your starting and ending x values
Start:=0                          %this will move the ball in an arc from one
End:=maxx                     %end of the screen to the other.
for x:Start..End
        y:=-1*(x**2)+maxy
    drawfilloval(x,y,2,2,red)
    delay (10)
drawfilloval(x,y,2,2,white)
end for


This code will of course send the ball right off the top of the screen and back. So we need to adjust the limits of the 'y' value and thus controlling the width of the arc.

We are using the basic formula of a parabola known as:y=c(x+a)^2+b

'a' will control the positioning of the parabola along the X-axis

'b' will control the vertical positioning of the parabola

'c' will control the "fatness" of the parabola's arc

Originally, the parabola opens upwards in the first quadrant. By multiplying it by a negative one, we reflect the arc through the X-axis.

We have added maxy to the equation to bring the arc back into the first quadrant.
Now to have the arc widen, we will have to divide the y value. so really we make 'c' a value of less than 1 thus dividing it. To make the ball touch the top of the screen at the peak of its climb we will make 'c'=1/250.
And finally, we need to move the arc so its vortex is located at "maxx"
We do this by decreasing the value of "a" to negative "maxx div 2."
Our new equation is now: y=1/250(x-maxx/2)^2+maxy
so in code it will look like this:

code:

y := (-1 * ((x - maxx div 2) ** 2)) div 250 + maxy


and when we plug this into our program, we create a ball that moves from the lower left corner, to the top of the screen, and finishes at the bottom right corner:
code:

var y := 0
var Start, End : int         
Start := 0                       
End := maxx                   
for x : Start .. End
    y := (-1 * ((x - maxx div 2) ** 2)) div 250 + maxy
    drawfilloval (x, y, 2, 2, red)
    delay (10)
    drawfilloval (x, y, 2, 2, white)
end for

Author:  ssr [ Mon Mar 07, 2005 7:26 pm ]
Post subject: 

yes thats nice
just use a little grade 10 math and u will be amazed

btw, I thought we aklready had a post on this topis
Very Happy

Author:  person [ Mon Mar 07, 2005 9:33 pm ]
Post subject: 

that post was the post that asked how to do the arc thing in turing help

Author:  mwachna [ Tue Mar 08, 2005 12:14 pm ]
Post subject: 

I did see a post, but the author was explainning arc using trig. You could do either way, but this was much more simple to me.

Author:  jamonathin [ Tue Mar 08, 2005 12:17 pm ]
Post subject: 

KISS, it's the way to do it Razz

Author:  person [ Tue Mar 08, 2005 3:34 pm ]
Post subject: 

speaking of KISS...is it the term that every teacher uses???? cuz everyone seems to kno it

Author:  ssr [ Tue Mar 08, 2005 9:42 pm ]
Post subject: 

pff
I saw it in a book
and my teachers never say it Crying or Very sad

Author:  Andy [ Wed Mar 09, 2005 4:01 pm ]
Post subject: 

wtf is KISS? for a problem like this, why not just use the winding function and simply use (cosx, sinx) to trace out the circle

Author:  The_$hit [ Wed Mar 09, 2005 5:41 pm ]
Post subject: 

How would you make the circle bounce off of an object, and continue going in its arc?

Author:  Flikerator [ Wed Mar 09, 2005 6:08 pm ]
Post subject: 

The_$hit wrote:
How would you make the circle bounce off of an object, and continue going in its arc?


You could possibly use whatdotcolour, or use a grid collision.

Author:  person [ Wed Mar 09, 2005 6:15 pm ]
Post subject: 

Quote:
How would you make the circle bounce off of an object, and continue going in its arc?


dont think it makes much sense since where an arc curves is already planned

Author:  mwachna [ Wed Mar 09, 2005 6:27 pm ]
Post subject: 

Andy wrote:
wtf is KISS? for a problem like this, why not just use the winding function and simply use (cosx, sinx) to trace out the circle


With this equation, you can easily manipulate the trajectory of the arc, and its position. As well, most arcs are not perfect half circles.

-matt
-Go T-Cats!-

Author:  mwachna [ Wed Mar 09, 2005 6:30 pm ]
Post subject: 

The_$hit wrote:
How would you make the circle bounce off of an object, and continue going in its arc?


if you want an object who is already in motion to collide with a surface, and then start a NEW arc, then you will have to use some more math calculations, calculating both angles of trajectory and gravitational effects.

Sorry, but I don't like math THAT much, you will just have to bash this one out, or hope someone already knows formulas for this.

-matt
-Go T-Cats!-

Author:  person [ Wed Mar 09, 2005 6:55 pm ]
Post subject: 

if u want something that bounces off (such as a line)..there's Zaster bunny's code where u turn positive to negative and ...(just go check it out)...

Author:  Andy [ Wed Mar 09, 2005 9:35 pm ]
Post subject: 

mwachna wrote:
Andy wrote:
wtf is KISS? for a problem like this, why not just use the winding function and simply use (cosx, sinx) to trace out the circle


With this equation, you can easily manipulate the trajectory of the arc, and its position. As well, most arcs are not perfect half circles.

-matt
-Go T-Cats!-


wtf? who said anything about half circles? and who said you manipulate the position/size of the arc with cos and sin? do you not take math or something?

Author:  mwachna [ Wed Mar 09, 2005 9:51 pm ]
Post subject: 

no sorry, I'm a drama student, so I just figured anything that if I understood it, it's pretty staight forward and simple...If I didnt understand it...then it's not as simple. If trig works for ya, more power to ya...I just stick to what I know.


: