3D Vectors - Calculating velocity components to reach a target

176 Views Asked by At

I found this golf game, and it led me to taking on a little physics challenge. I am trying to hit my ball into the hole perfectly every single time. I can add velocity on the x,y,z axis.

The things I know are:

  • The gravity (30 units/s)
  • My initial vertical velocity (20 units/s)
  • The ball and hole positions

Now there is some type of drag, represented by the value of 0.5. This is computed so the surface area isn't taken into account. The weight of the ball is 1

I'm not sure how to account for drag but this puts me in the right direction:

    gravity    = 30
    velocity_y = 20   //Vertical
        
    time = (velocity_y / gravity) * 2
        
    velocity_x = (target.x - start.x) / time
    velocity_z = (target.z - start.z) / time
        

As I said this gets me close but I am not sure how to account for the drag. Also when the ball is lower/higher it doesn't take that into account.

I attempted to include:

time_rise = velocity_y / gravity

height    = start.y + velocity_y * time_rise - 0.5 * gravity * (time_rise ^ 2)

time_fall = √(2 * height / gravity)

time = time_rise + time_fall

When I used this time value instead, I get some strange results for the fall time, here is a simple example of the issue I am having:

Target: (53.0, -0.9, -4.0)
Start: (35.0, 0.1, -4.0)

RiseTime = 0.6666667
Height = 6.736667
FallTime = 20.10473

This fall time is way off, the point is only 1 unit lower than me. I am getting most of my maths for this from

http://www.convertalot.com/ballistic_trajectory_calculator.html