How can I accurately determine the parameters of an ellipse that represents the trajectory of an object in space using initial condition values (r0, v0, deltat, and mu)?

In my current game project, I'm developing a primary user interface that displays the solar system from a top-down perspective (with Earth's north pole as 'up'). One of the challenges I faced was creating a semi-realistic path for an object traveling between planets. To tackle this, I've been using Lambert's problem to calculate the initial velocity vector for the object, and the results have been promising for the game.

After spending a few weeks on this issue, I even turned to ChatGPT-4 for assistance with the complex math involved. While I made progress at times, I struggled to arrive at the correct solution consistently.

One recurring issue I encountered was obtaining negative values for the a parameter (semi-major-axis of the ellipse), which shouldn't be the case.

I suspected one reason for this discrepancy could be the disparity in coordinate systems used in my game (left-handed) versus traditional mathematical calculations (right-handed). In order to address this, I inverted the y-values during vector calculations and ensured proper inversion for screen display. I also experimented with reversing the entire coordinate system, but the outcomes were similar.

Below is the TypeScript implementation of the logic responsible for generating the current elliptical path:

Following multiple iterations of custom Lambert problem solvers and aided by AI, I opted to utilize the lambert-orbit package, which provided the functionality I required along with additional useful features.

Furthermore, here is an excerpt from my vector class implementation:

For instance, when passing the given parameters to the generatePath method, the resulting data includes a velocity vector and various calculated values like the semi-major axis and the second foci point.

A visual representation of the computed ellipse shows discrepancies in intersecting the designated locations correctly, prompting reflections on possible causes and adjustments needed.

The journey to achieving accurate orbital paths continues as ongoing tests and observations shed light on potential solutions to refine the game's trajectory simulation.

Answer №1

I have finally discovered the solution that I have been searching for!

While exploring, I stumbled upon a detailed graphic depicting the visualization of an ellipse.

https://i.sstatic.net/LhF7O.png

Using this visualization, I was able to craft a code snippet that helped me determine the two potential locations for the second focus point. This involved creating circles representing 2a - r and 2a - r0 around their respective points and identifying the intersection points as my focal points.

Below is the code snippet:

private static circleCircleIntersection(
    c1: Vector,
    r1: number,
    c2: Vector,
    r2: number
  ): [Vector, Vector] | null {
    const d = c2.subtract(c1).magnitude();
    if (d > r1 + r2 || d < Math.abs(r1 - r2)) {
      return null;
    }

    const a = (r1 * r1 - r2 * r2 + d * d) / (2 * d);
    const h = Math.sqrt(r1 * r1 - a * a);
    const p = c1.add(c2.subtract(c1).normalize().multiply(a));

    const x1 = p.x + (h * (c2.y - c1.y)) / d;
    const y1 = p.y - (h * (c2.x - c1.x)) / d;

    const x2 = p.x - (h * (c2.y - c1.y)) / d;
    const y2 = p.y + (h * (c2.x - c1.x)) / d;

    return [new Vector(x1, y1), new Vector(x2, y2)];
  }

By utilizing this code, I was able to identify the required ellipses accurately. Notably, it aligned perfectly with the initial velocity vector, further solidifying its relevance to my problem at hand.

https://i.sstatic.net/itnhZ.png

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

Ways to define a static variable within a function using Typescript

There is a common approach to declaring a Static Variable or Function within a Class, demonstrated here: class SomeClass(){ static foo = 1; static fooBar(){ return ++SomeClass.foo; } } However, is it possible to declare a Static Local Variable ...

Exploring the Power of DataList in Angular

I am working with a <datalist> and <select> in the following setup: Updated: Example 1: <input type="text" list="codes" [(ngModel)]="codeValue" (change)="saveCode(codeValue)"> <datalist id="codes"> <option *ngFor="let c of ...

I have integrated React Hook Form with Typescript, where the input data is not being accepted by the string datatype

