Rocket Calculations Made Easy

Recently, I acquired a cutting-edge 3D system along with a set of coordinates:

  • Initial coordinates (x, y, z) for a rocket (located on the ground)
  • Target coordinates (x, y, z) for the rocket's destination (also on the ground)

Here are some essential starting values:

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

I'm seeking guidance on how to determine the flight velocities

(velocityX, velocityY, and velocityZ)
for each update frame. Can you assist?

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)

This code reflects my current progress. I believe I'm heading in the right direction with X and Y velocities, but I'm facing challenges with Velocity Z. The trajectory in 3D space appears far from realistic. Any guidance or suggestions would be greatly appreciated. Wishing you a happy new year - may it soar high like the rocket!

Answer №1

I'm unsure about the coordinate system you're using.

  • plane
  • sphere
  • ellipsoid like WGS84

Based on your constants, it seems like your ground is planar, but your positions suggest otherwise. So, I'll assume a planar ground for now. Here are the two main issues:

  1. Newton/D'Alembert physics

    Your physics seem unusual without the dt multiplication, so it only works if your updates are at 1 Hz. Take a look at this for more insight:

    • Can't flip direction of ball without messing up gravity

    You don't really need a speed limiter since air friction will handle that, and you should work with accelerations or forces to account for mass changes. However, if you're dealing with atmospheric flight instead of Newtonian physics, heading control should be managed by turning the integrated velocity while main thruster should still apply acceleration.

    Collisions might not be necessary if your ground is flat and obstacle-free.

  2. Rocket guiding system

    I recommend using a 3-state (Markov model) rocket control.

    1. launch

      Ascend to a safe altitude to avoid obstacles, conserve fuel, and maximize speed.

    2. cruise

      Travel to the target area while maintaining altitude. Calculate the heading projected on the ground plane and correct the rocket's heading accordingly.

    3. hit

      Hit the target while descending. Similar to #2, but also involve changing altitude.

    In addition to these, you can implement strategies to avoid detection/destruction or obstacles, such as approaching from different angles to keep the launch position hidden.

Here's a simple C++ example to illustrate this approach:

EXAMPLE CODE HERE

You may need to adjust the constants to suit your game's requirements. This setup allows for customization of the rocket, perfect for game tech upgrades.

The physics involve Newtonian mechanics with the rocket's velocity turning due to wings. The guiding system operates as described above. The rocket ascends to alt0, turns towards the target at dang0 turn speed while maintaining altitude, then descends when closer than dis0. If closer than dis1, the rocket should explode.

Refer to the provided visuals for a better understanding.

Pay attention to the units:

Ensure all units used are compatible, ideally using the metric system. Your 9.81 constant aligns with this, but your position and target values raise some concerns if in meters. Shooting a rocket at a target just a few meters away seems odd. Also, integers might not be suitable for these values; consider using floats or doubles instead.

Answer №2

The path followed by the object will take the shape of a parabola. You can find detailed explanations of the fundamental equations for this trajectory here:

The complex 3D issue (involving x, y, z axes) can easily be simplified into a 2D (horizontal, vertical) problem, and then reconverted back to 3D for full analysis.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for organizing data and dynamically linking options to another select value?

One of my challenges involves working with two select elements. The first select allows for multiple options, while the second select is dependent on the choice made in the first one. <select class="form-control" id="select1"> <option value=""& ...

Ensuring User Input Integrity with JavaScript Prompt Validation

I need help with validating input from a Javascript prompt() in an external js file using HTML code. I know how to call the Javascript function and write the validation logic, but I'm unsure how to handle the prompt and user input in HTML. Do I need ...

Jquery Timer that can be toggled on and off with a single button

I'm really struggling to find a way to make this work smoothly without any bugs. The button in the code below is supposed to perform three actions: Initiate a countdown when clicked (working) Stop the countdown automatically and reset itself when it ...

Node/Express unexpectedly returning string instead of Array after parsing JSON file

Having difficulty parsing an empty (stringified) Array from a JSON file. Instead of returning an empty array, I am receiving a string. The initial set up of my JSON file is: "[]" I am storing the parsed data in a variable using File System let parsedOb ...

Angular2 Error: Cannot have two identifiers with the same name, 'PropertyKey' is duplicated

