Help! Project a 3D Mesh to an image - how to get the corresponding 2d coordinates with 3D points

7 次查看(过去 30 天)
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.

回答(1 个)

George Abrahams
George Abrahams 2024-2-10
编辑:George Abrahams 2024-2-10
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.

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by