Advertisement Jump to content
Sign in to follow this  
CelticSir

Help calculating the correct direction between two points

This topic is 1883 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by thefollower

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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 ?

Edited by thefollower

Share this post


Link to post
Share on other sites

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.

Edited by Pink Horror

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!