- Create the Smooth Surface: Define a smooth surface to represent the base material.
- Overlay the Rough Surface: Use a loop to simulate the rough surface passing over the smooth surface. You can visualize this by updating the position of the rough surface incrementally.
- Visualize the Process: Use pause to step through the simulation manually.
How to pass 3D surfaces over each other?
5 ビュー (過去 30 日間)
古いコメントを表示
Hi, I'm trying to pass a rough 3D surface over a smooth surface to essentially simulate a grinding process. Ideally the code would allow me to manually step through the process to see visualize it better.
Anything helps, thank you!
Here is the rough surface:

Here is the code that generated the rough surface:
close all % closes open graphs
clc % clears console / cmd window
rng default % keeps RNG seed constant
clear all
M = zeros(100,100); % initial matrix
gritDensity = 0.002; % grit per area
N = 50 % number of grit // % size(M,1).*size(M,2).*gritDensity;
sigma = 2; % stdev (width)
mu = 5; % median
[x,y] = meshgrid(1:size(M,1),1:size(M,2)); % creates grid
for k = 1:N
% random location of grit
xc = randi(size(M,1)); % picks random location on x axis between 0 and max value
yc = randi(size(M,2)); % picks random location on y axis between 0 and max value
r = normrnd(mu,sigma); % radius, rand/randn/normrand?
s = r^2-((x-xc).^2+(y-yc).^2); % equation for circle
b = s>=0; % checks if 's' is a positive number
M(b) = max(M(b),sqrt(s(b))); % indexes boolean result into the matrix M, creates "blanket" effect
end
surf(M)
axis equal
shading faceted
0 件のコメント
回答 (1 件)
AKennedy
2025 年 2 月 13 日
To simulate a grinding process where a rough surface moves over a smooth surface, you can visualize the interaction by overlaying the surfaces and manually stepping through the process.
% Generate rough surface with the code you have
% Generate a smooth surface (e.g., a plane)
smoothSurface = zeros(size(M));
% Visualization parameters
numSteps = 20; % Number of steps for the rough surface to move
stepSize = 5; % Step size for moving the rough surface
% Create a figure
figure;
hold on;
% Loop to simulate the grinding process
for step = 1:numSteps
% Clear the previous plot
clf;
% Plot the smooth surface
surf(x, y, smoothSurface, 'FaceAlpha', 0.5, 'EdgeColor', 'none');
hold on;
% Calculate the offset for the rough surface
offsetX = stepSize * (step - 1);
offsetY = stepSize * (step - 1);
% Plot the rough surface with an offset
surf(x + offsetX, y + offsetY, M, 'EdgeColor', 'none');
% Set plot properties
axis equal;
shading interp;
title(['Step ', num2str(step)]);
xlabel('X');
ylabel('Y');
zlabel('Z');
% Pause to manually step through the process
pause(0.5); % Adjust the pause duration as needed
end
hold off;
The rough surface is moved over the smooth surface by incrementally changing its position using offsetX and offsetY. Adjust the pause duration and numSteps as needed to better visualize the grinding process.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!