CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 44

Threaded View

  1. #6
    Join Date
    May 2009
    Posts
    2,413

    Re: Help with math algorithm

    Quote Originally Posted by D_Drmmr View Post
    the minimum will be at y = 8*x/63.
    It depends on what you're optimizing. I've looked at minimizing w which is the distance between the runner and the approaching water when he starts running. For a given y and x this formula gives the w for which runner and water arrive at y simultaneously,

    w = sqrt(x^2 + y^2) * 8 - y

    The square root is the distance the runner runs to get to the riverbank a distance y downstream. Runner and water arrive at y at the same time but the water has travelled 8 times longer to get there hence the 8. Finally y is subtracted to give w, the distance between water and runner when he started to run.

    In my view it makes most sense for the runner to aim for the y which gives the smallest possible w. W is the point of no return really. If the water gets closer you won't make it regardless of how you run. By running towards the y that puts w the closest to you will give you the best chance of making it regardless of how far away the water actually is when you start.

    So what y gives the smallest w? Well according to my calculations it's y = x/sqrt(63). This differs from the y = 8*x/63 that D_Drmmr got so lets set x=1 and calculate w for the two y values.

    w (1/sqrt(63)) = 7.937253933
    w (8/63) = 7.937257808

    Amazingly the results differ only after the fifth decimal. But mine is smaller so it's more optimal .
    Last edited by nuzzle; October 19th, 2012 at 03:39 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured