Projecting 2D drawing onto a 3D closed mesh

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
Edited: Hitesh on 18 Nov 2024
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

h = surf(X, Y, Z);
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
Instead of taking those steps, you can use https://www.mathworks.com/help/images/ref/warp.html
Hello, thank you for taking the time to help me! I understand your approach is to texture an image onto the mesh, is it still possible to use a drawing input instead (dxf format) so that I can have better control of the geometry and dimensions? My idea is to be able to position the drawing over any part of the mesh and change its size so that the drawing is located only on certain parts of the mesh. Additionally, is it possible to afterwards extract the intersection points of the mesh and the drawing? Essentially, know exactly what points of the mesh are housing the drawing? Thanks!
When you texturemap, the intersection of the drawing and the mesh occurs at every pixel from one point of view. Or along every edge from a different point of view.
Regardless of the perspective, would you be able to obtain the x,y,z coordinates of the intersections?
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.

Asked:

on 18 Nov 2024

Commented:

on 18 Nov 2024

Community Treasure Hunt

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

Start Hunting!