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
javascript calculus
add a comment |
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
javascript calculus
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 21:04
add a comment |
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
javascript calculus
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
javascript calculus
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
add a comment |
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
add a comment |
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
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
add a comment |
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 9 at 19:09
wilkben
415
415
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 21:04