I'm plotting several lists of data (constant lines of density, temperature quality, etc. on a pressure-enthalpy diagram), none of which are fitted well by Interpolation
or Fit
. Since each table/line represents a constant density (in this case), I want to determine what density is at any selected point based off of the two nearest density lines (blue).
- Blue points are data points in
rho
lists. - Orange points are all points from my function
TotalClose
which returns one point from eachrho
list. - Green points are from my function
PointClose
. - Largest black point is set with
Manipulate
controls.
The Locator
is on a log scale so pt
makes it linear for calculations:
Control[{{pt0,{2295,Log@145}},Locator}]
pt={First@pt0,Exp@Last@pt0};
In my attempt I found the point from each rho
list closest to the point pt
selected with the Locator
:
TotalClose[list_]:=First@Nearest[list[[#]],pt]&/@Range@Length@list;
PointClose[list_]:=Nearest[TotalClose[list],pt,2];
Functions are evaluated at {rho1000,rho700,rho50,rho2,rho02}
The green points PointClose
returned are not correct here. It needs to return points from the rho700
and rho50
lists. This would be easier if I could fit these lists to a function but they won't.
I was planning on using the lever rule to determine what the density would be at the selected point. I am stuck as to how to get which two rho
lists are either immediately to the left and right or above and below pt
.
I tried changing the DistanceFunction
in Nearest
with no luck:
DistanceFunction->(((#1[[1]]-#2[[1]])^2+(Log@#1[[2]]-Log@#2[[2]])^2)^1/2&)
Here are the rho
lists that make the blue constant density lines:
rho1000 = {{2674.112, 10000.}, {2442.182, 9000.}, {2211.362,
8000.}, {1980.958, 7000.}, {1750.036, 6000.}, {1517.27,
5000.}, {1280.666, 4000.}, {1036.931, 3000.}, {779.806,
2000.}, {493.584, 1000.}, {461.831, 900.}, {429.132,
800.}, {395.296, 700.}, {360.063, 600.}, {323.059,
500.}, {283.706, 400.}, {241.029, 300.}, {193.124, 200.}, {135.03,
100.}, {120.986, 80.}, {105.405, 60.}, {87.389, 40.}, {64.549,
20.}, {48.572, 10.}, {44.443, 8.}, {39.658, 6.}, {34.028,
4.098}, {29.72, 2.984}, {25.44, 2.181}, {21.188, 1.692}, {16.964,
1.521}, {16.964, 0.05}};
rho700 = {{5000., 8801.33}, {4642.4, 8000.}, {4207.4, 7000.}, {3784.3,
6000.}, {3371.92, 5000.}, {2968.32, 4000.}, {2570.4,
3000.}, {2173.14, 2000.}, {1767.73, 1000.}, {1726.18,
900.}, {1684.37, 800.}, {1642.24, 700.}, {1599.79,
600.}, {1556.95, 500.}, {1513.7, 400.}, {1469.97, 300.}, {1425.7,
200.}, {1380.8, 100.}, {1377.65, 93.070}};
rho50 = {{5000., 331.29}, {4673.64, 300.}, {3703.16, 200.}, {2815.85,
100.}, {2739.86, 91.84}, {2444, 71}, {2100, 50}, {1900,
37}, {1700, 26}, {1490, 15.5}, {1300, 9.5}, {1050, 4.1}, {820,
1.6}, {590, 0.5}, {425, 0.2}, {325, 0.1}, {250, 0.05}};
rho2 = {{5000., 13.07}, {4184.58, 10.}, {3693.09, 8.}, {3234.16,
6.}, {2802.61, 4.}, {2734.26, 3.68}, {2500, 3.3}, {2150,
2.5}, {1950, 2}, {1750, 1.5}, {1500, 1}, {1230, 0.6}, {1020,
0.38}, {815, 0.2}, {660, 0.115}, {450, 0.05}};
rho02 = {{5000., 1.31}, {4184.66, 1.}, {3692.28, 0.8}, {3232.73,
0.6}, {2803.20, 0.4}, {2626.43, 0.31}, {2500, 0.32}, {2250,
0.32}, {2000, 0.3}, {1840, 0.28}, {1660, 0.24}, {1480,
0.2}, {1250, 0.15}, {1000, 0.105}, {810, 0.08}, {550, 0.05}};
Interpolation
of the data sets? You should be able to. $\endgroup$Interpolation
, that and some don't pass the vertical line test $\endgroup$f = Interpolation /@ Transpose @ rho1000
, for instance. This returns a list of two pure interpolating functions that you can plot parametrically:ParametricPlot[Through@f@t, Evaluate@Flatten@{t, f[[1]]["Domain"]}, AspectRatio -> 1]
. I've been trying to figure out how to do the calculation of the nearest points on the curves, but haven't succeeded yet. Perhaps you can have a go with these interpolations. $\endgroup$