Calculate angle of reach for projectile given velocity and distance









up vote
-1
down vote

favorite












I've been trying to implement projectile motion in Javascript and I'm stuck at figuring out the angle (from which to derive the x and y velocity)



var v = 1;
var d = 10;
var g = -1;
var angle = 0.5 * Math.asin((g*d)/(v*v));


I would've expected someting like this to work, since it's coming from here Here.

The values I seem to get are either NaN or a very small number.



To give a bit more context; The projectile has to go from point A to point B (the distance is d in my code) where A and B are at the same height. Later on I would like to randomize the distance and angle a bit, but I assume that's not going to be an issue once this angle problem is solved.



EDIT:

As for a better example:



var v = 100;
var d = 100;
var g = 1; // I've made this positive now
var angle = 0.5 * Math.asin((g*d)/(v*v));


This says that angle is now 0.005










share|improve this question























  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Samuel Liew
    Nov 9 at 21:04














up vote
-1
down vote

favorite












I've been trying to implement projectile motion in Javascript and I'm stuck at figuring out the angle (from which to derive the x and y velocity)



var v = 1;
var d = 10;
var g = -1;
var angle = 0.5 * Math.asin((g*d)/(v*v));


I would've expected someting like this to work, since it's coming from here Here.

The values I seem to get are either NaN or a very small number.



To give a bit more context; The projectile has to go from point A to point B (the distance is d in my code) where A and B are at the same height. Later on I would like to randomize the distance and angle a bit, but I assume that's not going to be an issue once this angle problem is solved.



EDIT:

As for a better example:



var v = 100;
var d = 100;
var g = 1; // I've made this positive now
var angle = 0.5 * Math.asin((g*d)/(v*v));


This says that angle is now 0.005










share|improve this question























  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Samuel Liew
    Nov 9 at 21:04












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I've been trying to implement projectile motion in Javascript and I'm stuck at figuring out the angle (from which to derive the x and y velocity)



var v = 1;
var d = 10;
var g = -1;
var angle = 0.5 * Math.asin((g*d)/(v*v));


I would've expected someting like this to work, since it's coming from here Here.

The values I seem to get are either NaN or a very small number.



To give a bit more context; The projectile has to go from point A to point B (the distance is d in my code) where A and B are at the same height. Later on I would like to randomize the distance and angle a bit, but I assume that's not going to be an issue once this angle problem is solved.



EDIT:

As for a better example:



var v = 100;
var d = 100;
var g = 1; // I've made this positive now
var angle = 0.5 * Math.asin((g*d)/(v*v));


This says that angle is now 0.005










share|improve this question















I've been trying to implement projectile motion in Javascript and I'm stuck at figuring out the angle (from which to derive the x and y velocity)



var v = 1;
var d = 10;
var g = -1;
var angle = 0.5 * Math.asin((g*d)/(v*v));


I would've expected someting like this to work, since it's coming from here Here.

The values I seem to get are either NaN or a very small number.



To give a bit more context; The projectile has to go from point A to point B (the distance is d in my code) where A and B are at the same height. Later on I would like to randomize the distance and angle a bit, but I assume that's not going to be an issue once this angle problem is solved.



EDIT:

As for a better example:



var v = 100;
var d = 100;
var g = 1; // I've made this positive now
var angle = 0.5 * Math.asin((g*d)/(v*v));


This says that angle is now 0.005







javascript calculus






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 18:51

























asked Nov 9 at 18:35









Dries

465524




465524











  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Samuel Liew
    Nov 9 at 21:04
















  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Samuel Liew
    Nov 9 at 21:04















Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew
Nov 9 at 21:04




Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew
Nov 9 at 21:04












2 Answers
2






active

oldest

votes

















up vote
0
down vote













Im not really good at this physics problrm but i'll try



https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin



  • the arg for Math.asin() should be between -1 and 1. Otherwise it returns NaN

  • from your example you run Math.asin(-10/1) maybe the velocity has max distance that it could cover. No matter the angle, 1m/s wont reach 500m distance for example

  • in your link there is a formula to count the max distance from given velocity and angle. Use that to confirm your variables are relevant.

  • angles are represented in values between -1 to 1 in cos, sin, tan. It makes sense that NaN (or values outside the range) means no angle can cover the distance

Hope it helps a bit






share|improve this answer




















  • Thanks, I'll try to see if I can incorporate some of those bulletpoints in my code to get a better understanding of what's happening
    – Dries
    Nov 9 at 19:02

















up vote
0
down vote













Note from the same wikipedia page you linked d_max = v*v/g. Given your inputs this evaluates to 1. Therefore a distance of 10 is impossible.



