1. Anyone know anything about trigonometry?

Hello all,

Does anyone know anything about trigonometry? I am interested in making a
"dueling artillery" game but cannot fathom the math needed to plot arcs. I
know that it has something to do with arc, tan, and cos (?) but what?!

So this is a call to all you mathematicians on the list ;)

Thanks a lot,
David S.

new topic     » topic index » view message » categorize

2. Re: Anyone know anything about trigonometry?

This is a multi-part message in MIME format.

------=_NextPart_000_003F_01C1371C.2C84D7C0
	charset="Windows-1252"

David,

they are not arcs. They are quite complex ballistic curves. But let's
assume we live in a complete vacuum, as some of us do, then we can
approximate them very well with parabolas. And parabolas are dead easy
to calculate, even to draw. The attached small demo is, I hope,
sufficiently commented to give you reasonable idea how to proceed.

jiri

----- Original Message -----
From: <dstanger at belco.bc.ca>
To: "EUforum" <EUforum at topica.com>
Sent: Thursday, 6 September 2001 16:57
Subject: Anyone know anything about trigonometry?


>
> Hello all,
>
> Does anyone know anything about trigonometry? I am interested in
making a
> "dueling artillery" game but cannot fathom the math needed to plot
arcs. I
> know that it has something to do with arc, tan, and cos (?) but
what?!
>
> So this is a call to all you mathematicians on the list ;)
>
> Thanks a lot,
> David S.
>
>
>

------=_NextPart_000_003F_01C1371C.2C84D7C0
Content-Type: application/octet-stream;
	name="Gun.ex"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="Gun.ex"

--  gun.ex
--  jiri babor
--  jbabor at paradise.net.nz
--  6 Sep 2001

include graphics.e

constant d2r =3D PI/180           -- degrees-to-radians factor
constant g =3D 5                  -- acceleration due to gravity
object o
sequence vc                     -- video configuration
atom hspeed,vspeed,x,x0,y,y0
integer angle, color, key, speed, toggle,xmax,ymax

procedure show_header()
    text_color(BLUE)
    puts(1, "enter : toggle lines/dots\n")
    puts(1, "up    : increase angle\n")
    puts(1, "down  : decrease angle\n")
    puts(1, "right : increase speed\n")
    puts(1, "left  : decrese speed\n")
    puts(1, "c     : change trace color\n")
    puts(1, "delete: clear screen\n")
    puts(1, "space : fire\n")
    puts(1, "esc   : quit\n")


    text_color(RED)
    position(11, 1)
    if toggle then
        puts(1, "lines")
    else
        puts(1, "dots ")
    end if
    position(12, 1)
    printf(1, "angle : %2d", angle)
    position(13, 1)
    printf(1, "speed :%3d", speed)
    position(14, 1)
    printf(1, "color : %2d", color)
end procedure

procedure fire()
    hspeed =3D speed * cos(angle*d2r)     -- horizontal speed component
    vspeed =3D -speed * sin(angle*d2r)    -- vertical speed component
    x0 =3D 0                              -- initial projectile position
    y0 =3D ymax                           -- also gun position
    x =3D x0                              -- projectile hor. position
    y =3D y0                              -- projectile ver. position
    while x <=3D xmax and y <=3D ymax do
        vspeed +=3D g                     -- new vertical speed
        x +=3D hspeed                     -- new projectile position
        y +=3D vspeed
        if toggle then
            draw_line(color, {{x0, y0},{x, y}})
        else
            pixel(color, {x, y})
        end if
        x0 =3D x
        y0 =3D y
    end while
end procedure


-- initial (default) parameters:
angle =3D 60                      -- gun angle from horizontal
speed =3D 60                      -- nozzle speed
toggle =3D 1                      -- draw lines
color =3D 15                      -- BRIGHT_WHITE, initial trace color

o =3D graphics_mode(18)           -- 640x480x16
vc =3D video_config()
xmax =3D vc[5]-1
ymax =3D vc[6]-1

show_header()
ellipse(7,1,{-5,ymax-5},{5,ymax+5}) -- gun

