Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a 3d table that represents distance for a given
height angle and temperature

for example the table looks like this
For angles from 0 through 45 to 90
and height from 0 through 200 to 600
and temperature from -5 through 10 to 25

Angle        |__0__|__45__|__90__
Height |Temp'|
0      | -5  |_25__|__19__|__17__
0      | 10  |_20__|__16__|__12__
0      | 25  |_27__|__32__|__30__
200    | -5  |_27__|__32__|__30__
200    | 10  |_25__|__29__|__28__
200    | 25  |_24__|__22__|__20__
600    | -5  |_40__|__47__|__50__
600    | 10  |_38__|__42__|__46__
600    | 25  |_37__|__39__|__40__


for angle =45, height = 200 and temperature = -5 the value is 32

I want a c++ function that receives an angle height and temperature and
return the interpolated value of the distance
float GetInerpolatedVal(int angle,int Height, int temperature );
the call will look like this
float fVal = GetInerpolatedVal(24,343,-2)

I guess I need to use some kind of 3d interpolation but I cant seem to find
an implementation that works with a table such as this.
I Found a 3d interpolation that seems like this:
double Linear3dInterp(double v1, double v2, double v3, double v4,
double v5, double v6, double v7, double v8, x, y, z );
But i dont understand what are v1-v8 (i guess x y and z are a given height angle and temperature for my example)

Thanks!

What I have tried:

Googling 3d interpolation
Using 1d interpolation as a base for 2d interpolation
and then Using 2d interpolation as a base for 3d interpolation
but i got confused with which values are the boundaries for the 2d interpolation
Posted
Updated 20-Mar-23 1:48am
v2

The value of the angle will tell you which column to select for the other values. Select the correct row in the height and temparature table. Then select the cell from the column that corresponds to the angle.
 
Share this answer
 
Comments
dj4400 16-Mar-23 12:09pm    
Thanks for your reply.
I know how to read the table - but not how to interpolate data from it
or calling Linear3dInterp according to it (v1-v8 represents vertices of a cube but how does that apply to my table?)
Richard MacCutchan 16-Mar-23 12:23pm    
I think you are expected to write the code yourself. See Interpolation Definition (Illustrated Mathematics Dictionary)[^] and Trilinear interpolation - Wikipedia[^].
Think about what an interpolation operation is. You need to calculate a target value using known values you have. If you don't have known values for the value you're looking up, you need to get the key values around your lookup value, calculate the distance your known value sits away from the key values, then you can apply that percentage to the key lookup values to get your target value.
 
Share this answer
 
A function that does interpolation in three dimensions can have arguments something like this :
C++
double Interpolate3D( 
              double xcoord1
            , double ycoord1
            , double zcoord1
            , double value1
            , double xcoord2
            , double ycoord2
            , double zcoord2
            , double value2
            , double xcoord3
            , double ycoord3
            , double zcoord3
            );
Sometimes the three coordinates are passed as a vector class or structure.

Here is one method that seems to be kind of what you are looking for : Trilinear interpolation - Wikipedia[^]
 
Share this answer
 
Thanks all

I have eventually understood how to create the 8 values input vector from my table and
add the requested values for the interpolation.
By using 1d interpolation as a base to 2d interpolation implementation and 2d interpolation as a base for 3d interpolation.
For example in the table above for loat fVal = GetInerpolatedVal(angle= 24, Height= 143,temperature-2)
call 1d interpolation for 25-19 and 20-16 with requested angle 24
then take the 2 results and call 1d interpolation with requested temperature -2
This 3 calls are basically 2d interpolation implementation (for 0m)
Call another 2d interpolation with 27-32 and 25-29 (for 200m)
Take the 2 results of 2d interpolation and call 1d interpolation for request height of 143
This 3 calls 2 times 2d interpolation and 1 time 1d interpolation on the results is basically 3d interpolation implementation
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900