How to subtract a scatterplot object from a polyshape object

In my app I am defining polyshapes that represent satellite scan regions on Earth. I know how to subtract polyshapes from each other, for example along coastlines. Now I have a set of scatterplots that represent things such as sea ice, that I also need to subtract from the polyshape scan regions, something like this:
The pink represents the satellite scan region, and the blue is the scatterplot. I need to subtract the scatterplot area from the polyshape scan region. I know scatterplots do not have "area" per se, but perhaps we can define a boundary?
Is there a way to convert a scatterplot to a polyshape? I have seen several discussions here on scatterplots, but nothing quite like this situation. The closest I have come is this answer:
Thanks!

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 8 Apr. 2025

0 Stimmen

You can retrieve the XData and YData from the scatter plot, and pass the resulting points to boundary or alphaShape to trace around the outside of the set of points. This will give you a refined set of points that you can use to create another polyshape that you can then subtract from the original polyshape.

8 Kommentare

Kurt
Kurt am 8 Apr. 2025
Bearbeitet: Kurt am 8 Apr. 2025
So, I extract the XY pairs, ignoring NaNs, and dump them into another matrix? How do I keep the vertices well-ordered? I seem to recall a function for that. Maybe boundary is sufficient. Thanks
You do not need to keep them well-ordered to use boundary() or (more likely) alphaShape()
Unless what you are talking about is
xd = HANDLE.XData;
yd = HANDLE.YData;
xyd = rmmissing([xd(:), yd(:)]);
shp = alphaShape(xyd);
Kurt
Kurt am 8 Apr. 2025
Bearbeitet: Kurt am 8 Apr. 2025
I guess I can use isnan() to strip out all the fluff.
I played around with boundary() yesterday. I set the shrink factor to 1 and got a reasonable approximation of the outer boundary. However, if there are holes in the data patch, boundary can't detect them. That's probably OK in my case.
You are correct, rmmissing is probably a better choice.
What is wrong with using rmmissing to strip out the fluff?
If you must use isnan then
xd = HANDLE.XData;
yd = HANDLE.YData;
mask = isnan(xd) | isnan(yd);
xd(mask) = [];
yd(mask) = [];
shp = alphaShape(xd, yd);
but rmmissing is a more compact way of removing nan.
There are a large number of holes in data patches formed from scattered points. Even if you restrict your analysis to triangulations, every triangle created is a "hole"
This does not work well for polyshapes with multiple regions. If you are trying to match a scatterplot to an existing polyshape, the resulting new polyshape ends up with weird tendrils extending between the regions. I don't see any way around that.
Well you could do something like kmeans clustering and select each cluster and boundary() it individually.
... Now you just need a way of automatically determining the correct number of clusters...
Is there a way to divide a polyshape into its separate regions? I didn't see anything.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

peak
peak am 1 Apr. 2025
Bearbeitet: Steven Lord am 1 Apr. 2025

0 Stimmen

The scatterplot is shown in blue, while the satellite scan region is shown in pink. The scatterplot area must be subtracted from the polyshape scan region. https://www.mathworks.com/matlabcentral/answers/472879-surface-from-scatter-3-plot
[SL: Removed link that appeared to be unrelated to the question.]

1 Kommentar

Kurt
Kurt am 1 Apr. 2025
Bearbeitet: Kurt am 8 Apr. 2025
Can you elaborate on this ? I don't see a solution in the link. I'm trying to work with polyshapes, which are not quite the same thing as surface plots.
Also, my scatterplot data contains NaNs, which don't work well with mesh objects.

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Version

R2023b

Gefragt:

am 1 Apr. 2025

Kommentiert:

am 10 Apr. 2025

Community Treasure Hunt

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

Start Hunting!

Translated by