Presentation is loading. Please wait.

Presentation is loading. Please wait.

Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab 9: 3D & Projections Basics.

Similar presentations


Presentation on theme: "Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab 9: 3D & Projections Basics."— Presentation transcript:

1 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab 9: 3D & Projections Basics

2 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Tutorial contents Introduction to Projections Basic Concepts Projection Types and Matrix Orthographic Perspective Solve Examples

3 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Introduction to Projections We live in a 3D world but the screen where the rendered objects appear is a 2D space. Thus, we need to convert somehow our 3D world to 2D. The operation which does this conversion is called projection. When Programming we focus on 2 main types of projections Orthographic – casts parallel rays of light from the scene to projection plane Perspective – casts angled rays of light from the scene to projection plane Perspective projection generates a realistic effect since our vision works the same way

4 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Basic Concepts camera coordinate system viewport coordinate system device/screen coordinate system

5 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Projection Type - Orthographic r 0 – a vector pointing from world origin to Projection plane origin r – object point vector (from world origin to P) P – object point P’ – projected point U – view direction Z’ – distance from P to P’ along U r’ – P’ coordinates in word CS u 1,u 2 – projected image main axis x’,y’ – P’ coordinate in image CS P P’

6 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Projection Matrix - Orthographic When U is Orthogonal to u 1 and u 2 we can simplify the equations to get the matrix If U is not orthogonal (like in oblique parallel) we must use the equations given in the lecture

7 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Projection Type - Perspective r v – eye coordinates Other vectors defined above

8 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Projection Matrix By selecting r v =r 0 +du We can use the matrix form We can see that d causes a scaling effect

9 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Solve Examples Given a cube in 3D space x = [0 1 1 0 0 0 1 1 0 0 1 1 1 1 0 0]-0.5; y = [0 0 1 1 0 0 0 1 1 0 0 0 1 1 1 1]-0.5; z = [0 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0]-0.5; We wish to find the isometric projection so we can see the cube in a 2D plane

10 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Solve Examples From the lectures – Isometric projection The rotation around y axis is φ=45 The rotation around x axis is θ=35.2

11 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Solve Examples Plot the 3D space for visualization %plot cube in 3D space Figureh=figure('NumberTitle','off','Name','3D space',... 'Position',[200 300 500 500]); line(x,y,z); view(3); daspect([1,1,1]); set(gca,'XLabel',text('string','X'),'YLabel',text('string','Y'),'ZLabel',text('string','Z'));

12 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Solve Examples Task: Define the projection matrix

13 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Solve Examples Solution: Set the projection matrix MIsometric=[cosd(phi) 0 sind(phi) 0; sind(teta)*sind(phi) cosd(teta) - sind(teta)*cosd(phi) 0;... -sind(phi)*cosd(teta) sind(teta) cosd(teta)*cosd(phi) 0;0 0 0 1]; Task Convert to homogeneous coordinates [m,n] = size(x); x4d = [x(:),y(:),z(:),ones(m*n,1)]'; %homographic coordinates

14 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Solve Examples Solution Convert to homogeneous coordinates [m,n] = size(x); x4d = [x(:),y(:),z(:),ones(m*n,1)]'; %homographic coordinates

15 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Solve Examples Task Calculate the points location in 2D and plot

16 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Solve Examples Solution Calculate the points location in 2D and plot %project to 2D x2d = MIsometric*x4d; x2 = zeros(m,n); y2 = zeros(m,n); x2(:) = x2d(1,:); y2(:) = x2d(2,:); Figureh=figure('NumberTitle','off','Name','2D space',... 'Position',[800 300 500 500]); plot(x2,y2) set(gca,'XLim',[-1 1],'YLim',[-1 1],'XLabel',text('string','u1'),'YLabel',text('string','u2'));

17 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Solve Examples Output – Question : Why is there a difference?

18 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Solve Examples Answer: which view is MATLAB default? Probably not isometric

19 Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Notes and References This is not (!!!) the way to use projections in MATLAB This is just an illustrated example of how projections work. Mathworks Documentation Center - http://www.mathworks.com/help/documentation-center.html http://www.mathworks.com/help/documentation-center.html


Download ppt "Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab 9: 3D & Projections Basics."

Similar presentations


Ads by Google