Thread: dogs chasing cats up trees

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by nonoob View Post
    Strategy might be as simple as:
    Calculate distance from initial cat position to all the trees. Find closest one. Is it 2x distance from dog to cat?

    But while the cat is heading off to any particular tree, should the dog aim for the same tree? Or aim for the cat at its anticipated position of intercept dynamically? Or travel in some curve? Now the problem starts to get all differential equationy. What if cat heads for tree #1, then takes a quick turn and goes for tree #2? Dog has to alter his path. I think this is too hard to solve.
    I tend to agree... this isn't the kind of problem you would hand someone in an introductory C class. It is solvable, of course, but probably not within the confines of small programs expected by most instructors and certainly not within a week...

    Reading these threads I do find myself wondering what the heck these so called "professors" are trying to accompish...

  2. #17
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    That's the trouble of being out of school so long and getting jaded by the real world... you tend to see everything complicated (real world). But I doubt the problem was meant to be as difficult.

    Instead of calculating distance to all trees, why not just find the first tree (in any order) whose distance from cat is 2x distance cat-to-dog. Stop there, the problem is solved.

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You mean less than 2X distance of cat to dog, of course.

    Sure, cat is sitting pretty in the treetops.

  4. #19
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Ok. Thinking more about it... the problem is actually complicated.
    Dog = "D", tree = "T", cat = "C"
    The above method only works if dog, tree, cat are co-linear.

    D ***** T ********** C
    ---> <---

    Dog and cat head for the tree (towards each other). Cat can do twice the speed, so it starts at 2x the distance from the tree. Great. That's the equilibrium point.

    Now what if dog, cat, tree are at some other angle with respect to each other.

    When dog covers a certain distance towards cat, cat has also moved. When does dog catch up?

  5. #20
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The dog doesn't care about any tree's, because it spotted the cat -- it is only interested in getting to the cat, and will take the shortest path to get there. It will not "head for the tree to cut off the cat", or any such strategy. For all intents and purposes, it's a straight line. Dogs in the heat of a chase, don't do any math. They will cut a corner in their pursuit, if possible, but there are no obstacles or mitigating factors in the environment, mentioned, here. Just dog, cat, trees, and distances

    The cat is always going to run, in as straight a line as possible, to the nearest tree. Anything more is beyond the scope of this problem, imo.

  6. #21
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    That's the problem. The dog is heading towards the cat at all times (straight line as far as he is concerned), but cat may be heading in some oblique angle away from the dog. So dog is continually changing direction... going in a curve. The length of that curve has to be compared with the length of the cat path.

    If the dog was smarter he'd be doing calculus, derivatives and such in his head to predict where the cat will be by the time he gets to the same spot, and then plot a straight line there. That way his path is optimized.

    The dog is certainly not going to just continue straight to the cat's initial position (where the cat started). However, that seems to be the assumption made to remain within the scope of this exercise.
    Last edited by nonoob; 03-24-2011 at 08:51 AM.

  7. #22
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The cat won't head in an oblique angle to the dog. They would be extinct if they made that a habit, since the dog would angle straight toward the cat then, vastly shortening the distance between them.

    Yes, a cat will "spring" into any immediately available tree, in any direction as the dog approaches, but this problem tells us it's a chase, so the cat will be running directly away from the dog, and the dog will be directly following. If some obstacles were mentioned, or the cat and dog had just spied each other, then EVERYTHING would change. For this problem, the cat is out in a barren environment, with just the trees to use for safety, and no angling by dog or cat, need to be considered.

  8. #23
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Yes the cat would head off in an oblique direction if a tree in that vector is closest. A cat might even head TOWARDS the dog if a tree is in line and close. Although instinctively it may not want to do that.

    I think we need to plot a locus of points where cat & dog intersect. Probably some form of ellipsoid or conchoid. Then we see if there are any tree coordinates within that area.

  9. #24
    Registered User
    Join Date
    Mar 2011
    Posts
    10

    Arrow help

    Code:
     
    int main()
          {
           
          FILE *fp;
           
       if((fp = fopen("CatAndDog.dat","r")) == NULL)
       printf("File could not be opened\n")
    
      fscanf(fp, "%d %d", &a, &b);
      fscanf(fp, "%d %d", &c, &d);
      fscanf(fp, "%d", &e);
      }
    the a,b,c,d,e are the coordinators of the cat, dog and trees. i also have done a loop to read all the coodrinators of the trees. What i don't know how to do is how to check if the cat can escape or not and also how to pick the closest tree to the cat if there are two or more.

  10. #25
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    There were suggestions to use an array of coordinates. Where is that? I don't see a struct or an array there. The struct would simply have 2 members, an X and a Y.
    If you understand what you're doing, you're not learning anything.

  11. #26
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by nonoob View Post
    Yes the cat would head off in an oblique direction if a tree in that vector is closest. A cat might even head TOWARDS the dog if a tree is in line and close. Although instinctively it may not want to do that.

    I think we need to plot a locus of points where cat & dog intersect. Probably some form of ellipsoid or conchoid. Then we see if there are any tree coordinates within that area.
    So you're taking a relatively simple programming problem, smack into the next realm, eh?

    Shades of Clinton, it all boils down to what your definition of "chasing" is.

    Sadam, despite being given advice on multiple forums, you've done nothing substantive, so far. Re-read itsme86's post, and get onto doing that - at least try. Just opening a file and reading in the values, does NOT show much.

  12. #27
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    You suggested an array of a Point structs, Adak suggested a matrix representing the map. What's the problem? It's a kindergarten exercise. Not a spacecraft prototype.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  13. #28
    Registered User
    Join Date
    Mar 2011
    Posts
    10
    can anyone solve it?

  14. #29
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Mario F. View Post
    You suggested an array of a Point structs, Adak suggested a matrix representing the map. What's the problem? It's a kindergarten exercise. Not a spacecraft prototype.
    Really? Kindergarten... So you should be able to manage a solution very nicely then...

    So lets see it... where is your solution?

  15. #30
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by sadam View Post
    can anyone solve it?
    Of course we can! If you'll remember, I already posted a solution. Get to work with the suggestions given and quit expecting to be spoon-fed. Show us your attempt at the point struct. Show us your array. If you're still stuck after that then you can ask questions.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Microwave Regular Hot dogs?
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 38
    Last Post: 01-11-2005, 01:53 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. A Miracle has occurred in the realm of Hot Dogs
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-08-2004, 03:18 PM
  4. Cats vs. Dogs
    By LouDu in forum A Brief History of Cprogramming.com
    Replies: 44
    Last Post: 03-14-2003, 09:22 PM

Tags for this Thread