2017-09-05 3 views
2

나는 높고 낮게 보였지만 아무것도하고 있지는 않습니다. 총알 궤도에 대한 x와 y 좌표를 계산 한 다음 Chart.js에 그 좌표를 플롯해야합니다.총알 탄도에 대한 x 및 y 좌표 계산 - Chart.js

(0, 5)에서 발사 된 총알은 (250, 5)에 대상을 때립니다. 문제는 그 사이의 궤도 (x는 야드, y는 피트)에서 정확하게 그래프로 그립니다.

목표를 치지 않고 총알과 총알 궤적의 궤적을 성공적으로 계산할 수 있습니다. 그러나 발사 각도를 계산할 수 없어 총알이 x 거리에서 목표에 도달합니다. https://en.wikipedia.org/wiki/Trajectory_of_a_projectile

내 응용 프로그램은 다음과 같습니다 :

여기

My apps graph

내가 지금까지 가지고 무엇을 : 내 계산 왔 곳

은 주로

calcTrajectory() { 

// get target distance - passed in 

// get launch angle to hit target at that distance 
let x = this.distance; 
let y = this.height; 
let g = 10.733; // gravity in yds 
let v = this.velocity/3; // velocity in yds 
let angle = Math.atan(
    Math.pow(v, 2) + Math.sqrt(
    Math.pow(v, 4) - g * ((g * x * x) + (2 * y * v * v) 
    )) 
/
    (g * x) 
); 

// graph x y coords based on target distance, launch angle, and bullet drop 
for (let i = 0; i < 10; i++) { 
    let time = (i * 100)/v; 
    let bulletY: number = Math.sin(angle - (Math.PI/2)) * v; 
    let dropVal = ((10.733/2) * Math.pow(time, 2)) * 3; 

    console.log('Bullet Y:', bulletY); 

    this.myChart.data.datasets.forEach((dataset) => { 
    dataset.data.push({ 
     x: (i * 100), 
     y: parseInt(this.height) + bulletY - dropVal 
    }); 
    }); 

    // update chart 
    this.myChart.update(); 
} 

무엇 내가 빠졌어?

편집 : 명확히 질문 내가 각도/타이프 라이터 물건을 모두 제거해야 사진

답변

1

을 추가,하지만 당신은 아래의 코드를 실행하고 붙여 그래프 프로그램에 출력을하고 검증 할 수 있어야한다. 제가하고있는 것은 거리 입력을 이동하는 데 필요한 각도를 계산 한 다음 초기 속도의 x와 y 벡터를 계산하는 것입니다. 그런 다음 시간 단계별로 곱하면 포인트를 얻을 수 있습니다. 더 세분화 된 포인트를 원하면 단계 변수를 늘리십시오.

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)