Filter löschen
Filter löschen

Trying to plot surface using "surfir" - but getting the wrong boundary (due to interpolation error)

1 Ansicht (letzte 30 Tage)
I am trying to take the output of a solution to a problem in COMSOL, and construct a smooth surface using the (x,y,z) values. I have come across the very helpful function surfir, which very nearly does exactly what I want.
I have written my own function called mphplot2surf as below, which uses LiveLink with COMSOL to load a model (called "model") in MATLAB and examine the data produced, referring to a plot group known as "pg".
function out = mphplot2surf(model,pg)
comsolPlot = mphplot(model,pg)
xCoords = double((comsolPlot{2}{1}.p(1,:))');
yCoords = double((comsolPlot{2}{1}.p(2,:))');
zCoords = double(comsolPlot{2}{1});
surfir(xCoords,yCoords,zCoords,0.2)
end
and with a particular model and plot group in mind, I get the following plot, where I have added some black lines to indicate where the true boundary of the domain is. It is a T-shaped domain, but MATLAB has incorrectly interpolated between two points on each side and therefore not correctly identified the true boundary. Since surfir relies on interpolation, I can't simply select points on these triangular portions and delete them.
I am stumped as to how to fix this. Could anybody please assist (even if you haven't used COMSOL before)
  1 Kommentar
Stephen23
Stephen23 am 8 Feb. 2023
Bearbeitet: Stephen23 am 8 Feb. 2023
"but MATLAB has incorrectly interpolated between two points on each side and therefore not correctly identified the true boundary."
Actually it is the third-party function SURFIR() that does that. The function SURFIR() relies on
to detect the boundary points, which according to its documentation uses an alpha shape:
The "tightness" of its fit can be controlled by its "shrink factor" input argument (default value = 0.5). But it is the nature of an alpha shape (moving a circle/sphere around the points cloud) that it cannot really fit into a arbitrarily tight corners like your concave right angles. It rather depends on the density of your data points, but I suspect that an alpha shape will not work for you.
Why not just interpolate over the whole rectangle, and then mask the points using NaN when plotting?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by