# Coordinate conversions (similar to polar coordinates)

#### MystMage

I use a coordinate system that is very similar to polar coordinates, but has a unified reference.

Basically, a point's coordinates is an angle and a distance.

At the moment I'm just doing 2d. The coordinates help me build things easier programmatically. I know this has programming but it is the math that is tripping me up.

In any case, I am putting together some computer functions that converts a point's coordinates from one origin point to another origin point.

However, in the tests, the results seem to be backwards. The test points that should be between the two origins have their new coordinates on the far side, while the test points on the far side has it's new coordinates place it in between.

For example, I have the second origin point at 90 degrees and 20 units distant from the primary origin point. From that second origin, the test point A is at 90 degrees and 10 units out. Therefore, it's total distance from the primary origin should be 30 units, but I get 10 instead. Meanwhile, the test point B that is at 270 degrees from the second origin and 10 units distant, placing it directly between the two origin points, comes up as a distance of 30.

The numbers all come up correctly, just for a reciprocal point.

The method I'm using is solving SAS triangles. I know two sides (originA to originB and point to originB), and the angle between those sides. Thus I use law of cosines then law of sines.

Any ideas why this might be the case?

For reference,
F is primary origin, L is secondary origin, and P is the point whose coordinates are being translated.

x is distance, y is angle (for the coordinates)
a is an intermediate angle of the triangle.
These stack together for easy recognition of values.
I.E.
Lx is the distance from F to L.
Px is the distance from P to L,
Fx is from F to P.
Ly is the angle of L from reference with F as the vertex,
Py is the angle of P from reference with L as vertex.
Fy is the angle of P from reference with F as the vertex. (one of the values I want to find)
Pa is the angle from Px to Fx, with P as the vertex.
Fa is the angle from Fx to Lx with F as the vertex.
La is the angle from Lx to Px with L as the vertex.

getInverseAngle just returns the reciprocal angle (I.E. 90 degrees returns as 270 degrees)
correctAngle just ensures no negative angle nor angle of more than one full rotation, thus all angles are between 0 and 360 degrees.

I have the angles measured as 1 = 360 degrees, and thus get converted to radians for the sin, asin, and cos functions as needed.

