Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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

Grid is 100x100 so the centre is 50,50

User clicks @ X,Y

range = System.Math.Sqrt(

System.Math.Pow(System.Mat

+

System.Math.Pow(System.Mat

);

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

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 =

Hence:

R = 2X +

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).

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)

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

{

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));

}