Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So I got a 3d system and some coordinates:

  • Start coordinates (x, y, z) of a rocket (on the ground)
  • Target coordinates (x, y, z) of the rockets target (also on the ground)

I got some initialize values like:

  • maximum_velocityZ = 0.5
  • maximum_resVelocityXY = 0.3
  • gravity factor = 9.81

How can I calculate the flight velocitys (velocityX, velocityY and velocityZ) for every update frame?

let maximum_velocityZ = 0.5
let maximum_resVelocityXY = 0.3
let gravity_factor = 9.81

let rocketPosition = {
  x: 3,
  y: 0,
  z: 2
}
let rocketTarget = {
  x: 7,
  y: 5,
  z: 8
}
let rocketVelocity = {
  x: 0,
  y: 0,
  z: 0
}
let update = function() {
  rocketPosition.x += rocketVelocity.x
  rocketPosition.y += rocketVelocity.y
  rocketPosition.z += rocketVelocity.z

  let distanceX = (rocketTarget.x - rocketPosition.x)
  let distanceY = (rocketTarget.y - rocketPosition.y)
  let distanceZ = (rocketTarget.z - rocketPosition.z)

  let factorXY = Math.abs(distanceX / distanceY)
  rocketVelocity.x = maximum_resVelocityXY / Math.sqrt((1 / factorXY ** 2) + 1) * (distanceX > 0 ? 1 : -1)
  rocketVelocity.y = maximum_resVelocityXY / Math.sqrt((factorXY ** 2) + 1) * (distanceY > 0 ? 1 : -1)
  rocketVelocity.z = maximum_velocityZ * distanceZ;
  rocketVelocity.z /= gravity_factor;

  console.log("x:", Math.round(rocketPosition.x), "y:", Math.round(rocketPosition.y), "z:", Math.round(rocketPosition.z))
}

setInterval(update, 300)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
135 views
Welcome To Ask or Share your Answers For Others

1 Answer

The trajectory will be a parabola. The basic equations of which are explained quite well here: https://courses.lumenlearning.com/boundless-physics/chapter/projectile-motion/

The 3D problem (x, y, z) can be easily be transformed to a 2D (single plane) problem (horizontal, vertical), for the equations then back to 3D for the problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...