Results 1 to 3 of 3

Math Help - Calculating an Angle for Artillery

  1. #1
    Newbie
    Joined
    Aug 2011
    Posts
    2

    Calculating an Angle for Artillery

    Hey guys this is my first post and I would like to start of by saying Hello.

    So Hello

    Anyways, I'm currently programming a 2D game and am having a few difficulties on working out an equation, or finding an equation that is. I'll give you some details of what it is.

    Basically, I'm building an AI that fires its artillery gun at a target in the distance. But I need to find out how mathematically wise it would do this. There are 3 key elements to it. The first being the distance between the AI and its target, the second being the gravity that is implemented in the game and the angle in which it needs to find to hit the target. If I know the equations ill be able to implement it within the code.

    Does anybody on here know how you would work out the angle in order for the AI to hit it's target?

    Thanks for any help

    Calculating an Angle for Artillery-ai-iron-tide-equations.png
    Follow Math Help Forum on Facebook and Google+

  2. #2
    -1
    e^(i*pi)'s Avatar
    Joined
    Feb 2009
    From
    West Midlands, England
    Posts
    3,053
    Thanks
    1

    Re: Calculating an Angle for Artillery

    Going down the route of parametric equations would be the way I'd go about it.

    x(t) = t\cos(\theta) - D (where D is drag, if your game has no air resistance this is 0)

    y(t) =t\sin(\theta) - mg (mg being the object's weight)


    Your horizontal displacement is x(t) and the vertical displacement is y(t). I suspect the AI would know/guess x(t), the gravity is up to you as a programmer and depends on the mass of the shell.

    To find the angle you can isolate t\sin(\theta) \text{  and  } t\cos(\theta)

    t\sin(\theta) = y(t) + mg \text{.....  [eq1]}

    t\cos(\theta) = x(t) + D \text{......  [eq2]}

    You can then divide eq1 by eq2

    \dfrac{eq1}{eq2} \Leftrightarrow \dfrac{t\sin(\theta)}{t\cos(\theta)} = \dfrac{y(t)+mg}{x(t)+D} \Longleftrightarrow \tan(\theta) = \dfrac{y(t)+mg}{x(t)+D}


    \theta = \arctan \left( \dfrac{y(t)+mg}{x(t)+D} \right)


    I'm not sure how correct that is going to be though :\
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Aug 2011
    Posts
    2

    Re: Calculating an Angle for Artillery

    Thanks Man,

    I think this is exactly what I needed

    Cheers
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Calculating an angle in 3D coordinates
    Posted in the Geometry Forum
    Replies: 8
    Last Post: September 6th 2011, 12:15 PM
  2. Calculating an angle of a none right angle triangle
    Posted in the Trigonometry Forum
    Replies: 14
    Last Post: August 19th 2011, 01:42 PM
  3. Points on a circle, calculating angle
    Posted in the Geometry Forum
    Replies: 6
    Last Post: May 7th 2010, 12:51 PM
  4. calculating angle
    Posted in the Calculus Forum
    Replies: 6
    Last Post: August 15th 2007, 05:33 AM
  5. Calculating Angle from Coordinates.
    Posted in the Trigonometry Forum
    Replies: 3
    Last Post: February 14th 2007, 02:01 PM

Search Tags


/mathhelpforum @mathhelpforum