Is there a way to control distortion in Matlab's 3D viewer?
5 ビュー (過去 30 日間)
古いコメントを表示
The background of this problem relates to my attempt to combine output from a ray tracer with Matlab's 3d plotters. When doing ray tracing, there is no need to apply a perspective transformation to the rendered image. You see this in the image below. Basically, the intersections of the rays with the viewport will automatically adjust for the perspective scaling.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150017/image.png)
Suppose I've gone and created a ray-traced image (so I am given my camera, my focal length, viewport dimensions, etc.). How do I create exactly the same view in Matlab's 3d plotting environment?
Here is an example:
clear
close all
evec = [0 200 300]; % Camera position
recw = 200; % cm width of box
recl = 200; % cm length of box
h = 150; % cm height of box
% Create the front face rectangle
front = zeros(3,5);
front(:,1) = [-recw/2; 0; -recl/2];
front(:,2) = [recw/2; 0; -recl/2];
front(:,3) = [recw/2; h; -recl/2];
front(:,4) = [-recw/2; h; -recl/2];
front(:,5) = front(:,1);
% Back face rectangle
back = zeros(3,5);
back(:,1) = [-recw/2; 0; recl/2];
back(:,2) = [recw/2; 0; recl/2];
back(:,3) = [recw/2; h; recl/2];
back(:,4) = [-recw/2; h; recl/2];
back(:,5) = back(:,1);
% Plot the world view
figure(1);
patch(front(1,:), front(2,:), front(3,:), 'r'); hold all
patch(back(1,:), back(2,:), back(3,:), 'b');
plot3(evec(1), evec(2), evec(3), 'bo');
xlabel('x'); ylabel('y'); zlabel('z');
title('world view'); view([-30 40]);
% Plot the camera view
figure(2);
patch(front(1,:), front(2,:), front(3,:), 'r'); hold all
patch(back(1,:), back(2,:), back(3,:), 'b');
xlabel('x'); ylabel('y'); zlabel('z');
title('Camera view');
campos(evec);
camup([0 1 0]); % Up vector is y+
camproj('perspective');
camtarget([evec(1), evec(2), 0]);
title('camera view');
Now you see the world view
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150019/image.png)
and the camera view
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150021/image.png)
I know how to adjust the camera position, the camera view angle, and orientation to match the output from my ray tracer. However, I do not know how to adjust Matlab's built-in perspective command
camproj('perspective')
for different distortions.
Note: within the documentation, there is the viewmtx command, which allows you to output a transformation matrix corresponding to a perspective distortion of a certain angle. This is not quite what I want. I want to do things in 3D and through Matlab's OpenGL viewer. In essence, I want a command like
camproj('perspective', distortionamount)
so I can match up the amount of distortion in Matlab's viewer with the distortion from the ray tracer. If you use the viewmtx command to create the 2D projections, you will not be able to use patch or surf and keep colours and faces intact. You would essentially have to do some complicated guff to keep the depths sorted, whereas within Matlab's 3d plotter, this is already handled.
0 件のコメント
回答 (2 件)
Mike Garrity
2015 年 10 月 9 日
I think that the CameraViewAngle property is what you're looking for. You mentioned it as one of the things you know how to adjust, but I don't see it in your example.
What do the view parameters of your raytracer look like? Instead of view angle, they might have focal length. You can convert between the two using tan/arctan, as shown here .
Bjorn Gustavsson
2015 年 10 月 9 日
Matlab uses only a pinhole camera model for their 3-D rendering in the perspective mode, and pinhole cameras has strictly speaking no distortion at all. The plot you show for your ray-tracing indicates that it too uses the pinhole camera model, so there should be no distortion there either.
HTH
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!