Help! Project a 3D Mesh to an image - how to get the corresponding 2d coordinates with 3D points
7 views (last 30 days)
Show older comments
I'm rendering a 3d mesh using opengl as renderer and the trimesh function.
trimesh(... face, mesh(:, 1), mesh(:, 3), mesh(:, 2), ... 'EdgeColor', 'none', ... 'FaceVertexCData', tex/255, 'FaceColor', 'interp', ... 'FaceLighting', 'phong' ... );
set(gca, ... 'DataAspectRatio', [ 1 1 1 ], ... 'PlotBoxAspectRatio', [ 1 1 1 ], ... 'Units', 'pixels', ... 'GridLineStyle', 'none', ... 'Visible', 'off', 'box', 'off', ... 'Projection', 'perspective'... );
then, I want to know the 2d pixel coordinates of every 3D points without any other calculation.
I've been playing with this for a while and am pretty much stumped, any help would be hugely appreciated.
0 Comments
Answers (1)
George Abrahams
on 10 Feb 2024
Edited: George Abrahams
on 10 Feb 2024
If you're not commited to using the MATLAB axes' camera, my 3D Rendering Toolbox on File Exchange contains the function world2image which will give you the 2D (X,Y) coordinates of every 3D (X,Y,Z) vertex.
N.B. Technically world2image will also give you a Z-coordinate, which is used for Z-buffering if you want to subsequently rasterize/render the mesh, but you can just ignore this.
0 Comments
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!