Solved

Grid coordinates from range and bearing

Posted on 2011-03-09
9
500 Views
Last Modified: 2012-05-11
I have the following code which gives me range and heading when a user clicks on a grid.
Grid is 100x100 so the centre is 50,50


User clicks @ X,Y

range = System.Math.Sqrt(
                     System.Math.Pow(System.Math.Sqrt( System.Math.Pow((50-Y),2)),2)
                     +
                     System.Math.Pow(System.Math.Sqrt( System.Math.Pow((50-X),2)),2)
                 );

heading = System.Math.Atan2(50- X, 50 - Y) * 180 / System.Math.PI + 180;

This works OK but I want to reverse the process and get X and Y from range and heading?

Any ideas?

Thanks
0
Comment
Question by:oddszone
  • 5
  • 4
9 Comments
 
LVL 7

Expert Comment

by:Gene_Cyp
ID: 35083413
I will explain to you the process and you can do the steps.

As it stands you cannot reverse them, you have to do some groundwork first.

That is, given R, to find X you must first replace 'Y' with what it corresponds to for X

Simple example:

R = 2X + 3Y
=> Y = (R-2X) / 3

Hence:

R = 2X + (R-2X) / 3

Once you reach that state, since you know the value of R and you want to find X, you then go about making X the subject of the equation

Continuing from the example above:

R = 2X + (R-2X) / 3
=> 3R = 6X + (R-2X)
=> 2R = 4X
=> X = R / 2

You do the SAME process for Y.

Thus given 'R' (range) you can find X and Y


You repeat the same steps for H (heading).
0
 

Author Comment

by:oddszone
ID: 35083500
I kind of see what you are saying but my math is not good enough to do this :(
0
 

Author Comment

by:oddszone
ID: 35089080
Anyone :)
0
 
LVL 7

Expert Comment

by:Gene_Cyp
ID: 35092799
Odds,

I have some good news and some bad news. Once I took a closer look into your equations I realised they were trigonometry.


The good news is, I have changed your equations for you.
The bad news is: you have to either know the ANGLE or at least X or Y.


What I mean is, if you know R, to find X, you must also know Y.
If you know R, to find Y, you must know the value of X.
If you know R and you don't know the value of either X or Y, then you need to know one of the two triangle angles. (but given your problem I assume you don't)
Same applies to the Heading equation.

R = Range
H = Heading
X, Y = Length of sides
A = angle

Given that you stated your math is not good, I don't expect you to fully understand what I am talking about.

Have a look at this:

http://www.clarku.edu/~djoyce/trig/right.html
http://zonalandeducation.com/mmts/trigonometryRealms/introduction/rightTriangle/trigRightTriangle.html


By the way, it will have to wait till tomorrow, because I wrote it down on paper and left it at home (and don't have the time right now to redo it)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Accepted Solution

by:
oddszone earned 0 total points
ID: 35094495
       public int getX(double range, double bearing)
        {
            return (int)(range * System.Math.Sin(bearing * System.Math.PI / 180) + 50);
        }

        public int getY(double range, double bearing)
        {
            return 100-((int)(range * System.Math.Cos(bearing * System.Math.PI / 180) + 50));
        }
0
 
LVL 7

Expert Comment

by:Gene_Cyp
ID: 35094541
Lol, so I am curious, how did you end up to your two getX and getY methods?
0
 
LVL 7

Expert Comment

by:Gene_Cyp
ID: 35094557
Let me rephrase it, you are aware that what i said above about the angle is what you are doing there right?
0
 

Author Comment

by:oddszone
ID: 35094610
I wanted X and Y from range so now i have functions to do that.

I am not a programmer and I couldn't understand your replies
0
 

Author Closing Comment

by:oddszone
ID: 35135811
Fixed myself.
Thanks for all input though.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now