Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (744)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (825)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Calculate required impulse to reach the spot.  (Read 857 times)
0 Members and 1 Guest are viewing this topic.
Offline xor_

Innocent Bystander





« Posted 2017-06-15 14:12:42 »

Good day friends.Around three days can`t resolve a problem with impulse calculation(Porbably because my physics knowledge is very poor).

In Figure 1(Fig.1) and Figure 2(Fig.2) are conditions which requires to calculate Velocity of a body for succesefull landing.

What we know:
     bodyVelocity,
     bodyPosition,
     targetPosition.

Question is : How to calculate  velocity to reach the spot?



I have been searching before posting this topic but found nothing(maybe i didn't realize that problem is similar?!).
Thanks for your time!
Offline KaiHH

JGO Kernel


Medals: 486



« Reply #1 - Posted 2017-06-15 18:06:57 »

If you think of your angry circular player as a "bullet" and given that it always jumps with the same velocity magnitude/speed you can search for "ballistic trajectory angle to target" and get:
https://blog.forrestthewoods.com/solving-ballistic-trajectories-b0165523348c#891a
This gets you the angle at which to jump (relative to the horizontal x axis) given the delta x and delta y between the position to jump from and the target landing position.
In Java this works like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
float g = 9.81f; // <- acceleration of gravity
float dx = targetPosition.x - playerPosition.x;
float dy = targetPosition.y - playerPosition.y;
float v = 20.0f; // <- magnitude of jump velocity
float v2 = v * v;
float sqrt = (float) Math.sqrt(v2 * v2 - g * (g * dx * dx + 2 * dy * v2));
// If it is possible to reach the target, you'll always get two possible shot/jump angles.
// One for an indirect "high arc" shot and one which is most direct "low arc".
float hiangle = (float) Math.atan2(v2 + sqrt, g * x); // <- "high arc" angle
float loangle = (float) Math.atan2(v2 - sqrt, g * x); // <- "low arc" angle
// If it is not possible to jump to the target, you'll get NaN
// If you are not so much into angles, but prefer vectors, then your jump direction is:
Vector jumpHi = normalize(vector(g * x, v2 + sqrt));
Vector jumpLo = normalize(vector(g * x, v2 - sqrt));
Offline abcdef
« Reply #2 - Posted 2017-06-15 18:28:21 »

You need to split your equations in to two and work out the velocity where they are both equal.

The horizontal equation, assuming no air resistance

distanceHorizontal = initial velocity(horizontal) * time

You can reach arrange and work out the time t to travel horizontally to your chosen spot.

The vertical equation assuming gravity

distanceVertical = initial velocity(vertical) * time - (1/2)*gravityAcceleration * time * time

Again you can rearrange to get the time on one side (just a simple quadratic).

Now you have two equations in t, now find the velocity values which give you the same t for a given distance in the horizontal and vertical

I haven't given you the answer (as I am on my phone) but hopefully you have enough to go on to work this out yourself
Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (147 views)
2017-09-30 02:57:34

theagentd (213 views)
2017-09-26 18:23:31

cybrmynd (295 views)
2017-08-02 12:28:51

cybrmynd (284 views)
2017-08-02 12:19:43

cybrmynd (294 views)
2017-08-02 12:18:09

Sralse (287 views)
2017-07-25 17:13:48

Archive (966 views)
2017-04-27 17:45:51

buddyBro (1092 views)
2017-04-05 03:38:00

CopyableCougar4 (1663 views)
2017-03-24 15:39:42

theagentd (1425 views)
2017-03-24 15:32:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!