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

Username:   Password: 
 RegisterRegister   
 Trajectory
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Sean




PostPosted: Wed Mar 26, 2008 5:47 pm   Post subject: Trajectory

Alright, I'm making a program that deals with a person shooting an arrow, and flying at a target.

This is what I believe needs to happen..

The program needs to check for the angle of the shot, then calculate the motion of it and the speed depending on the given power. The angle comes into affect, along with gravity to pull it down to the target, creating an arch effect.

Velocity, Gravity, Force, and Motion are what I need?

But since there is no mass on the arrow, then it would be flying always at a constant speed, if it had a certain mass, and depending on the power it would either slow down, and speed up.

Or, am I over thinking this too much?
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Mar 26, 2008 5:59 pm   Post subject: RE:Trajectory

is this inspired by the game bowman?
just wondering.

unfortunately, you (although a programming noob) are far more advanced than me in using turing (as you pointed out in my thread)
and I cannot help you
Sean




PostPosted: Wed Mar 26, 2008 6:01 pm   Post subject: Re: Trajectory

It's somewhat like bowman, but mine is just Archery. Shoot at a target board, hit a certain area, get certain points and such.
Saad




PostPosted: Wed Mar 26, 2008 6:06 pm   Post subject: Re: Trajectory

Your over thinking it way too much, all you need is basic kinematics.

All you need to use is vectors and split it into its horizontal and vertical components since they are both independent of each other.

Vx = cos (theta) * Power
Vy = sin (theta) * Power

Using the split components its just plugging into simple kinematic equations.
Sean




PostPosted: Wed Mar 26, 2008 6:10 pm   Post subject: Re: Trajectory

Our Gr. 10 Science class never got to vectors, but I guess I got some research to do.

Thanks
Sean




PostPosted: Fri Mar 28, 2008 6:58 am   Post subject: Re: Trajectory

Okay, I can possibly get them in advance, but I might not be able to do it.

Saad, if you have a link of some sort that breaks down the formula into its sections then I would appreciate it.

All I know to do is Cos so far, guess I'll have to speak to my Science Teacher to get extra work outside of the semester. I don't have it anymore, but I'd like to learn it.
Saad




PostPosted: Fri Mar 28, 2008 2:44 pm   Post subject: Re: Trajectory

This should cover up on basic kinematics.
Sean




PostPosted: Fri Mar 28, 2008 4:17 pm   Post subject: Re: Trajectory

Thanks you.
Sponsor
Sponsor
Sponsor
sponsor
Sean




PostPosted: Sat Mar 29, 2008 7:03 pm   Post subject: Re: Trajectory

Okay, I have the other formulas, but I don't know the formula for Thead, if you can supply a link or the formula, I'd appreciate it.
LaZ3R




PostPosted: Sat Mar 29, 2008 7:55 pm   Post subject: RE:Trajectory

Bud, you're overthinking this WAY Too much...

You simply get the angle to the horizontal based on where you are shooting.

the horizontal component (your x) will be moving at a constant speed (since you are not factoring any air resistance/friction).

the vertical component (your y) will be pulled down by "gravity" but you have to understand that you are making your own gravity in the game.

Saad's post mentions:

Vx = cos (theta) * Power
Vy = sin (theta) * Power

... There's NOTHING to it. It's simple so just try to understand it an you will.

You are treating the x values and y values as two seperate quantities. If you take grade 12 physics you'll understand this much simpler. If you're not in grade 12 yet, just go learn this yourself and search google, it takes two seconds.

Vx = velocity in the x direction.
power = just a multiplier...
theta = angle which determines how fast the projectile will b traveling in the x direction once you take the cos of it.

You take cos of the angle for x since you are looking for the horizontal component (vector) of the actual angle itself.

Then for y, you use sin to calculate it for the vertical.

Now, as I said, in physics, we assume that there is no air resistance to greatly simplify problem solving , and because it really doesn't make a difference in an indoor setting (Outdoor is much different :p).

Therefore, once you launch the projectile, you are no longer calculating the angle (unless you are going to have a tail on your projectile which in that case you will). The x position of the projecile will simply add the Vx variable onto itself over and over again. The y position of the projectile will be adding the Vy variable onto itself over and over again, BUT, yu have to decrease the value of Vy by 1 or 2 every time the projectile moves so that it starts "falling" sooner or later.

Get this working and you'll understand it a lot more.
The_Bean




PostPosted: Sun Mar 30, 2008 9:19 am   Post subject: Re: Trajectory

Ok I'm not sure if this is what your looking for, but I think it might be.
If its not it still looks cool

Turing:

View.Set ("graphics:500,500,offscreenonly,nobuttonbar,title:trojectory")
var xm, ym, bm : int
var x, y : int
var xDiff, yDiff : int
var angle : int
var power : int := 5
var chars : array char of boolean
function setAngle (x, y : real) : real
    if x = 0 and y = 0 then
        result 0
    elsif x = 0 and y > 0 then
        result 90
    elsif x = 0 and y < 0 then
        result 270
    elsif y = 0 and x > 0 then
        result 0
    elsif y = 0 and x < 0 then
        result 180
    else
        result abs (arctand (y / x))
    end if
end setAngle
loop
    Mouse.Where (xm, ym, bm)
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        power += 1
    end if
    if chars (KEY_DOWN_ARROW) then
        power -= 1
    end if
    cls
    angle := round (90 + setAngle (xm, ym))
    xDiff := round (cosd (angle) * power * 10)
    yDiff := round (sind (angle) * (angle - 90) * 5)
    for decreasing i : angle .. 180 - angle
        x := round (cosd (i) * power * 10) - xDiff
        y := round (sind (i) * (angle - 90) * 5) - yDiff
        Draw.Dot (x, y, 7)
    end for
    put power
    View.Update
    delay (25)
    exit when chars (chr (32))
end loop
cls
for decreasing i : angle*10 .. (180 - angle)*10
    cls
    x := round (cosd (i/10) * power * 10) - xDiff
    y := round (sind (i/10) * (angle - 90) * 5) - yDiff
    Draw.FillOval (x, y, 5, 5, 7)
    View.Update
    delay(0)
end for
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  [ 11 Posts ]
Jump to:   


Style:  
Search: