Projecting 2D drawing onto a 3D closed mesh

51 views (last 30 days)
Pablo
Pablo on 18 Nov 2024 at 5:45
Commented: Walter Roberson on 18 Nov 2024 at 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

Answers (1)

Hitesh
Hitesh on 18 Nov 2024 at 6:37
Edited: Hitesh on 18 Nov 2024 at 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 Comments
Pablo
Pablo on 18 Nov 2024 at 20:28
Regardless of the perspective, would you be able to obtain the x,y,z coordinates of the intersections?
Walter Roberson
Walter Roberson on 18 Nov 2024 at 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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!