Whenever I pass {...register(name)} as an argument to my input component using the hook form, it results in an error. However, when I pass it as {...register("fullname")}, no error occurs. Unfortunately, using something like ("fullname" ...

Ways to verify if an array contains elements from other arrays in Typescript

How can I verify if the winningConditions are present in chosenNumbers? The chosenNumbers array is of varying lengths and consists of a mix of numbers. For example, one of the winning conditions is [0, 3, 6], but there is also the number 2 included. How ...

Issue with decompressing the identical data using zlib (Z_BUF_ERROR)

Below is the Python code snippet I am working with: import zlib raw = bytes.fromhex("789C34C9410AC2301005D0BBFC752289A88BB94A53CAD8061B48D3329D2A1A7277DDB87BF02A14548E9C0DF63FD60DE49DC104AA98238BDE23EB908A467972065DFCF9FAFB4185C708EAD0053C58E38BDF769 ...

Guide on creating an interface for a JSON object with an array of custom functions

I am working on developing an interface for a JSON object that consists of n keys with unknown names, each containing an array of functions with specific signatures. // CLASSES class Server { // Private variables mapping : IMapping = {} // ...

The TypeScript compilation is not able to find index.ts at the moment

When I tried to run 'ng serve', I encountered the following error message: The TypeScript compilation is missing node_modules/angular2-indexeddb/index.ts. It is crucial to ensure that this file is included in your tsconfig under the 'file ...

Is it possible to specify the version of a dependency using Stackblitz?

Is it possible to specify the dependency version on StackBlitz? I recently updated the dependency on NPM, however StackBlitz seems to be stuck on installing the old version. ...

Navigating images within Typescript - NextJS operations

My website fetches data from the Spoonacular API to search for ingredients, receiving responses with titles and images. I have defined the types as: export interface IProps { id: number; name: string; image: string; } Currently, my list of i ...

Generating a new Observable from a callback function

I am currently working on customizing an example from ngx-chips to fit my specific needs. The challenge I am facing involves adjusting the onRemoving method example provided: public onRemoving(tag: TagModel): Observable<TagModel> { const con ...

Tips on extracting the value from an observable and storing it in a variable

I am facing a challenge in returning a value from an observable method to assign it to a public variable for later use. Specifically, I need to retrieve this value and store it in the 'viewcount' variable for utilization in another function. pub ...

Tips for Implementing Error Handling in Angular using Sweetalert2

On this code snippet, I have implemented a delete confirmation popup and now I am looking to incorporate error handling in case the data is not deleted successfully. confirmPopUp(){ Swal.fire({ title: 'Are You Sure?', text: 'Deleti ...

"How can we trigger a re-render of a React component once a promise is fulfilled? Is there a way to prevent rendering until the

Having attempted to make updates to a functional component that interfaces with an azure-devops-ui/Filter, I've encountered a situation where I am utilizing the azure-devops-extension-sdk to handle async responses. This component is intended to be use ...

Tips for scrolling ion-items vertically to the bottom and top using arrow icons in Ionic 4

I'm developing an Ionic 4 app with Angular and looking to incorporate Up and Down Arrow buttons for vertical scrolling from top to bottom and vice versa. ...

What is the correct way to employ async/await in combination with Array.filter within a React application?

I'm currently in the process of developing a basic currency converter using React and Typescript. Below is a snippet of my component code: const App = () => { const [countries, setCountries] = useState<Array<CountriesProps>>([]) co ...

The most effective approach to creating linked observable subscriptions

How can we refactor this code reactively using RxJS for better performance? let profileInformation; updateProfile() { let token; let profileId = 1; this.userService.getAccessToken() .pipe( tap((res) => { //as I need it multipl ...

Guide to initializing the state in pinia with Typescript

I am encountering an issue while trying to add typescript to a pinia store. Any suggestions on how to resolve this problem would be appreciated. The project currently utilizes pinia:^2.0.16 and Vue:3.2.37 The error message is as follows: Type '{}&a ...

Angular2 authguards encountering issues when trying to run asynchronous functions

I need a way to safeguard my routes by verifying if a user is logged in from the server, but I'm facing issues with asynchronous functions not executing properly. Below is the code snippet that's causing trouble: canActivate (route: ActivatedRo ...

Where can one find Typescript definitions when using typings?

Whenever I run typings install mongoose, it seems like the Typescript definitions are being fetched from https://github.com/louy/typed-mongoose This change feels a bit unexpected. Previously, they were sourced from DefinitelyTyped at https://github.com/ ...

Angular auto-suggest components in material design

Can someone assist me in resolving my issue? I am trying to incorporate an autocomplete feature with a filter into my form. .ts file : contactArray; selectedContact: IContact; myControl = new FormControl(); filteredContact: Observable<string[] ...