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

Username:   Password: 
 RegisterRegister   
 [Tutorial] Simple arc movement
Index -> Programming, Turing -> Turing Tutorials
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mwachna




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
ssr




PostPosted: Mon Mar 07, 2005 7:26 pm   Post subject: (No 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
person




PostPosted: Mon Mar 07, 2005 9:33 pm   Post subject: (No subject)

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




PostPosted: Tue Mar 08, 2005 12:14 pm   Post subject: (No 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.
jamonathin




PostPosted: Tue Mar 08, 2005 12:17 pm   Post subject: (No subject)

KISS, it's the way to do it Razz
person




PostPosted: Tue Mar 08, 2005 3:34 pm   Post subject: (No subject)

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




PostPosted: Tue Mar 08, 2005 9:42 pm   Post subject: (No subject)

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




PostPosted: Wed Mar 09, 2005 4:01 pm   Post subject: (No 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
Sponsor
Sponsor
Sponsor
sponsor
The_$hit




PostPosted: Wed Mar 09, 2005 5:41 pm   Post subject: (No subject)

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




PostPosted: Wed Mar 09, 2005 6:08 pm   Post subject: (No 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.
person




PostPosted: Wed Mar 09, 2005 6:15 pm   Post subject: (No 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
mwachna




PostPosted: Wed Mar 09, 2005 6:27 pm   Post subject: (No 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!-
mwachna




PostPosted: Wed Mar 09, 2005 6:30 pm   Post subject: (No 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!-
person




PostPosted: Wed Mar 09, 2005 6:55 pm   Post subject: (No 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)...
Andy




PostPosted: Wed Mar 09, 2005 9:35 pm   Post subject: (No 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?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: