How to subtract surface from pdegplot?

1 visualización (últimos 30 días)
Baisseyev Miram
Baisseyev Miram el 14 de Dic. de 2018
Editada: Maneet Kaur Bagga el 8 de Oct. de 2024
Hi, sorry for bad english. I want to subtract surface created from x,y,z coordinates from stl model imported by pdegplot. I imported stl model and extacted X,Y,Z values of this model, then by using griddata command i made dimention of X and x same and subtracted and get result like in image. In red section what i want, but result also create subtraction result in blue sections. So is the any way to get only result only in red section? The basic code is presented
model = createpde;
importGeometry(model,'BELT PULLEY.stl');
U= generateMesh(model)
pl2=pdeplot3D(model)
X=pl2.XData;
Y=pl2.YData;
Z=pl2.ZData;
Xgrid = griddata(y,z,x,Y,Z,);
hh=plot3(X-Xgrid,Y,Z)
image2.PNG

Respuestas (1)

Maneet Kaur Bagga
Maneet Kaur Bagga el 8 de Oct. de 2024
Editada: Maneet Kaur Bagga el 8 de Oct. de 2024
Hi ,
As per my understanding, the code has the following errors:
  1. The function "generateMesh(model)" was called but the output "U" is not used to access nodes and elements of the generated mesh.
  2. The variable "pl2 = pdeplot3D(model)" assigns the plot to a variable, but "pdeplot3D" does not return the data in the way you are trying to access. This function is used for plotting and not for extracting X, Y, and Z data directly. You can extract the mesh node coordinates from the generated mesh model.
  3. The "griddata" function call "Xgrid = griddata(y,z,x,Y,Z,);" is incorrect as the variables "x", "y" and "z" are not defined.
Please refer to the modified code below for better understanding of the above mentioned points:
model = createpde;
mesh = generateMesh(model); % Generate mesh for the geometry
% Extract mesh node coordinates
X = model.Mesh.Nodes(1, :); % X coordinates
Y = model.Mesh.Nodes(2, :); % Y coordinates
Z = model.Mesh.Nodes(3, :); % Z coordinates
% Use griddata
Xgrid = griddata(Y, Z, X, Y, Z); % Interpolating the X values
% Define bounds for where you want to subtract
x_min = -10; x_max = 10;
y_min = -5; y_max = 5;
z_min = 0; z_max = 15;
% Create a mask for the red section
mask = (X > x_min) & (X < x_max) & (Y > y_min) & (Y < y_max) & (Z > z_min) & (Z < z_max);
% Apply the subtraction only in the selected region
X_subtracted = X;
X_subtracted(mask) = X(mask) - Xgrid(mask);
% Plot the result
figure;
plot3(X_subtracted, Y, Z);
I hope this resolves your query!

Community Treasure Hunt

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

Start Hunting!

Translated by