"Unfold" a 3D point cloud onto a 2D map

I have a 3D point cloud from a FE-analysis with pressure values for each point. X-, y-, z-coordinates and pressure values are stored column-wise in a csv-file. Here is a 3D-scatter plot of the points:
As you can see, the coordinates create a curved surface/strip. Now imagine you were to place a strip of tape along this surface, project the pressure magnitude onto it and then flatten it. Then you would have a 2D-map with projected x-values on the x-axis, y-values the same as in the csv-file on the y-axis and then respective pressure magnitude-values for each point.
I would like to plot the pressure distribution as a colored 2D contour-map.
Here is my attempt scripting a solution but now im stuck:
clc
clear all
%importing csv file.
filename = "contpres_87905_0.11333.csv";
C=readtable(filename);
% coordinate system is rotated in ANSYS. geometry is in 2nd quadrant.
x=C.zcor;
y=C.ycor;
z=C.xcor;
A=C.Pressure;
%remove rows with only zeros
x = x(any(x,2),:);
y = y(any(y,2),:);
z = z(any(z,2),:);
A = A(any(A,2),:);
% Get new x-axis coordinates with custom function below
tc=unfoldCircum(x,z);
%length
l=length(A);
% interpolation of magnitudes
xv = linspace(min(tc),max(tc),l);
yv = linspace(min(y),max(y),l);
[X,Y] = ndgrid(xv,yv);
Z = griddata(tc, y, A, X, Y);
% plot
cMap=jet(16); %set the colomap using the "jet" scale
colormap(cMap);
h = surf(X,Y,Z);
set(h, 'edgecolor','none');
view(2);
colorbar;
xlim([min(tc) max(tc)])
%%%%%%%%%% function [tCoords] = unfoldCircum(x,y)
% This function takes a 2D coordinate data set and:
% - creates a smooth spline s(t) from the data
% - projects the 2D-points [xi,yi] onto the spline
% - returns the respective t-coordinate for each point
% x,y=column vectors of x- and y-coordinates with the same length
% Output
% tDist = Coordinate along tape from tape beginning
function [tCoords] = unfoldCircum(x,y)
np=length(x);
if(np ~= length(y))
error('input vectors are not the same size.')
end
tCoords=zeros(np,1);
%sort x and y coordinates.
[xsort, ind]=sort(x);
% new x-vector. the geometry have x-coordinates from ~-60 to 0mm
x_s = linspace(min(x), 0,np)';
% cubic smoothing spline using the SPLINEFIT package
% https://se.mathworks.com/matlabcentral/fileexchange/71225-splinefit
y_struct=splinefit(xsort,y(ind),20);
y_s=ppval(y_struct,x_s);
% TODO: calculate total spline length
l=100;
minDistV=zeros(np,2);
%for each coordinate [xi yi], find the nearest spline coordinate [xsj ysj].
for i=1:np
minDist=1e9;
for j = 1:np
dist2=sqrt((x(i)-x_s(j))^2 + (y(i)-y_s(j))^2);
if dist2<minDist
minDist=dist2;
minDistV(i,1)=j;
minDistV(i,2)=minDist;
end
end
%calculate t-coordinate by
tCoords(i)=minDistV(i,1)/np * l;
end
end

Answers (0)

Asked:

on 20 Sep 2021

Edited:

on 21 Sep 2021

Community Treasure Hunt

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

Start Hunting!