I am currently developing an application with angular2 using angular-cli. Unfortunately, angular-in-memory-web-api was not included by default. After some research, I manually added the line "angular-in-memory-web-api": "~0.1.5" to my ...

Assistance needed with dynamically resizing a background image

Is there a way to automatically adjust the size of a background image for an element? For instance, I want my links in HTML to have a background image with slanted borders and rounded corners. Usually, you would set the width of the anchor element to fit t ...

Experiencing problems with integrating Slim framework and AngularJS, such as encountering a 404 error

Although this may seem like a repeat question, I am encountering an issue with using AngularJS with Slim Framework web services. I have set up a webservice to retrieve a student record with a URL structure like: http://www.slim.local/api/getstudent/1 ...

Guide on how to append to a nested array within a React component?

I have been working on a prototype for a Slack clone. I encountered an issue where when I attempt to add a message to the array this.state.channels.message, it ends up being added as a new object in the array channels: EXPECTED RESULT class App extends R ...

Convert inline javascript into an external function and update the reference to `this`

I'm currently in the process of converting some inline JavaScript code triggered by a button's onclick event to a regular JavaScript function. In my previous implementation, I successfully used the "this" reference to remove a table column. Howe ...

Compel the browser to launch a fresh tab

I'm currently working on an app that involves uploading files. One issue I'm facing is that the file system pop up doesn't close after the upload, causing a quarter of the screen to be covered while the test keeps running in the background. ...

Passing data from the controller to the $resource object in Angular with the MEAN stack

After several attempts to troubleshoot my issue with passing parameters to the Express server, it turns out the problem lies on the Angular side. When I manually inserted the id in the flConstruct.js function, the query worked correctly. It appears that ...

Updating to the latest version of Next.js will result in a modification of the API path

I recently updated my app to the latest version of nextjs (13.1.6) and encountered a problem where all my requests are now failing. It seems that the URL I specified in the request creator, based on the ENV value, is being overwritten. .env file CONST NEXT ...

Creating a JSON object from an array of data using TypeScript

This might not be the most popular question, but I'm asking for educational purposes... Here is my current setup: data = {COLUMN1: "DATA1", COLUMN2: "DATA2", COLUMN3: "DATA3", ..., COLUMNn: "DATAn"}; keyColumns = ["COLUMN2", "COLUMN5", "COLUMN9"]; ...

AngularJS is throwing a $injector:modulerr error and I've exhausted all possible solutions

I recently started learning Angular and I've been following the tutorial on the official AngularJS website. Here's what I've tried so far: Installed angular-route and included the script below angular.min.js Utilized ngRoute in my mod ...

Using AngularJS, I can bind the ng-model directive to asynchronously update and retrieve data from

I am currently working with Angular to develop a preferences page. Essentially, I have a field in a mysql table on my server which I want to connect my textbox to using ng-model through an asynchronous xhr request for setting and fetching data. I attempt ...

JavaScript sticky navigation bar - error displayed in console

Hey there, I'm having an issue with my Sticky-menu. I've been trying to troubleshoot it but keep getting these console error messages: 1. Cannot read property 'offsetTop' of null at HTMLDocument. 2. Cannot read property 'class ...

Develop a JSON parsing function for VUE reusability

Currently, I am iterating through an array in Vue that contains objects with strings nested within. These objects have various properties such as idType, type, user, visibility, seller, product, company, and additionalData. notifications: [ 0: { idTy ...

javascript - data needed

Currently, I am diving into practicing javascript coding on CodeAcademy. While testing out my code in Codeacademy, I rely on console.log to display strings to the built-in browser within the platform. Everything runs smoothly there. The challenge arises wh ...

ERROR: The data has reached its end prematurely (data length = 0, requested index = 4). Could this be a corrupted zip file?

Currently, I am developing a WhatsApp bot and storing the chat data in an Excel file using exceljs for further processing. In order to handle responses efficiently, I am utilizing promises to resolve them. Below is the function I have created to read the c ...

Searching recursively for keys with empty values in an array using Javascript

I've written a function that recursively locates empty values in a nested array. The function initially produces the correct value, but it seems to reset it to the input value before returning the result. What could I be overlooking? Below is my co ...