Finding a quantity between two points in three dimensional space

28 Views Asked by At

I'm obligated to let you know I've cross posted this on stack overflow earlier today but decided after some comments that I this question is probably less one of code and more one of the mathematics involved.

Basically, these two points are at different lats and lons and as I stated I want to find the amount of something between them. The tricky thing to me is that the model data I'm working with is gridded so I need to be able to account for the amount of something along a line at the lat and lons at which that line cuts through said grid. I guess that infers that the value I get will come from the length of the vector present in each cell.

My question can be visualized like this:3D Grid

Ultimately, I'd like to be able to create a program (within any programming language honestly) that could find the amount of "something" between two points in a 3D grid. If you would like specifics of my problem, the bottom altitude is the surface, the top grid is the "top of the atmosphere". The bottom point is a measurement device looking at the sun during a certain time of day (and therefore having a certain zenith and azimuth angle). I want to find the NO2 between that measurement device and the "top of the atmosphere" which in my grid is just the top altitude level (of which there are 25 levels).

Hopefully my question is beneficial to the forum as well as asked in such a way that it is helpful!

Best, Taylor

1

There are 1 best solutions below

0
On BEST ANSWER

This is more or less the 3D analog for a problem that I have provided an answer before. Here is how to do it for your case. I will use $x,y,z$ coordinates for simplicity:

  • you have a regular grid in each direction. We can assume that the planes perpendicular to $x$ are at $x_i$, $i$ from $0$ to $N_x$
  • the trajectory starts at $(x_m,y_m,z_m)$ and ends at $(x_M,y_M,z_M)$ and it's a straight line
  • the intersections with the planes are given by $$\frac{x-x_m}{x_M-x_m}=\frac{y-y_m}{y_M-y_m}=\frac{z-x_m}{z_M-x_m}=k$$
  • calculate the intersections with planes $x$ by plugging $x_i$ in the above equation and computing the corresponding $y$ and $z$ values. Only keep the $(x,y,z)$ triplets that fall on the grid. Store the corresponding $k$ as well. $k$ will be between $0$ and $1$.
  • repeat for $y$ and $z$ planes.
  • Add $(x_m,y_m,z_m, k=0)$ and $(x_M,y_M,z_M,k=1)$ to your list of interesting points, then sort them by $k$.
  • Final step, for consecutive pairs of sorted points, calculate the length of the segment between them and multiply with the value of the grid at the center of the segment. Sum these values to get your result