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

Username:   Password: 
 RegisterRegister   
 Basic gravity equation.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
14fenix




PostPosted: Fri Sep 26, 2003 2:26 pm   Post subject: Basic gravity equation.

This is a very simple program thats like a sort of hwk for my compsci class yet Im stumped because I keep gettin "Argument is the wrong type" message. All the program has to be is a ball falling towards the ground, each pixel = 1 m and the acceleration is 32 / t ** -2.

Any help?? Pretty n00bish question but I gotta start somewhere. Here is my code so far

code:


setscreen ("graphics")
var x, y, t, a, ymax : real
ymax := 399
t := 0
x := 20
a := 32 / t ** 2
loop
    y := ymax - 9.8 * a * t ** -2
    drawfilloval (20, y, 6, 6, 5)
    t := t + 1
    delay (1000)
end loop



Thanks.
Sponsor
Sponsor
Sponsor
sponsor
PaddyLong




PostPosted: Fri Sep 26, 2003 3:56 pm   Post subject: (No subject)

it's because the draw methods take integer parameters, and you are trying to give real ...
as a solution to this, use round(someReal) to turn it into an integer ...

in your case, you would change
drawfilloval (20, y, 6, 6, 5)
to be
drawfilloval (20, round(y), 6, 6, 5)

however, you have other problems in your program and I will give you a hint to start t at 0.1 rather than 0 or change your equation for solving a
Tony




PostPosted: Fri Sep 26, 2003 4:45 pm   Post subject: (No subject)

yeah, your equation is really messed up. Your acceleration is constant = 9.81. You dont need acceleration variable.

Quote:

D = Vi*T + (1/2)(A)(T^2)


Knowing physics really comes in handy when you're programming physics related stuff.

So your code should be:

code:

for t:1..10
     Draw.FillOval(100,maxy - round(4.9*t*t),5,5,red)
end for


a bit of expanation here:

since Vi is 0, first part of formula is 0.

4.9 is (1/2) or acceleration (which is 9.81)

*t*t is time squared. pow() (** in turing) is a function and will slow down your program. If the power is a constant integer, write it out - program works faster.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
14fenix




PostPosted: Fri Sep 26, 2003 5:18 pm   Post subject: (No subject)

Wow its amazing how simple it really was lol. Im using a Turing handbook from school that gave me the weird acceleration equation so I thought I'd use it but I did know gravity = -9.8 m/s^2

Thanks a lot.
krishon




PostPosted: Fri Sep 26, 2003 5:20 pm   Post subject: (No subject)

well the gravity varies depending on the location, but only by like .02 or .01 so no huge difference....but in rocket science that's a different matter
vexd




PostPosted: Sat Sep 27, 2003 9:15 pm   Post subject: (No subject)

/\d = 1/2*A */\t ** 2 + V1 * /\t


^ best equation Razz
thoughtful




PostPosted: Sat Oct 11, 2003 8:50 pm   Post subject: Try this

Try this code
code:

var x : int := 100
for decreasing t : 10 .. 1
    Draw.FillOval (x, maxy - round (4.9 * t * t), 5, 5, red)
    x := x + 15
    delay (30)
end for
for t : 1 .. 10
    Draw.FillOval (x, maxy - round (4.9 * t * t), 5, 5, red)
    x := x + 15
    delay (30)
end for
Prince




PostPosted: Sat Oct 11, 2003 9:52 pm   Post subject: (No subject)

vexd wrote:
/\d = 1/2*A */\t ** 2 + V1 * /\t


^ best equation Razz

what equation is that? Confused
Tony




PostPosted: Sat Oct 11, 2003 10:16 pm   Post subject: (No subject)

change in distance equals to initial velocity multiplied by change in time plus half of acceleration multipled by time squared.

Laughing

you can find distance traveled by accelerating object using acceleration and time Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
rizzix




PostPosted: Sat Oct 11, 2003 10:26 pm   Post subject: (No subject)

lol thats a delta symbol o ok. sheesh i was wondering what he meant by that Laughing

nice avatar
rizzix




PostPosted: Sat Oct 11, 2003 10:45 pm   Post subject: (No subject)

ok i just realised i'm using a mac so to show off:

Option + j = ∆ (delta)
Option + d = ∂ (partial differential)
Option + m = µ (mu)
Option + w = ∑ (sigma)
Option + b = ∫ (integral)
Option + x = ≈ (aprox equal to)
Option + r = ®
Option + g = ©
Option + 2 = â„¢
Option + f = Æ’
Option + s = ß (beta)
Option + z = Ω (omega)
Option + p = π (pie)
Option + 5 = ∞ (infinity)
Option + v = √ (square root)
Option + Command + k = ° (degrees)
Option + , = ≤
Option + . = ≥
Option + / = ÷
Option + = = ≠ (not equal to)


a lot more but these are the most useful ones
Tony




PostPosted: Sat Oct 11, 2003 10:50 pm   Post subject: (No subject)

what encoding are you using? cuz symbols are all screwed up for me
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
rizzix




PostPosted: Sat Oct 11, 2003 10:55 pm   Post subject: (No subject)

oh! unicode.. it shows all.. thus i always use it (default encoding)

anyhow i switched to the western ISO encoding.. it seems it's more popularly used by windows users :/
Mazer




PostPosted: Sun Oct 12, 2003 8:27 am   Post subject: (No subject)

rizzix wrote:

a lot more but these are the most useful ones


well that's good. hey maybe someday people will actually be able to pronounce (and draw) those letters without pissing me off. Laughing hah, but that will never happen
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: