Interpolation

Dear Experts,
I was looking for the way to make 2D interpolation based on two input values (Qb/Qc, Ab/Ac):

I.e.:
Qb/Qc = 0.285
Ab/Ac = 0.303
Result: 0.88

@kvusal ,

i found just python stuff
https://docs.scipy.org/doc/scipy/tutorial/interpolate/1D.html
KR
Andreas

2 Likes

I think its possible with just Dynamo too. Something like that:

Lets say this is the list with the positions, by the given example all the Q and A values:

The matrix is a list of lists so it’s easy to represent in a simple way in Dynamo. You round the numbers and get the closest value for both positions, while you also define a multiplier like that:

In the end, you get the two indexes, you can use them to get the value from a second matrix and apply the multiplier.

I haven’t had time to validate the logic, but I think it should work at least as a general concept :slight_smile:

EDIT: I actually think the logic is ok, but the multiplier formula should be a bit different:

Home.dyn (26.6 KB)

3 Likes

Hello, here is a possibility
(Data must exist in csv format)


edit: I substituted the hastily written code block with a python script, in case you go that route.
Python Script:

List_Polycurve=IN[0]

OUT = [[List_Polycurve[i],List_Polycurve[i+1]] for i in range(0,len(List_Polycurve)-1)]

Cordially
christian.stan

3 Likes

wow, turning the matrix into a surface and simply getting a point’s Z value, brilliant ! :slight_smile:

2 Likes

Thanks,here’s the dot matrix (now my eyes hurt with this data, time to bask :wink:)
and the complete script.

here
a=1..9;
[a,a,a,a,a,a,a,a,a];
[[0.73,0.34,0.32,0.34,0.35,0.37,0.38,0.39,0.40],
[3.10,0.73,0.41,0.34,0.34,0.32,0.32,0.33,0.34,0.35],
[7.59,1.65,0.73,0.47,0.37,0.34,0.32,0.32,0.32],
[14.2,3.1,1.28,0.73,0.51,0.41,0.36,0.34,0.32],
[22.92,5.08,2.07,1.12,0.73,0.54,0.44,0.38,0.35],
[33.76,7.59,3.1,1.65,1.03,0.73,0.56,0.47,0.41],
[46.71,10.63,4.36,2.31,1.42,0.98,0.73,0.58,0.49],
[61.79,14.2,5.86,3.1,1.9,1.28,0.94,0.73,0.6],
[78.98,18.29,7.59,4.02,2.46,1.65,1.19,0.91,0.73]];

24 Mai Forum anglais.dyn (23.9 KB)

Good evening
edit: She has a funny look this surface :grinning:

Cordially
christian.stan

6 Likes

Dear Cristian,
is it possible to adopt mentioned script to this input:
image

Hi,
The matrix only enlarges, so normally no impediment

From a PDF read the data to create the matrix, Mr. @c.poupin, may have already done this kind of thing, on occasion he will answer you.

Sincerely
christian.stan

Thanks for prompt feedback.
I could not able to create list for mentioned matrix :slightly_frowning_face:
What can be reason?


Correct Matrix.dyn (7.7 KB)

Lacing long


cordially
christian.stan

1 Like

Hi,


# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

import pandas as pd
import scipy 
from scipy.interpolate import griddata

csv_path = IN[0]
row_value = IN[1]
column_value = IN[2]

#load a csv file into a dataframe using pandas
df = pd.read_csv(csv_path)

# set the index of the dataframe as the "Ab_Ac" column
df = df.set_index('Ab_Ac')

#This code creates a list of tuples for each index and column in the dataframe
index_column_tuples = [(index, col) for index in df.index for col in df.columns]

# create a list of values by iterating through the index_column_tuples list
# and appending the value at that index and column in the dataframe
values = [float(df.at[row, col]) for row, col in index_column_tuples]

# create a list of index_column values by iterating through the index_column_tuples list
# and appending the index and column values as floats
index_column_values = [[float(i), float(j)] for i , j in index_column_tuples]

# uses the griddata function from scipy to interpolate the data at the index_column values
test = griddata(index_column_values, values, (row_value, column_value) )


#This line of code outputs the dataframe and the interpolated value
OUT = repr(df), float(test)
2 Likes

Dear Christian,
it seems great solution. But today i realized that this solution is not working on the negative Z values of surface. What kind of revision we can do in order to get result?
Thanks in advance.
Negative Z Value Error.dyn (29.9 KB)

1 Like

Hello here

sincerely
christian.stan

1 Like

Create Approach. Many thanks.

1 Like