key =3D get_key()
while key !=3D 27 do              -- escape
    if key =3D 328 then           -- up arrow
        if angle < 80 then
            angle +=3D 1
            position(12, 9)
            printf(1, "%2d", angle)
        end if
    elsif key =3D 336 then        -- down arrow
        if angle > 10 then
            angle -=3D 1
            position(12, 9)
            printf(1, "%2d", angle)
        end if
    elsif key =3D 333 then        -- right arrow
        if speed < 100 then
            speed +=3D 1
            position(13, 8)
            printf(1, "%3d", speed)
        end if
    elsif key =3D 331 then        -- left arrow
        if speed > 10 then
            speed -=3D 1
            position(13, 8)
            printf(1, "%3d", speed)
        end if
    elsif key =3D 13 then         -- enter: dots/lines toggle
        toggle =3D not toggle
        position(11, 1)
        if toggle then
            puts(1, "lines")
        else
            puts(1, "dots ")
        end if
    elsif key =3D 32 then         -- space: fire!
        fire()
    elsif key =3D 'c' then        -- change trace color
        color +=3D 1
        if color > BRIGHT_WHITE then
            color =3D GREEN
        end if
        position(13, 9)
        printf(1, "%2d", color)
    elsif key =3D 339 then        -- delete: clear screen
        clear_screen()
        show_header()
        ellipse(7,1,{-5,ymax-5},{5,ymax+5})
    end if
    key =3D get_key()
end while
o =3D graphics_mode(-1)           -- back to text mode

------=_NextPart_000_003F_01C1371C.2C84D7C0--

new topic     » goto parent     » topic index » view message » categorize

3. Re: Anyone know anything about trigonometry?


new topic     » goto parent     » topic index » view message » categorize

4. Re: Anyone know anything about trigonometry?

Unless you really want it to be fairly accurate, I wouldn't worry about
calculating trajectories.
In fact, more often than not, I find it looks more realistic, taking the
approach I mention, rather than actually trying to calculate the trajectory.
Like others said, you need to consider gravity, resistance (friction and
wind force), inertia, mass, aerodynamics (that's being very petty :P).
If you were making a golf game, I would say that tracjectory calculations
would be crutial.

If you look at any fireworks demos, they should give you an idea of what to
do. Most use arcs for the path of the flare and the sparks, they will even
take into account GRAVITY and trajectory SPEED.
I haven't looked at the workings of the EU fireworks demos, but I suspect it
would be similar.
I know that there are numerous fireworks examples for BASIC, that
demonstrate how to do the arced paths.
The main concept is to change the position incrementally(the increment can
be whatever realistic value you choose), multiplying the increment by SPEED,
and subtracting (or dividing) GRAVITY every time. Once you've made your
calculation for that increment, you decrement SPEED. Eventually, speed will
be 0 and the trajectory will end.

For fireworks, I would have static values for increment and gravity, and
speed is random. For your purposes, speed wouldn't be random.

This should give you an idea of how to proceed

EG.
INCREMENT=10
GRAVITY=0.6
SPEED=50

while SPEED>0 do
    pos_x+=INCREMENT*SPEED*GRAVITY
    pos_y+=INCREMENT*SPEED*GRAVITY
    SPEED-=1
end while

Chris

new topic     » goto parent     » topic index » view message » categorize

5. Re: Anyone know anything about trigonometry?

hello David,

When the user tells the program the angle to shoot at, you should convert 
the angle and speed to component vector form.  It is easier to work with (x, 
y) than (angle, speed) internally.  First, get the x and y components for 
the velocity vector of the projectile as follows:

xspeed = cos(angle) * speed
yspeed = sin(angle) * speed

When the projectile is in motion, move the ball by an amount proportional to 
the x and y speed.  Then decrease the y speed by a number that tells the 
acceleration due to gravity.

It gets a bit more complicated than this.  A knowledge of maths (and 
physics) would help for this.  I made a small program that simulates 
projuctile motion, and you can download it at

http://www.geocities.com/daryl_vdb/euphoria

Sorry if the code is hard to understand, or the program is buggy.  Email me 
again if you want to know more.

regards,
Daryl van den Brink

>Hello all,
>
>Does anyone know anything about trigonometry? I am interested in making a
>"dueling artillery" game but cannot fathom the math needed to plot arcs. I
>know that it has something to do with arc, tan, and cos (?) but what?!
>
>So this is a call to all you mathematicians on the list ;)
>
>Thanks a lot,
>David S.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu