Projecting 2D drawing onto a 3D closed mesh

51 vues (au cours des 30 derniers jours)
Pablo
Pablo le 18 Nov 2024 à 5:45
Commenté : Walter Roberson le 18 Nov 2024 à 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

Réponses (1)

Hitesh
Hitesh le 18 Nov 2024 à 6:37
Modifié(e) : Hitesh le 18 Nov 2024 à 6:46
Hi @Pablo,
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 commentaires
Pablo
Pablo le 18 Nov 2024 à 20:28
Regardless of the perspective, would you be able to obtain the x,y,z coordinates of the intersections?
Walter Roberson
Walter Roberson le 18 Nov 2024 à 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.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by