# Surface Plot problem Good evening everyone, I got a little problem that I hope you will be able to help me with. The problem I am facing is the following (i study physic, just for info): after a simulation, I obtained a series of points, every one represented by a set of three value. 2 are coordinates (xy plane) and the third (z) is the corresponding energy. I convert the three waves in an uniqe 3D waves and with Gizmo I was able to create a scatter plot without any problem. What i want for my work is not a series of point in the graph, but a surface that connect all my points. In Gizmo if, instead of selecting scatter i choose surface, nothing is displayed. My problem is this, what is the right way to convert 3 wave representing X,Y and Z value in an unique surface wave to use in Gizmo?
Thank to everyone that will help me
Stefano

P.S. i'm sorry for my bad english , but i'm not english
I think that the easiest way is to interpolate your {x,y,z} waves into a 2D matrix (sampling on a rectangular grid), which you can then straightforwardly plot as a surface. There are built-in procedures for this in recent versions of Igor: go to the data menu -> Packages -> XYZ to matrix.
741 is exactly right. The other route to his solution is to put
#include <XYZtoMatrix>

at the beginning of your Procedure file, select your conversion choice from the Macros menu, and follow the prompts in the interface window.

However, making a Gizmo surface plot with the resulting matrix shows interpolated values. You can create a Gizmo surface plot connecting the exact XYZ points, but this involves creating the appropriate two-dimensional parametric triangles wave. It is more complicated, so let us know if this is really what you need.
It is pretty common for a triplet data set like yours to be sampled on a grid, but transmitted as a series of triplet values. If it is sampled on a grid, then the Redimension command can be used to "fold" the Z values into a grid. This does not involve interpolation, just a interpreting the values differently.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
John,
I wanted to experiment with your suggestion and run some tests, so I started with a preliminary check:
#pragma rtGlobals=1     // Use modern global access method.
#include <MatrixToXYZ>
#include <XYZtoMatrix>

function foo()
make/O/N=(20,20) wave0
setscale x, -1, 1,"" wave0
setscale y, -1, 1,"" wave0
wave0 = exp( - 4*(x^2+y^2)) + gnoise(0.1)
Execute "MatrixToXYZTriplet(\"wave0\",\"triplet\",2)"
Execute "XYZTripletToMatrix(\"triplet\",\"wave1\",20,20,NaN,NaN,NaN,NaN,2,2)"
end

The curious thing is that the reconverted Matrix ('wave1') has dimension (19,19) whereas the starting matrix was (20,20). The data in the common points agrees, but the 'wave1' scales are shifted. The intermediate 'triplet' wave has the correct (400,3) dimensionality. What am I doing wrong here? (IP 6.22A, WinXP)
s.r.chinn wrote:

The curious thing is that the reconverted Matrix ('wave1') has dimension (19,19) whereas the starting matrix was (20,20). The data in the common points agrees, but the 'wave1' scales are shifted. The intermediate 'triplet' wave has the correct (400,3) dimensionality. What am I doing wrong here? (IP 6.22A, WinXP)

Hi Steve,

John's suggestion is an important consideration: if the data are sampled on a grid one should not resort to triangulation. Not only is it computationally wasteful but it is also a source of inaccuracies as you discovered.

The old procedures that you used rely on ImageInterpolate Voronoi which builds the Delaunay triangulation for what it thinks is scatter data. Normally, the algorithm introduces a small, random perturbation of the XY locations and proceeds to triangulate as if the data were not sampled on a rectangular grid (this is because a pure rectangular grid does not have a unique triangulation). Next, you are trying to interpolate at the exact locations of the original data -- something that the Voronoi interpolation is not real happy about. If you run some careful tests you would notice that you may get NaNs on the boundary although you may be perfectly correct to expect a finite value. The reason for a NaN result in this case is that the initial perturbation which I mentioned above renders your interpolating point outside the convex domain and so you get a NaN. This is also dependent on the tolerance value provided in a /PFTL flag (but this is probably more than you might want to tweak).

To get around some of these issues the procedure tries to choose the parameters for the /S flag so that they stay within the convex domain. This results in the apparent shift that you observed but the procedure was never intended to be reversible.

If you really want to evaluate the quality of the various representations I recommend a composite Gizmo plot. Plot the triplet as a scatter and the 2D wave as a surface and see how they match.

A.G.
WaveMetrics, Inc.

A.G wrote:
This results in the apparent shift that you observed but the procedure was never intended to be reversible.

Thanks for explaining this. I was merely trying to exercise some useful WM Procedures prior to trying John's "folding" suggestion, but with different triplet ordering scenarios (e.g. the triplets are known to be grid samples, but not in any predictable order.)