Another way to notice this is the range of sin is (-1,1). Therefore asin of any number outside of this range is undefined. (g*d)/(v*v) is 10, so Math.asin returns NaN






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231538%2fcalculate-angle-of-reach-for-projectile-given-velocity-and-distance%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Im not really good at this physics problrm but i'll try



    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin



    • the arg for Math.asin() should be between -1 and 1. Otherwise it returns NaN

    • from your example you run Math.asin(-10/1) maybe the velocity has max distance that it could cover. No matter the angle, 1m/s wont reach 500m distance for example

    • in your link there is a formula to count the max distance from given velocity and angle. Use that to confirm your variables are relevant.

    • angles are represented in values between -1 to 1 in cos, sin, tan. It makes sense that NaN (or values outside the range) means no angle can cover the distance

    Hope it helps a bit






    share|improve this answer




















    • Thanks, I'll try to see if I can incorporate some of those bulletpoints in my code to get a better understanding of what's happening
      – Dries
      Nov 9 at 19:02














    up vote
    0
    down vote













    Im not really good at this physics problrm but i'll try



    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin



    • the arg for Math.asin() should be between -1 and 1. Otherwise it returns NaN

    • from your example you run Math.asin(-10/1) maybe the velocity has max distance that it could cover. No matter the angle, 1m/s wont reach 500m distance for example

    • in your link there is a formula to count the max distance from given velocity and angle. Use that to confirm your variables are relevant.

    • angles are represented in values between -1 to 1 in cos, sin, tan. It makes sense that NaN (or values outside the range) means no angle can cover the distance

    Hope it helps a bit






    share|improve this answer




















    • Thanks, I'll try to see if I can incorporate some of those bulletpoints in my code to get a better understanding of what's happening
      – Dries
      Nov 9 at 19:02












    up vote
    0
    down vote










    up vote
    0
    down vote









    Im not really good at this physics problrm but i'll try



    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin



    • the arg for Math.asin() should be between -1 and 1. Otherwise it returns NaN

    • from your example you run Math.asin(-10/1) maybe the velocity has max distance that it could cover. No matter the angle, 1m/s wont reach 500m distance for example

    • in your link there is a formula to count the max distance from given velocity and angle. Use that to confirm your variables are relevant.

    • angles are represented in values between -1 to 1 in cos, sin, tan. It makes sense that NaN (or values outside the range) means no angle can cover the distance

    Hope it helps a bit






    share|improve this answer












    Im not really good at this physics problrm but i'll try



    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin



    • the arg for Math.asin() should be between -1 and 1. Otherwise it returns NaN

    • from your example you run Math.asin(-10/1) maybe the velocity has max distance that it could cover. No matter the angle, 1m/s wont reach 500m distance for example

    • in your link there is a formula to count the max distance from given velocity and angle. Use that to confirm your variables are relevant.

    • angles are represented in values between -1 to 1 in cos, sin, tan. It makes sense that NaN (or values outside the range) means no angle can cover the distance

    Hope it helps a bit







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 9 at 18:54









    Nikko Khresna

    32817




    32817











    • Thanks, I'll try to see if I can incorporate some of those bulletpoints in my code to get a better understanding of what's happening
      – Dries
      Nov 9 at 19:02
















    • Thanks, I'll try to see if I can incorporate some of those bulletpoints in my code to get a better understanding of what's happening
      – Dries
      Nov 9 at 19:02















    Thanks, I'll try to see if I can incorporate some of those bulletpoints in my code to get a better understanding of what's happening
    – Dries
    Nov 9 at 19:02




    Thanks, I'll try to see if I can incorporate some of those bulletpoints in my code to get a better understanding of what's happening
    – Dries
    Nov 9 at 19:02












    up vote
    0
    down vote













    Note from the same wikipedia page you linked d_max = v*v/g. Given your inputs this evaluates to 1. Therefore a distance of 10 is impossible.



    Another way to notice this is the range of sin is (-1,1). Therefore asin of any number outside of this range is undefined. (g*d)/(v*v) is 10, so Math.asin returns NaN






    share|improve this answer
























      up vote
      0
      down vote













      Note from the same wikipedia page you linked d_max = v*v/g. Given your inputs this evaluates to 1. Therefore a distance of 10 is impossible.



      Another way to notice this is the range of sin is (-1,1). Therefore asin of any number outside of this range is undefined. (g*d)/(v*v) is 10, so Math.asin returns NaN






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Note from the same wikipedia page you linked d_max = v*v/g. Given your inputs this evaluates to 1. Therefore a distance of 10 is impossible.



        Another way to notice this is the range of sin is (-1,1). Therefore asin of any number outside of this range is undefined. (g*d)/(v*v) is 10, so Math.asin returns NaN






        share|improve this answer












        Note from the same wikipedia page you linked d_max = v*v/g. Given your inputs this evaluates to 1. Therefore a distance of 10 is impossible.



        Another way to notice this is the range of sin is (-1,1). Therefore asin of any number outside of this range is undefined. (g*d)/(v*v) is 10, so Math.asin returns NaN







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 19:09









        wilkben

        415




        415



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231538%2fcalculate-angle-of-reach-for-projectile-given-velocity-and-distance%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Darth Vader #20

            Ondo