score:2

Accepted answer

i had to remove all of the angular/typescript stuff, but you should be able to run the below code and paste the output into a graphing program and verify it. what i'm doing is calculating the angle required to travel the distance input, then calculating the x and y vectors of the initial velocity. then you can just multiply those by a timestep to get points that you can plot. if you want more granular points, just increase the step variable.

const calctrajectory = (distance, height, velocity)=> {

  // get target distance - passed in

  // get launch angle to hit target at that distance
  let x = distance;
  let y = height;
  let g = 10.733; // gravity in yds
  let v = velocity / 3; // velocity in yds
  let angle = math.asin((x*g)/(v*v));
  let step = 100;
  let xvelocity = v * math.cos(angle);
  let yvelocity = v * math.sin(angle)
  // graph x y coords based on target distance, launch angle, and bullet drop

  let data = {x:[], y:[]}
  for (let i = 0; i < 100; i++) {
    let time = (i / step);
    data.x.push(time*xvelocity)
    data.y.push(time* yvelocity)
    yvelocity -= (g/step)
  }
console.log(data);
}

calctrajectory(250, 0, 2024.43)


Related Query

More Query from same tag