Download Document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Mechanical engineering wikipedia , lookup

Transcript
Lab 8:
Transformations Hierarchy
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Tutorial contents
This section explains the Parent child
relationship
Example – folding a cube
 Parent-Child Relations
 Hierarchy of transformations

Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Example – Folding Cube


We will demonstrate and understand the concept of
transformation hierarchy using a coded example
Run the code in the file “Hierarchy.m”
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Parent-Child Relationship

Using the tools we learned until today we can solve
the above problem – for every patch






Draw a patch around (0,0)
Rotate it by 90 deg around the relevant axis
Translate to final location
This will create a large number of transformations
We avoid this by using hierarchy
Any transformation performed on a parent is also
performed on its children.
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Parent-Child Relationship

By Defining this
hierarchy we need to
define only 2 translation
matrix –



Move 1 in x direction
Move 1 in y direction
The matrix multiplication
accumulates due to the
hierarchy
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Parent-Child Relationship

The folding process occurs using the same logic – two
transformations are needed


Rotate around y by -90 deg and then translate along x by 1
Rotate around x by 90 and the translate along y by 1
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Hierarchy of transformations
Code Analysis :
 Hierarchy definition – happens before transformations were
introduced
% Define the object hierarchy
t(1) = hgtransform;
t(2) = hgtransform('parent',t(1));
t(3) = hgtransform('parent',t(2));
t(4) = hgtransform('parent',t(3));
t(5) = hgtransform('parent',t(4));
t(6) = hgtransform('parent',t(5));
 Data
definition – Single patch and single text data around (0,0,0)
% Patch data
X = [0 0 1 1];
Y = [0 1 1 0];
Z = [0 0 0 0];
% Text data
Xtext = .5;
Ytext = .5;
Ztext = -.15;
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Hierarchy of transformations
Code Analysis :
 Pairing objects with the hierarchy
% Corresponding pairs of objects (patch and text)
% are parented into the object hierarchy
p(1) = patch('FaceColor','red','Parent',t(1));
txt(1) = text('String','Bottom','Parent',t(1));
p(2) = patch('FaceColor','green','Parent',t(2));
txt(2) = text('String','Right','Parent',t(2));
p(3) = patch('FaceColor','blue','Parent',t(3));
txt(3) = text('String','Back','Color','white','Parent',t(3));
p(4) = patch('FaceColor','yellow','Parent',t(4));
txt(4) = text('String','Top','Parent',t(4));
p(5) = patch('FaceColor','cyan','Parent',t(5));
txt(5) = text('String','Left','Parent',t(5));
p(6) = patch('FaceColor','magenta','Parent',t(6));
txt(6) = text('String','Front','Parent',t(6));
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Hierarchy of transformations
Code Analysis :
 Assign data to graphic objects
% All the patch objects use the same x, y, and z data
set(p,'XData',X,'YData',Y,'ZData',Z)
% Set the position and alignment of the text objects
set(txt,'Position',[Xtext Ytext Ztext],...
'HorizontalAlignment','center',...
'VerticalAlignment','middle')
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Hierarchy of transformations
Code Analysis :
 Assign
translation to the hierarchy objects and draw for unfolded view
% Set up initial translation transforms
% Translate 1 unit in x
Tx = makehgtform('translate',[1 0 0]);
% Translate 1 unit in y
Ty = makehgtform('translate',[0 1 0]);
% Translate the unit squares to the desired locations
% The drawnow and pause commands display
% the objects after each translation
set(t(2),'Matrix',Tx);
set(t(3),'Matrix',Ty);
set(t(4),'Matrix',Tx);
set(t(5),'Matrix',Ty);
set(t(6),'Matrix',Tx);
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Hierarchy of transformations
Code Analysis :
 Assign
rotation and translation to the hierarchy objects and draw for folded
view
% Specify rotation angle (pi/2 radians = 90 degrees)
fold = pi/2;
% Rotate -y, translate x
Ry = makehgtform('yrotate',-fold);
RyTx = Tx*Ry;
% Rotate x, translate y
Rx = makehgtform('xrotate',fold);
RxTy = Ty*Rx;
% Set the transforms
% Draw after each group transform and pause
set(t(6),'Matrix',RyTx);
set(t(5),'Matrix',RxTy);
set(t(4),'Matrix',RyTx);
set(t(3),'Matrix',RxTy);
set(t(2),'Matrix',RyTx);
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
Final Notes


There are simpler ways to draw a cube – this was
used to demonstrate the hierarchy principles
Hierarchy is very useful when creating a complex
scenes
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering
References
The code example and image was taken from link
Technion - Israel Institute of Technology
Faculty of Mechanical Engineering
Laboratory for CAD & Lifecycle Engineering