Help calculating the correct direction between two points

Started by
6 comments, last by LorenzoGatti 10 years, 4 months ago

Hey

I have an animation of two objects rotating in different circles at different speeds. I then have two possible directions in which to travel to and from each object (red & green line represent this).

What I am stuck with is how I work out which path is the correct path to travel on. To explain what is going on in the animation see this image:


hyceSA3.png

In the above image the red path is the correct path, going from inner to outer orbit the travel direction on the red path is clockwise, given that the green path is bowing into a smaller orbit, it is not the correct path to take.

In the below image the objects are in different locations! In this situation the green path is correct going from inner to outer orbit the travel direction on the green path is anti-clockwise, given that the red path is bowing into a smaller orbit, it is not the correct path to take.

VVADj1e.png

My animation is here showing the paths calculated at the same time to show two possible choices at any given time: http://jsfiddle.net/Kz32b/

How can I work out which line is best between red and green. When the set of rules are the path must not go below the smallest orbit.

Advertisement

Find the midpoint of the segment that connects the origin and destination points. Project a ray from the center of the orbits through this midpoint. Find the intersection of your possible paths with the ray. The one which is further along the ray, i.e. further away from the center of the orbits, will be correct.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Ah! You are correct here is the changes i added:

http://jsfiddle.net/FSYC5/

Slight follow up question for it if you see that link ^ notice there is a small margin of time when the orbit goes below the smaller orbit, is there any way I can correct that at all ?


Slight follow up question for it if you see that link ^ notice there is a small margin of time when the orbit goes below the smaller orbit, is there any way I can correct that at all ?

Your calculated path isn't always going to look good as just a choice between two circular segments with a fixed radius.

I doubt the path between orbits should be a circular segment, but I have no idea. I'd expect a good-looking path and a somewhat realistic path to not have any sharp angles transitioning into or out of an orbit.

Edit: I may not have put enough thought into this, and I've never used this HTML5 canvas thing before, but it seems like you might want to draw a quadratic curve.

I don't understand what you mean ?

I don't understand what you mean ?

I'm not sure how to respond. I hope someone else can write something in a way you understand. Maybe I missed something in your code? Are your connecting paths not how I described them?

If we're talking about orbits, the appropriate term for moving from one orbit to another is an "orbital transfer". If you google that term, and check out the idea behind the "Hohmann transfer orbit", then it should achieve what you want without relying on hardcoded circles. Also, check out Kerbal Space Program, which features quite accurate orbital mechanics as part of its gameplay.

[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler
What you are trying to do is both wrong (your red and green circles have a completely arbitrary radius) and impossible: there are many point locations for which both paths cross the smaller orbit (in the demo, whenever the "currentAngle" difference between the squares falls in a certain interval around 180° that depends on arc radius). If you want a good looking path, use splines. You have a simple interpolation between two points, presumably with tangent constraints that you should make explicit. If you want an orbital transfer, use a physical simulation without computing an arbitrary "path". Hohmann transfers are certainly suitable, spirals without braking are also good, but in fact any sufficiently general control system can execute an orbit transfer (or similar tasks like reaching a point).

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement