Imagine you are on a two dimensional cartesian plane and want to determine your position on it. You know 3 points on that plane and your distance to each of them. While it is always possible to calculate your position from that, doing that in your head is pretty hard. So you decide to write a program for that.
Given 3 points and your distance to them, output the cordinates of your position.
- Input and output may be in any convenient format, including using complex instead of real numbers. Please clarify in your answer which format you use.
- You will always get exactly 3 distinct points with their distance to you.
- The coordinates and distances will be floats with arbitrary precision. Your output has to be correct to 3 decimal places. Rounding is up to you. Please clarify in your answer.
- You may assume that the three points are not collinear, so there will be always an unique solution.
- You are not allowed to bruteforce the solution.
- You may not use any builtins that trivialize this particular problem. Builtins for vector norms, etc. are allowed though.
Hint to get started:
Think about a circle around each of those 3 points with their distance to you as radius.
- Function or full program allowed.
- Default rules for input/output.
- Standard loopholes apply.
- This is code-golf, so lowest byte-count wins. Tiebreaker is earlier submission.
Input format for one point here is
y being the coordinates and
d being the distance to this point. The 3 of those points are arranged in a list. Output will be
x and then
y in a list.
[[[1, 2], 1.414], [[1, 1], 2.236], [[2, 2], 1.0]] -> [2, 3] [[[24.234, -13.902], 31.46], [[12.3242, 234.12], 229.953], [[23.983, 0.321], 25.572]] -> [-1.234, 4.567] [[[973.23, -123.221], 1398.016], [[-12.123, -98.001], 990.537], [[-176.92, 0], 912.087]] -> [12.345, 892.234]
You can generate additional test cases with this Pyth program. Location goes on the first line of the input and the 3 points are on the following 3 lines.