Plotting a volume in 3D
19 次查看(过去 30 天)
显示 更早的评论
How do I plot a solid volume given (x, y, z). they are defiend by 3 parameters (t1, t2, t3). each is defined over a range of values (minimum and maximum).
any help would be much appreciated!
0 个评论
回答(2 个)
Gautam
2024-10-23,12:23
Hello @Michael Ross
To plot a solid volume defined by parameters t1, t2, t3, where each parameter has a defined range, you can use MATLAB's "meshgrid" and "scatter3" functions.
Below is a sample code that plots a volume with the output
% Define the parameter ranges
t1_min = 0; t1_max = 1; % Range for t1
t2_min = 0; t2_max = 2; % Range for t2
t3_min = 0; t3_max = 3; % Range for t3
% Define the number of points in each parameter direction
nPoints = 20;
% Create a grid of points in the parameter space
[t1, t2, t3] = ndgrid(linspace(t1_min, t1_max, nPoints), linspace(t2_min, t2_max, nPoints), linspace(t3_min, t3_max, nPoints));
% Define the functions for x, y, z in terms of t1, t2, t3
x = t1 .* cos(t2) .* sin(t3);
y = t1 .* sin(t2) .* sin(t3);
z = t1 .* cos(t3);
% Plot the volume
figure;
scatter3(x(:), y(:), z(:), 20, z(:), 'filled');
axis equal;
grid on;
For more information on these functions, you can refer to the following MathWorks documentation:
0 个评论
John D'Errico
2024-10-23,14:50
编辑:John D'Errico
2024-10-24,12:34
Your question is somewhat incomplete, as to what you mean by plotting a solid volume. I'll assume you may mean something like the surface of an ellipsoid. And that is quite easy. Of course, it depends on what form you have the equations of that surface. You might have it defined symbolically, or as a function handle.
syms t1 t2 t3
eqn = t1^2 + t2^2 + 2*t3^2 - t1-t2*t3/5 + t1*t2/3;
fimplicit3(eqn)
grid on
box on
axis equal
The result is a nice 3-d ellipsoid. Quite easily done, as I said.
But perhaps from your question, all you have is a cloud of points in 3-d. Again, not at all clear as to your real question. But if that is your question, then you would generally need to form the "surface" of that cloud. That might be done using a convex hull, or if it is not a convex volume, then an alpha shape may be a good choice. For example...
xyz = rand(10000,3);
D = sqrt(sum((xyz - [1 1 1]).^2,2));
xyz(D <= 0.75,:) = [];
plot3(xyz(:,1),xyz(:,2),xyz(:,3),'o')
view(-21,53)
I've creates a point cloud of a box like thingie, with a spherical cutout in one corner of radius 0.75. Can we transform that into a "solid" object now? It will never be perfect of course, since we have only a point cloud.
figure
S = alphaShape(xyz)
plot(S)
Note that this thing above is pretty rough. If we rotate it around, we may even find holes near the edges, and too many irregularities.
S.Alpha = 0.5;
figure
plot(S)
view(-21,53)
That seems fairly reasonable, made by a slightly larger value for alpha in the alpha shape.
Alpha shapes do not always work perfectly well of course. But the can sometimes do a reasonable job.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!