Thread: Algorithm needed!

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    32

    Algorithm needed!

    Hi,
    I am currently working on a program that governs nautical navigation by warships and encomposes many simple geometric algorithms that assist ships in finding courses, distances and speeds to different points in space. (in my case, ocean).

    My question is as follows:
    I need to create algorithm which will take the distance to the point travelled to and the ship's deceleration and current speed and will return the distance from the destination in which the ship should start decelerating in order to reach it's destination exactly.

    I know it's a simple problem but I'm after about 8hrs of programming and have reached a blank in thought... I will appreciate pseudo code but please NO C++ CODE

    Thank you,
    Warlax

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    given a decelaration a [m/sec2] and the current speed v [m/sec] you can calculate the time to stop as t = v/a.
    from the time you can calculate the distance as d = v/2 * t.
    Kurt

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Rearrange t = v-u/a
    then
    0.5*t*a

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    You just got there before me.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    32

    Nope

    This doesn't help
    Let me refine my question a little further:

    I have a ship that has a max. speed of M (mtrs/sec) and a current speed of V (mtrs/sec). It is able to accelerate or decelerate at a rate of A (mtrs/sec per sec). I also have my distance to destination given...

    I need two things:
    a) an algorithm which will set the proper speed towards the destination, taking into account the possibility of the destination being to close to the ship's initial point of departure to allow it to gain full speed before it needs to start stoping.

    b) an algorithm which tells me when to start decelerating the ship towards a stop.

    * I am not interested in just stopping the vessel from it's speed to zero, as it is not realistic.
    ** I do not wish to overshoot my destination, creating a situation in which my ship will continue to plan new courses to try to re-hit the target over and over again.

    Thank you.

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    I don't think that stopping a ship from current speed to zero is necessarily unrealistic - besides, 0 is a nice number with which to do this kind of simple modelling using vectors... zero allows you to factor out "final velocity" from equations of motion.

    that would make your 'knowns' as follows:
    Code:
    u:  "initial velocity" (m/s) = ships max. speed
    v:  "final velocity" (m/s) = 0 - ship isn't moving anywhere (maybe the anchor is down?)
    a:  "acceleration" ( (m/s)/s ) = a negative value - how fast your ship is decelerating
    as someone already said, you can find the time it takes to stop with
    Code:
    a = (v-u) / t
    rearranged to
    Code:
    t = (v-u) / a
    then displacement can be calculated with
    Code:
    s = (1/2)*(v+u)*t
    legend:
    Code:
    s:  "displacement" (m)          t:  "time" (s)
    u:  "initial velocity" (m/s)    v:  "final velocity" (m/s)
    a:  "acceleration" ( (m/s)/s )

    I don't know what you mean by "Proper speed to its destination" if a ship is decelerating, then its velocity is constantly changing.
    Last edited by Bench82; 05-10-2006 at 06:59 PM.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    This is simple maths, once you know the relevant equations.
    http://www.physchem.co.za/Graphs/Equations.htm

    Take an appropriate one, rearrange it to find out what you want, from what you know and apply.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent Help Needed In Writing Algorithm!!
    By Vikramnb in forum C++ Programming
    Replies: 1
    Last Post: 01-09-2009, 12:46 PM
  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. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Algorithm needed
    By sean in forum C++ Programming
    Replies: 17
    Last Post: 08-22-2002, 07:48 PM