[Scilab-users] Non rectangular contour plot

Pinçon Bruno bruno.pincon at univ-lorraine.fr
Mon Jan 30 16:20:37 CET 2017


Le 30/01/2017 à 00:25, Max Rossi a écrit :
> Hi all,
>
> I'm trying to plot in Scilab the surface error of different non rectangular
> panels (see attachments).
> At a certain point of my code, everything is turned into nice XYZ data but
> the only way I found to plot the data is to generate a grid and fit the Z
> above it as follows:
>
>          tl_coef = cshep2d(XYZ);
>          xpx = round((max(X)-min(X))/pix_size);
>          ypx = round((max(Y)-min(Y))/pix_size);
>          vx = linspace(min(X),max(X),xpx);
>          vy = linspace(min(Y),max(Y),ypx);
>          [Xg,Yg] = ndgrid(vx,vy);
>          map1 = eval_cshep2d(Xg,Yg, tl_coef);
>
> When the panel is not rectangular or circular I'm in trouble assigning %nan
> to points that are inside the grid but outside the panel XY measured
> locations.
> Is there any smart way to manage the problem?

      Hello,

/If I understand well, you want a way to put Nan for those
  grid points which are far from interpolation points (because
  the values got by cshep2d are not really meaningful due to
  large errors) ? For "exterior points", assuming the interpolation
  region is more or less convex a possibility would be to compute
  the convex-hull of the (x-y coordinates) interpolation points and
  to test if each grid point is inside but I 'm not sure you can do
  that immediatly with scilab : the convex hull function was part of
  metanet which is not embedded in scilab since a while, maybe
  it is still available through atoms. Btw I don't remenber if there
  is a "inside polygon test" in scilab.

   Otherwise you could try a force brute method (which could be
  accelerated) by computing the minimal distance between each grid
  point to the interpolations points and discarding those which
  are too far. This can be done like this : (assuming that X and Y
  are the coordinates of the interpolation points)

[Xg,Yg] = ndgrid(vx,vy);
Zg = eval_cshep2d(Xg,Yg, tl_coef);

// compute distance betwen grid and interpolation points
ngp = size(Zg,"*")
dmin = zeros(Zg)
for k = 1:ngp
     dmin(k) = sqrt(min( (Xg(k) - X).^2 + (Yg(k) - Y).^2) )
end

// discard points which are too far
threshold_dist = 0.1   // to be set adequately...
Zg(dmin > threshold_dist) = %nan


   hth
  Bruno





///
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170130/e00743d1/attachment.htm>


More information about the users mailing list