ATMResearcher 107 Report post Posted July 29, 2012 Hi all, I’m doing some university work based around aircraft in the air traffic system and I’m looking to use a lot of geometrical math typically found in game development. Right now, I'm trying to find out if an aircraft trajectory path intersects a circle in 2D. My path is defined by 7th degree x and y polynomials parameterised by time. The distance between the circle (Coordinates [EQN]W_x[/EQN] , [EQN]W_y[/EQN] and radius r)and the x,y trajectory path is then [EQN]d(t)=\sqrt{(x(t)-W_x )^2+(y(t)-W_y )^2 }-r[/EQN] By setting d(t) to zero and finding the roots of the equation I can find either the intersection time or the closest point of approach time between the path and the circle. However, to find the roots of the equation, which factors out to be a 14th degree polynomial, I have to use a numerical root finder. Are there analytical or simply better ways of finding the time of intersection between a trajectory path and a circle?? Also, what if I wanted to find the time of intersection between a trajectory and a rotated rectangle/ square? Can I do it with simple math, such as the root finding approach I used above, or do I need an algorithms with if statements etc? I've seen people here recommend the GJK algorithm, so I'll try that next. Any recommendatins, pointers or suggestions would be warmly received. 0 Share this post Link to post Share on other sites
jjd 2140 Report post Posted July 29, 2012 There might be a great reason for using a 7th order polynomial, but this is the thing that I would discard first. Replace it with a simple linear, piece-wise curve and then your intersection problem becomes a set of simple intersection tests between line-segments and a circle. Once you get that working you can refine the approximation of the curve. -Josh 1 Share this post Link to post Share on other sites
jefferytitan 2523 Report post Posted July 29, 2012 In general I don't believe there's an analytical solution to polynomials anywhere near that complicated. However it occurs to me that if you could provide limits on the values of t, a bounding box could be estimated very easily. To get a minimum limit on x, put the lower value of the t range in all positive terms, and the maximum value of the t range in all negative terms. Similarly you could create quick and easy values for max x, min y and max y. If this box doesn't intersect the circle, done. 1 Share this post Link to post Share on other sites
ATMResearcher 107 Report post Posted July 29, 2012 Thanks Josh, I did have a few thoughts along the lines you suggested. I guess I was hoping that there might be some special properties of polynomials that I could take advantage of to help simplify the problem. I'm essentially doing a trajectory optimization problem. For these sorts of problems the aircraft's positions, speeds and accelerations are represented by a series of linked linear segments (like you suggested) or by polynomials. Polynomials are more accurate at representing the changes in the position and speeds of things with time, but linear segments can come with a lot fewer headaches. I might have to just keep it simple this time. Cheers!! 0 Share this post Link to post Share on other sites
ATMResearcher 107 Report post Posted July 30, 2012 Thanks Jeffrey Titan, I was going to chop up my trajectory with lots of discrete points and then measure the distances from the points on the line to bounding boxes to determine if I needed to run a more detailed collision detection. However I do have knowledge of my max time and yes I could use that as an initial bounding box to eliminate spatial areas that will never interact with my trajectory. As a first cut, it should definitely save me some computational time. I've been reading these forums for a while now, I should have asked some questions sooner. 0 Share this post Link to post Share on other sites
jefferytitan 2523 Report post Posted July 30, 2012 (edited) I had a thought on tightening the bounds on the box that I suggested. My previous method looks at each term of the polynomial individually. Terms can be grouped, as long as the max/min for each group can be calculated analytically. For example, our original equation is: x = at^7 + bt^6 + ct^5 + dt^4 + et^3 + ft^2 + gt + h We then extract two groups out of it: x = at^7 + (bt^6 + ct^5 + dt^4) + (et^3 + ft^2 + gx) + h x = at^7 + t^4(bt^2 + ct + d) + t(et^2 + ft + g) + h We can analytically find the min and max values of the bcd and efg groups in the appropriate range of t values. As per my previous approach we fudge the at^7, t^4 and t terms using t(min) and t(max) as appropriate. And h is constant, so... yeah. My other thought is whether it would be possible to find two linear, quadratic or stepwise equations which are guaranteed to upper and lower bound your function, because they might give a much tighter bound than a box. Edit: I thought of a quadratic bounding approach which I'm kicking myself over for not noticing before. Use fgh as your quadratic, then use estimates based on all the other terms as a big constant. The estimate could be based on t^6 times the linear equation (at + b) and t^3 times the quadratic equation (ct^2 + dt + e). It may also work if you break it up the other way, e.g. quadratic in abc times a constant approximation for t^5. Edited July 30, 2012 by jefferytitan 1 Share this post Link to post Share on other sites
alvaro 21272 Report post Posted July 30, 2012 This idea of bounding groups of terms in an expression seems quite unorthodox. The minima and the maxima of the different pieces will not line up, so I can't see how this helps at all. The roots of a polynomial equation of degree 5 of larger cannot generally be expressed using a closed formula involving +,-,*,/ and taking roots (the precise statement of the theorem is more complicated, but look up Galois Theory if you are interested). This means that numeric approximations will have to do. The good news is that numeric approximations for this type of problem work very well in practice, and [url="http://en.wikipedia.org/wiki/Root-finding_algorithm#Finding_roots_of_polynomials"]a lot of people have worked on this problem before[/url]. 0 Share this post Link to post Share on other sites
jefferytitan 2523 Report post Posted July 30, 2012 @alvaro: Agreed that it is unorthodox, however the OPs particular request has some special features: a limitation on the range of t, more than one dimension, existence of roots rather than their values, and lastly the OP asked for an analytical solution. Also based upon my guesses on the purpose of this, a bounding approach could be easily extended for multiple circles, or for a z dimension as well. It doesn't give an exact answer, but if it works as I imagined it gives certainty from one angle (if it's not within the bounding area there is no possibility of intersection), and for an exact answer I'd hand over to numerical methods. 0 Share this post Link to post Share on other sites
alvaro 21272 Report post Posted July 30, 2012 [quote name='jefferytitan' timestamp='1343619242' post='4964380'] @alvaro: Agreed that it is unorthodox, however the OPs particular request has some special features: a limitation on the range of t, more than one dimension, existence of roots rather than their values, and lastly the OP asked for an analytical solution. [/quote] Oh, I missed the part where he is not interested in the values of the roots. The number of real roots of a polynomial in an interval can be computed using Sturm's theorem. Perhaps that's all the OP needed? EDIT: Hmmm... Silly link bug... This should work: http://en.wikipedia.org/wiki/Sturm%27s_theorem 1 Share this post Link to post Share on other sites
jefferytitan 2523 Report post Posted July 30, 2012 (edited) @alvaro: Interesting, I hadn't heard of Sturm's theorem. I'm not positive that he doesn't require the values of the roots, but that's how I read it. I think your link got truncated, link below: [url="http://en.wikipedia.org/wiki/Sturm"]http://en.wikipedia....m's_theorem[/url] Edit: Oh Sturm, you and your apostrophe. I'm not going to try any more. [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img] Edited July 30, 2012 by jefferytitan 0 Share this post Link to post Share on other sites
ATMResearcher 107 Report post Posted July 30, 2012 Thanks for the input guys. To clear things up, I am interested in the root values, but not always. The circles intersecting my trajectory can either be obstacles to be avoided or waypoints to be followed. For the obstacles I just need to know if the obstacle is avoided. For the waypoint case I need to know if the waypoint is crossed, and if not, I want to know the Closest Point of Approach between the trajectory and the waypoint. You see I make some corrections to the polynomials based on the CPA to move them closer to the waypoints. If there is no intersection between the waypoint and the polynomials, then the complex root of the equation below will give the time of CPA and hence the CPA. [EQN] \sqrt{(x(t)-W_x )^2+(y(t)-W_y )^2} - r = 0 [/EQN] I have already tried Sturm, and it works. It can also be used recursively to find the roots. It does require a lot of convolution and deconvolution though (polynomial multiplication and division) and gets quite time consuming quite quickly. Another thing I’ve tried is Chebfun, which generates a polynomial expansion of a function. It can be used to find the roots of a polynomial of any degree. It’s not analytical but it’s quite accurate. Again the computation time is a higher than I would like. For Sturm and Chebfun, I don’t think there is any great advantage in using them over numerical root finders for my particular problem. JeffreyTitan your quadratic suggestion looks interesting, I’ll plug some numbers in to see what I think. Otherwise I think I’ll do something similar to what Josh suggested and break my trajectory into lots of small linear segments. This should keep things fast and the loss of accuracy should be minimal. 0 Share this post Link to post Share on other sites
jefferytitan 2523 Report post Posted July 30, 2012 Thanks for updating us on your progress, always good to hear how it goes. Keep in mind that my suggestion was invented on the spot and is a bound only. But I'd be curious to know if/how much it worked. I'm too busy with my own projects to test it out. ;) 0 Share this post Link to post Share on other sites