Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
[Tutorial] Simple arc movement
Author Message
mwachna

Posted: 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

ssr

Posted: 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

person

Posted: 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

Posted: 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

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

KISS, it's the way to do it
person

Posted: 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

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

pff
I saw it in a book
and my teachers never say it
Andy

Posted: 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

The_\$hit

Posted: 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

Posted: 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

Posted: 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

Posted: 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

Posted: 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

Posted: 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

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: