Help with a relative motion/geometric problem

Study of algorithms, Automata, Programming (Basic, Delphi, C, C++, Assembler, Maple, Mathematica), Software/Hardware, Computational Mathematics, Complexity Theory.

From the same network: MyComputerForum ! Join today !

Help with a relative motion/geometric problem

Postby Optimus » Sat Feb 11, 2012 11:31 pm

Hi,

I'm not sure if this is the right forum to ask this question but here it goes: I'm trying to write a program that simulates an old but simple target tracking device used on ships in WWII but I've been having problems trying to understand how to use a few geometrical equations in a code.

The program should be able to come up with new ranges and bearings over time based on initial values.

Here are the equations in question, pgs 24-25 of this 1944 manual:

http://www.hnsa.org/doc/tdc/pg024.htm
http://www.hnsa.org/doc/tdc/pg025.htm

The terminology for the variables can be found here on pgs. 13/15:

http://www.hnsa.org/doc/tdc/pg013.htm
http://www.hnsa.org/doc/tdc/pg015.htm

I'm trying to figure out how to calculate delta R from equation VIII on pg25 and delta B equation X on pg25.

This is the "wrong" quick code I came up with in C# for testing (I'm sure I'm missing something):
Code: Select all
 
   public partial class Form1 : Form
    {

        float R, B, So, St, Co, Ct, A, Br, iR, iB;
        float dR, dB, dt;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            //********** RANGES

            iR = 5000;   // Initial range in yards
            R = iR;      // Range
           
            //********* COURSES AND SPEEDS
           
            Ct = 120;           // Target course in degrees
            St = 10 * 0.5626f;  // Target speed in knots (converted to yards/sec)
            Co = 270;           // Ownship course
            So = 5 * 0.5626f;   // Ownship speed in knots (converted to yards/sec)   


            //************** ANGLES

            Br =  25;           // Relative target bearing

            iB = Co + Br;       // Initial true target bearing in degrees
            B = iB;             // True target bearing
            A = 180 + B - Ct;   // Target angle

           
            //********** INSTANTANEOUS CHANGES

            dB = 0;   // Instantaneous change in true bearing
            dR = 0;   // Instantaneous change in range


            dt = 1f;  // time step?

            for (float t = 1f; t < 1000f; t += dt)
            {

                dR = dR + (St * (float)Math.Cos(DegToRad(A)) + So * (float)Math.Cos(DegToRad(Br)));

                R = iR - dR;

                dB = dB + ((St * (float)Math.Sin(DegToRad(A)) + So * (float)Math.Sin(DegToRad(Br)))*t) / R;

                B = iB + dB;
                if (B > 360)
                    B = B % 360;
                if (B < 0)
                    B = B + 360;
                if (B > 359.5 && B < 360.5)
                    B = 0;

                Br = B - Co;
                if (Br > 360)
                    Br = Br % 360;
                if (Br < 0)
                    Br = Br + 360;
                if (Br > 359.5 && Br < 360.5)
                    Br = 0;

                A = 180 + B - Ct;
                if (A > 360)
                    A = A % 360;
                if (A < 0)
                    A = A + 360;
                if (A > 359.5 && A < 360.5)
                    A = 0;

                listBox1.Items.Add( "t = " + t.ToString("000.00") + "       Range (R)  = " + R.ToString("0000") + "    True Bearing (B) = " + B.ToString("000.00")
                                   + "    Relative Bearing (Br)  = " + Br.ToString("000.00") + "   Angle A = " + A.ToString("000.00") + "   dB = " + dB.ToString("0.0000")
                                   + "    dR = " + dR.ToString("0.0000"));
            }

        }

        double DegToRad(float dd)  { return (double)(0.0174532925f * dd);  }
    }


But once I run some of these test problems:

http://www.hnsa.org/doc/tdc/pg220.htm

...the new range and bearing results aren't even close to the values shown.

What I'm not understanding is how to integrate the equations over time and how to keep track of time in seconds or minutes(not in real time I mean). If any of you guys have ideas on how to correctly code these equations (in C# or any other language) I'd really appreciate!

I'm sorry if this seems like a very basic question, but I'm just not seeing how to solve it.

Thanks!
Optimus
Newcomer
Newcomer
 
Posts: 2
Joined: Sat Feb 11, 2012 10:41 pm

Re: Help with a relative motion/geometric problem

Postby CRGreathouse » Sun Feb 12, 2012 8:47 am

One possibility: you put angles in degrees, but C# expects them to be in radians.
Pari/GP: this is the program I probably mentioned in my post. Windows users can get it at http://pari.math.u-bordeaux.fr/~bill/mingw/PARI-2-6.exe
User avatar
CRGreathouse
Global Moderator
Global Moderator
 
Posts: 10646
Joined: Sat Nov 25, 2006 9:52 am
Location: UTC -5

Re: Help with a relative motion/geometric problem

Postby Optimus » Sun Feb 12, 2012 3:11 pm

CRGreathouse wrote:One possibility: you put angles in degrees, but C# expects them to be in radians.


Hi GRGreathouse, I'm already using radians for the sin and cos calculations, I believe the only place that it would matter. I think the problem must be something with the program's logic. Anyway, thanks for the reply.
Optimus
Newcomer
Newcomer
 
Posts: 2
Joined: Sat Feb 11, 2012 10:41 pm


Return to Computer Science

Who is online

Users browsing this forum: No registered users and 1 guest