# -*- coding: utf-8 -*-
from scipy.optimize import fsolve
from math import sqrt
""" Coordinates from EDSM """
xMerope, yMerope, zMerope = ( -78.59375, -149.625, -340.53125 )
xSynuefe, ySynuefe, zSynuefe = ( 74.53125, -149.375, -339.96875 )
xCol285, yCol285, zCol285 = ( -78.65625, -150.59375, -49.25 )
xWredguia, yWredguia, zWredguia = ( -78, 175.8125, -341.125 )
""" Distances from Probe """
dMerope = 1
dSynuefe = 0.85
dCol285 = 1.177
dWredguia = 1.149
"""
Our equations are based on the generalized Pythagorean theorem:
x^2 + y^2 + z^2 = d^2
Where d is the direct distance between the two systems and x, y and z
are the distances along the axis.
While we don't know the distance between say Merope and the mystery
system, we can write the difference using Merope's standard coordinates.
^
y |
| Mystery system (x0, y0)
| x
| ^
| |
| |
| | y0 - yMerope
| |
| |
| Merope (xMerope, yMerope) |
| x<-- ------------------------+
| x0 - xMerope
|
+---------------------------------->
x
With this we can write the Pythagorean theorem as:
(x0 - xMerope)^2 + (y0 - yMerope)^2 + (z0 - zMerope)^2 = d^2
"""
""" Define the equations """
def equations( guess ):
d0, x0, y0, z0 = guess
"""
Pythagoran theorem is often written as:
x^2 + y^2 + z^2 = d^2
When solving equations, writing them as equaling 0 is more convenient.
For this reason the equations below are written in the form:
x^2 + y^2 + z^2 - d^2 ( = 0 )
"""
return (
( x0 - xMerope )**2 + ( y0 - yMerope )**2 + ( z0 - zMerope )**2 - ( dMerope * d0 )**2,
( x0 - xSynuefe )**2 + ( y0 - ySynuefe )**2 + ( z0 - zSynuefe )**2 - ( dSynuefe * d0 )**2,
( x0 - xCol285 )**2 + ( y0 - yCol285 )**2 + ( z0 - zCol285 )**2 - ( dCol285 * d0 )**2,
( x0 - xWredguia )**2 + ( y0 - yWredguia )**2 + ( z0 - zWredguia )**2 - ( dWredguia * d0 )**2,
)
"""
Scipy solves the equation system numerically.
The equations are written in the form of:
x-something + y-something + z-something - d-something = 0
The solver can now take a guess of x, y, z and d and calculate the left side
of the equation. It'll get some result. The closer the result is to 0 the
better the guess was.
The solver will repeat the calculation several times moving the guessed values
to a direction that seems to be reducing the error. Once the solver finds
values that result in calculations that are "close enough" to 0 it'll stop.
So the only thing that remains for us is to give it some initial guess.
The probed distances grew smaller when we moved to +x direction (Synuefe) and
larger when we moved to +y (Wredguia) and +z (Col285). So we'll use a guess
that's somewhere to +x, -y, -z of Merope.
d x y z """
initial_guess = ( 500, 500, -500, -500 )
d0, x0, y0, z0 = fsolve( equations, initial_guess )
""" Display the results. """
print( "d0 =", d0 )
print( "x0 =", x0 )
print( "y0 =", y0 )
print( "z0 =", z0 )
"""
Finally we can use some of the other probe results to check that these values
were correct
We can do this with the normal pythagoran theorem.
d^2 = ( x^2 + y^2 + z^2 )
or solved for d:
d = sqrt( x^2 + y^2 + z^2 )
"""
""" Synuefe TI-Z B33-1 coordinates """
xSynuefeTIZ, ySynuefeTIZ, zSynuefeTIZ = ( 243.75, -150.28125, -339.96875 )
""" The probe-distance of the system """
probeSynuefeTIZ = 0.697
""" Calculate the distance from the solved origin system """
dSynuefeTIZ = sqrt( ( x0 - xSynuefeTIZ )**2 + ( y0 - ySynuefeTIZ )**2 + ( z0 - zSynuefeTIZ )**2 )
""" Calculate Synuefe's distance as a ratio of Merope's distance (d0) """
ratioSynuefeTIZ = dSynuefeTIZ / d0
print()
print( "Synuefe TI-Z BB33-1" )
print( " - Probe:", probeSynuefeTIZ )
print( " - Calculated:", ratioSynuefeTIZ )
"""
The solver uses 4 equations to solve the 4 variables. There are usually
multiple solutions to the equation systems, e.g. x^2 = 4, x could be 2 or -2.
Verifying the given solution with a fifth data point should be enough to tell
us whether the solution we got is the "correct" one or not.
If the values for the fifth system do not match, we can get the other solutions
from the solver by changing the initial guess.
"""