if (Ly < Py && Py < getInverseAngle(Ly)){
La = correctAngle(getInverseAngle(Ly) - Py);
Fx = sqrt((Px*Px) + (Lx*Lx) + (2 * Px*Lx*cos(La*(2 * PI))));

if (Px <= Lx){//if Px is not larger than Lx, then can go straight to Fa, Px is used as known angle/side
Fa = (sin(La*(2 * PI)) / Fx)*Px;
Fa = asin(Fa) / (2 * PI);
Fy = Fa + Ly;
}//close if Px is smaller
else {
Pa = (sin(La*(2 * PI)) / Fx)*Px;
Pa = asin(Pa) / (2 * PI);
Fa = .5 - La - Pa;
Fy = Fa + Ly;
}//close if Lx is smaller
}
else {
La = correctAngle(.5-(Ly- Py));
Fx = sqrt((Px*Px) + (Lx*Lx) + (2 * Px*Lx*cos(La*(2 * PI))));

if (Px <= Lx){//if Px is not larger than Lx, then can find Fa directly, Px is used as known angle/side
Fa = (sin(LoA*(2 * PI)) / Fx)*Px;
Fa = asin(Fa) / (2 * PI);
Fy = correctAngle(Ly - Fa);
}//close if Px is smaller
else {//if Px is larger than Lx, then need to find the smaller angle first, then find Fa,
Pa = (sin(La*(2 * PI)) / Fx)*Lx;
Pa = asin(Pa) / (2 * PI);
Fa = .5 - La - Pa;
Fy = correctAngle(Ly - Fa);
}//close if Lx is smaller

#### Country Boy

Math Team
What do you mean by "a unified reference"?

#### MystMage

In polar coordinates, the horizontal angle starts in one direction and the vertical angle starts from straight up, thus the two angles are completely divorced from each other as though you would ponder only one at a time. Given it's use in astronomy, it sort of makes sense, in a weird way that totally requires explaining, several times.

My coordinates were designed to be conceptually easy to use as though from a ship or vehicle, thus the horizontal angle goes from straight ahead to the right, and then vertical coordinates go up or down from there. The two are unified conceptually and thus easy to envision, understand, and use (not to mention much easier to program algorithms).

#### studiot

Use this for programming.

#### Attachments

• 99.2 KB Views: 15
• 23.6 KB Views: 8

#### MystMage

Problem solved, I just had the wrong sign in using the rule of cosines. No idea how I missed that.

Thank you studiot, I'll check those out, though I'm curious why that method needs a test for each quadrant, mine only needs whether the point is cw or ccw from the angle to second origin (though I also test if the points are in line because that removes all the complex math in those cases). Interesting.

#### studiot

Problem solved, I just had the wrong sign in using the rule of cosines. No idea how I missed that.

Thank you studiot, I'll check those out, though I'm curious why that method needs a test for each quadrant, mine only needs whether the point is cw or ccw from the angle to second origin (though I also test if the points are in line because that removes all the complex math in those cases). Interesting.
If you look carefully it is the standard method that requires the tests.
There are four quadrants, therefore 3 tests are required to decide which quadrant the triangle to be solved lies in. That is what the flow diagram is about.

The replacement method offers replacement formulae which can be used directly with no tests at all.

#### MystMage

Now I just need to figure how to apply it to 3d.

As for my program, I will still need to do those two tests, because I use the results to not simply solve the triangle, but also to make the new coordinates, which must either add or subtract the triangle's angle depending on the direction the triangle faces. Or maybe not... We'll see.

#### studiot

but also to make the new coordinates,
Gosh, try reading the article it does exactly that, for exactly the reason you mention, and is all explained there.

To go to 3D you will need to use additional equations corresponding to the additional angle required in spherical coordinates.
Or you can use it directly with one angle and two distances in cylindrical coordinates.

#### MystMage

Perhaps I'm missing something, but I'm not seeing how it automatically converts coordinate origins. Honestly, I don't even know what the examples are doing. The only bit I got from the article, which I figured was the important bit, was that by assuming a circle had 5/4s total angle and flipping sin for cos at certain points allowed you to avoid testing for quadrant, something I'm not doing anyway. The only testing I'm doing is the direction of the triangle, because in one direction, I'll add a triangle angle to a coordinate angle, and in the other direction I'll subtract, either way this occurs after solving the triangle.

As I have no idea what numbers the article was trying to obtain in the first place (what are DE, DN, and R anyway?). It mentions calculating coordinates, but calculating from what is left unstated. The formulas used in the examples are nothing like solving a triangle.

I see potential there for other uses, but in circumventing solving the triangle? I'm not seeing that.

To be more clear about what I'm doing, just in case I gave the wrong impression in the first place (happens a lot with me), is I have a reference point, we'll call it a space station, and a second reference point, a space ship, and the space ship finds a rock. The space ship knows where the rock is relative to the ship, and the station knows where the ships is relative to the station, but the ship wants to relay the rock's position to the station so the station knows where the rock is relative to them. How I'm doing this is, I'm taking the three points, the station, ship, and rock, solving a triangle with those three points (knowing two sides, from ship to station and ship to rock, plus the angle between those sides), then adjusting for the triangle's orientation.

#### studiot

Perhaps I'm missing something, but I'm not seeing how it automatically converts coordinate origins. Honestly, I don't even know what the examples are doing. The only bit I got from the article, which I figured was the important bit, was that by assuming a circle had 5/4s total angle and flipping sin for cos at certain points allowed you to avoid testing for quadrant, something I'm not doing anyway. The only testing I'm doing is the direction of the triangle, because in one direction, I'll add a triangle angle to a coordinate angle, and in the other direction I'll subtract, either way this occurs after solving the triangle.

As I have no idea what numbers the article was trying to obtain in the first place (what are DE, DN, and R anyway?). It mentions calculating coordinates, but calculating from what is left unstated. The formulas used in the examples are nothing like solving a triangle.

I see potential there for other uses, but in circumventing solving the triangle? I'm not seeing that.

To be more clear about what I'm doing, just in case I gave the wrong impression in the first place (happens a lot with me), is I have a reference point, we'll call it a space station, and a second reference point, a space ship, and the space ship finds a rock. The space ship knows where the rock is relative to the ship, and the station knows where the ships is relative to the station, but the ship wants to relay the rock's position to the station so the station knows where the rock is relative to them. How I'm doing this is, I'm taking the three points, the station, ship, and rock, solving a triangle with those three points (knowing two sides, from ship to station and ship to rock, plus the angle between those sides), then adjusting for the triangle's orientation.

As to your other points, you state that you don't follow the article yet you feel competent to pontificate about what it can and can't do.

Can you read a map ?

If I told you Sometown was 10 miles North and 3 miles West of Anothertown, would you be able to place Sometown on a map?

This is exactly what the method is doing.

By the Way a coordinate system can only have one Origin. That is why it is called The Origin.

Last edited: