technion - israel institute of technology faculty of mechanical engineering laboratory for cad &...
TRANSCRIPT
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Lab 9: 3D & ProjectionsLab 9: 3D & ProjectionsBasicsBasics
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Tutorial contents
Introduction to ProjectionsBasic ConceptsProjection Types and Matrix
OrthographicPerspective
Solve Examples
Technion - Israel Institute of TechnologyFaculty 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
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Basic Concepts
camera coordinatesystem
viewport coordinatesystem
device/screencoordinate system
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Projection Type - Orthographic
r0 – 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 u1,u2 – projected image main axis
x’,y’ – P’ coordinate in image CS
P P’
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Projection Matrix - Orthographic
When U is Orthogonal to u1 and u2 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
1
2
0
0
0
0 0 0 1 0 0 0 1
x
yOrthographic
z
u r
u I rM
u r
0 2 0 1 0 1 2
1 2 2 1 1 2
( )( ) ( )( ) ( )( )' , ' , '
( ) ( ) ( )
r r u u r r u u r r u uX Y Z
u u u u u u u u u
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Projection Type - Perspective
rv – eye coordinates
Other vectors defined above
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Projection Matrix
By selecting rv=r0+du
We can use the matrix form
We can see that d causes a scaling effect
1
2
0 0 0 0
0 0 0 0
0 0 0 0
0 0 1 0 0 0 1 0 0 0 1
x
yPerspective
z
d u r
d u I rM
d u r
d
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Solve Examples
Given a cube in 3D spacex = [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
Technion - Israel Institute of TechnologyFaculty 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
Technion - Israel Institute of TechnologyFaculty 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'));
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Solve Examples
Task:
Define the projection matrix
Technion - Israel Institute of TechnologyFaculty 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
Technion - Israel Institute of TechnologyFaculty 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
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Solve Examples
Task
Calculate the points location in 2D and plot
Technion - Israel Institute of TechnologyFaculty 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'));
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Solve Examples
Output – Question : Why is there a difference?
Technion - Israel Institute of TechnologyFaculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Solve Examples
Answer: which view is MATLAB default? Probably not isometric
Technion - Israel Institute of TechnologyFaculty 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