Projecting 2D drawing onto a 3D closed mesh
50 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pablo
el 18 de Nov. de 2024 a las 5:45
Comentada: Walter Roberson
el 18 de Nov. de 2024 a las 23:24
Hello,
I am attempting to project a 2d drawing onto a 3d mesh so that the 2d drawing completely follows the contours of the mesh similar to how a sticker would conformally be laminated onto a sphere for example. I have attempted a few ideas similar to projecting a 2d drawing onto a 3d surface but I can't repeat it for a volume. So for example, how can I project the pattern in figure 1 onto the sphere in the second figure. I am importing the drawing in figure 1 but I could use any pattern as a starting point. Thanks
0 comentarios
Respuestas (1)
Hitesh
el 18 de Nov. de 2024 a las 6:37
Editada: Hitesh
el 18 de Nov. de 2024 a las 6:46
You can use the "set" function to map the image as a texture onto the sphere's surface. You need to set the "FaceColor" to "texturemap", and the "CData" property to the loaded image. Refer to below code as example :
% Generate the coordinates for a sphere with a specified number of divisions
[X, Y, Z] = sphere(50);
figure;
% Create a 3D surface plot of the sphere using the generated coordinates
h = surf(X, Y, Z);
% Load an image from a file to use as a texture for the sphere
img = imread('pattern.png');
% Set properties for the surface plot to apply the texture
set(h, 'FaceColor', 'texturemap', ... % Use the image as a texture map for the sphere's surface
'CData', img, ... % Set the texture data to the loaded image
'EdgeColor', 'none'); % Remove the grid lines on the sphere for a smoother appearance
% Adjust the axes to ensure equal scaling, so the sphere appears round
axis equal;
% Add a light source relative to the camera to enhance 3D visualization
camlight;
% Apply Gouraud shading for smooth color transitions across the sphere's surface
lighting gouraud;
% Set the view to a 3D perspective
view(3);
For more information on "set" function, kindly refer to the following MATLAB documentation:
5 comentarios
Walter Roberson
el 18 de Nov. de 2024 a las 23:24
Sure you can get the x y z coordinates of the intersections:
surfh = findobj(gcf, 'type', 'surface');
if isempty(surfh)
error('did not find surface')
end
coordinates_of_intersection = [surfh.XData(:), surfh.YData(:), surfh.ZData(:)];
This is because when you texturemap, the CData is wrapped to the entire surface, so the coordinates of intersection is identical to the coordinates of the surface.
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!