# Calculating the intersection of spheres [Trilateration Calculation]

Hi Everyone,

I have a mathematical calculation I needed solved, to do with the intersection of spheres.

I have a node transmitting a message and it is received by 3 or more gateways (base stations). The location of the node is unknown and I want to calculate it.

The gateway location and the timestamp the message arrives is known.

Here I am showing an example of 3 gateways, but it could be a lot more, 4 gateways will give 3D accuracy.

The flow below is a inject node with the JSON in it.

Are you asking how to implement a solution for that equation in a function node? If so then I think you need to find a JavaScript (or possibly python) solution elsewhere.

Yes, I know it is more related to JavaScript(Python), but the last time I did mathematics like this is long, long time back.

Need to find a Maths master.

It helps to know the name of the tool your trying to use. This is a trilateration problem. Old school single engine pilots do the opposite of this with old AM radio towers to figure out where we are at. Heck only need 1 tower because as we move towards it we can plot 2 points over time.

Ill take a stab at it next weekend if no one else touches it..... I do like my Maths.

Question: does the node move around or is it stationary ? if it moves you only need one tower to pull off a ruff estimate of its location +/- the opposite side of the radius. 2 towers fixes that for a moving node.

Factors that mess up the equation. If the tower(s) is/are on hill(s) at high elevations and the node is low to the ground then your estimation of location err goes up. or you need 3 towers for sure!

The node moves slowly (1-15km/h), but mostly stationery.

Towers - not very specific of location, varies some on hills, buildings, but mostly 10m AGL

Nodes are generally not more than 3m AGL

0: object
gateway_ids: object
gateway_id: "tech5-alverstone-02-dbn"
eui: "313330374E005900"
time: "2021-08-22T06:35:06.519602Z"
timestamp: 506974466
snr: 6
location: object
latitude: -29.770195
longitude: 30.716669
altitude: 950
source: "SOURCE_REGISTRY"
channel_index: 6
1: object
gateway_ids: object
time: "2021-08-22T06:35:06.523276Z"
timestamp: 388469847
snr: -9.25
location: object
latitude: -29.796528
longitude: 30.790431
altitude: 647
source: "SOURCE_REGISTRY"
channel_index: 6
2: object
gateway_ids: object
gateway_id: "on-the-hill-01"
eui: "00800000A000104F"
time: "2021-08-22T06:35:06.521836Z"
timestamp: 2525021188
snr: 10.5
location: object
latitude: -29.806432
longitude: 30.771859
altitude: 615
source: "SOURCE_REGISTRY"
channel_index: 6

So I played around with some math in javascript ( getting roots too dang slow ) and forget a differential.

Then did some hunting on NPM figuring someone with way more skill than me probly did a 100X better job of it.

Ohhhhh Looks like I might be making a new node-red-contrib

First we need to sort out the lat / lon / height issues ---> geodetic-to-ecef - npm
Now we can use ---> lm-trilateration3d - npm

On last issue I'm sorting out is distance now. speed of (EM waves in a vacuum)

As we are dealing with a RF link, we do have RSSI as well to help getting the estimation correct. BUT, the RF could be attenuated adversely between the node and tower as it have to travel thru a brick wall, but could be used as a reference to guess if our calculation is relatively accurate. There are also some reference to RSSI on this page.

I am using currently a call to a API, but some how the error gets worse when they have more than 3 points and they don't exclude 2 point calculations.

This is a stationery node over the last 24 hours.

299 792 458 m / s

Last time I looked, the earth had an atmosphere:-)

5 Likes

We are slowly sucking it up, so we are going to end up with a vacuum.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.