Presentation is loading. Please wait.

Presentation is loading. Please wait.

Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab.

Similar presentations


Presentation on theme: "Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab."— Presentation transcript:

1 Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab 6 : Transformations

2 Written by: Itzik Ben Shabat Tutorial contents Introduction to Transformations Matrix Representation Translation Rotation Scaling Transformation Order Dry Exercise Transform coordinate systems Dry Example Implementation of Dry Exercise (the straightforward way) MATLAB transformations implementation (better way) Final Notes Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

3 Written by: Itzik Ben Shabat Introduction to Transformations In this course we work with 2 types of transformations Moving objects in relation to a coordinate system Static objects in relations to different coordinate systems Essentially these two types are the same, however mathematically the order of mathematical operations is different In this section we will discuss moving objects in relation to a coordinate system transformations Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

4 Written by: Itzik Ben Shabat Introduction to Transformations Formal Definition: The operation of changing position, orientation or size of an object is a basic transformation A transformation is applied by multiplying a vertex in the world by an appropriate transformation matrix. V new – new vertex location V old – old vertex location M – Transformation matrix In order that the multiplication will be correct for all transformation we use Homogenous Coordinates. Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

5 Written by: Itzik Ben Shabat Introduction to Transformations In order that the multiplication will be correct for all transformation we use Homogenous Coordinates. Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

6 Written by: Itzik Ben Shabat Translate – move a point along the main axes If we wish to translate point p Matrix Representation - Translate Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering p T p new X Y Z

7 Written by: Itzik Ben Shabat Matrix Representation - Rotation Rotate a point around one of the main axes in a given angle f rotation (θ) If we wish to rotate point p around z axis Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering p p new X Y Z θ

8 Written by: Itzik Ben Shabat Matrix Representation - Scaling Scale each axis by the corresponding scale factor Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

9 Written by: Itzik Ben Shabat Rotation Translation Scale Matrix Representation - Summary Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

10 Written by: Itzik Ben Shabat Transformation Order Questions: we wish to move and rotate a point What happens if we first translate it and then rotate it? What happens if we first rotate it and then translate it? Hint (apply these transformations on the origin (0,0) ) Which is the right order? Answer: It depends what we wish to accomplish (usually we first rotate and then translate) Mathematically we perform matrix multiplication from right to left. Therefore the rightmost matrix will apply first S (scaling) will apply first. R (rotation) will apply next and T (Translation will apply last) Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

11 Written by: Itzik Ben Shabat Dry Exercise Transform a Square with parameters width =1 Height=1 Center at (0,0) Into a rectangle with the following parameters Width=0.5 Height=2 Center at (2,2) Rotated around Z axis by 45 deg See image for desired transformation Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

12 Written by: Itzik Ben Shabat Straightforward Implementation We wish to transform the blue square into the red rectangle Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

13 Written by: Itzik Ben Shabat Solve Question 2 Questions Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

14 Written by: Itzik Ben Shabat Transform coordinate systems In this course we work with 2 types of transformations Moving objects in relation to a coordinate system Static objects in relations to different coordinate systems In this section we will discuss static objects in relations to different coordinate systems Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

15 Written by: Itzik Ben Shabat Transform coordinate systems Given a point P in Coordinate system A (p xA,p yA ), we wish to express this point in coordinate system B which is translated by (T x,T y ) and rotated by θ around z axis (see image below) Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering A P θ XAXA YAYA YBYB XBXB B (T x,T y ) Image notes: The blue vectors are known θ is known We are looking for the red vector In terms of CS B

16 Written by: Itzik Ben Shabat Transform coordinate systems The transformations are made on the destination CS – i.e. what are the operations that must be made on CS B so it will merge with A ? Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering A P θ XAXA YAYA YBYB XBXB B (T x,T y )

17 Written by: Itzik Ben Shabat Consider the example of T x =T y =2 p x =p y =3 Θ=45 Using the equations from previous slides we get Dry example Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering A(0,0) θ=45 XAXA YAYA YBYB XBXB B(2,2) P(3,3)

18 Written by: Itzik Ben Shabat Solve Question 1 Question Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

19 Written by: Itzik Ben Shabat Implementation of Dry Exercise Using MATLAB Transform a Square with parameters width =1 Height=1 Center at (0,0) Into a rectangle with the following parameters Width=0.5 Height=2 Center at (2,2) Rotated around Z axis by 45 deg Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

20 Written by: Itzik Ben Shabat Straightforward Implementation We wish to transform the blue square into the red rectangle Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

21 Written by: Itzik Ben Shabat Implementation of Dry Exercise Solution outline Calculate square vertices and initialize parameters Plot square Convert vertices to homogeneous coordinates Matrix multiplication (notice ordering) plot rectangle Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

22 Written by: Itzik Ben Shabat Straightforward Implementation Open a new.m file and Create a function called main6 which opens a new figure and axis in it and calls the drawingCB function [ ] = main6( ) %main6 Demonstrates the use of Basic Transformations using matrix %multiplications clear all; close all; clc; %code %Open figure and create axis Figureh=figure('NumberTitle','off','Name','Transformation Example',... 'Position',[200 200 500 500]); %bg is set to red so we know that we can only see the axes Axesh=axes('XLim',[-3 3],'YLim',[-3,3]); DrawingCB( ); end Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

23 Written by: Itzik Ben Shabat Straightforward Implementation Create a function called drawingCB which performs as the solution outline demonstrated Calculate square vertices and initialize parameters %Initializing Variables square=[-0.5 -0.5;-0.5 0.5;0.5 0.5;0.5 -0.5]; %represented by its vertices Sx=0.5; Sy=2; Tx=2; Ty=2; teta=45; Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

24 Written by: Itzik Ben Shabat Straightforward Implementation Plot square line([square(:,1);square(1,1)],[square(:,2);square(1,2)],'Color','b','LineWidth',3); Convert to homogeneous coordinates Hsquare=[square, ones(size(square,1),1)]; Generate Matrix S=[Sx 0 0;0 Sy 0 ;0 0 1]; T=[1 0 Tx;0 1 Ty; 0 0 1]; R=[cos(teta) -sin(teta) 0;sin(teta) cos(teta) 0; 0 0 1]; Question: What is the right matrix order of multiplication? Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

25 Written by: Itzik Ben Shabat Straightforward Implementation Answer: scale first, then rotate, then translate. %Calculate rectangle vertices Hrect=T*R*S*Hsquare'; Hrect=Hrect'; line([Hrect(:,1);Hrect(1,1)],[Hrect(:,2);Hrect(1,2)],'Color','r','LineWidth',3); grid on; Result: Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

26 Written by: Itzik Ben Shabat Straightforward Implementation Lets explore what are the results if we used a different order: Question: Can you guess which order is represented in green and which in yellow ? Hint : what is special about the yellow? Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

27 Written by: Itzik Ben Shabat Straightforward Implementation Answer: green – R*S*T Yellow - S*R*T (the scaling after rotation creates the distortion) Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

28 Written by: Itzik Ben Shabat MATALB Implementation – The right way In previous section we explored the implementation of transformations using matrix multiplication In MATLAB there are built in routines that make our lives easier ( no need to define the entire matrix and multiply it or transform to homogeneous coordinates) Makehgtform Create transform matrices for translation, scaling, and rotation of graphics objects M = makehgtform('translate',[tx ty tz]) - Translation M = makehgtform('scale',s) - Uniform scale M = makehgtform('scale',[sx,sy,sz]) - nonuniform scale M = makehgtform('xrotate',t) - rotate around x axis – t in radians M = makehgtform('yrotate',t) - rotate around y axis – t in radians M = makehgtform('zrotate',t) - rotate around z axis – t in radians Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

29 Written by: Itzik Ben Shabat MATALAB Transformation implementation h = hgtransform('PropertyName',propertyvalue,...) We will mainly use h = hgtransform(‘Parent’,ax,‘matrix’,M); Executes the transformation defined by the matrix M on all children (graphic objects) of ax. Ax can be an axes, hggroup or hgtransform objects For more information on hgtransform properties visit this linklink Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

30 Written by: Itzik Ben Shabat MATALAB Transformation implementation Implement in previous section example Guidance: Plot 2 squares and save their handles Calculate matrix Set hgtform object to parent one of the squares Refresh the figure using drawnow Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

31 Written by: Itzik Ben Shabat MATALAB Transformation implementation Your Final Drawing function should look something like this Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

32 Written by: Itzik Ben Shabat Final notes We recommend that you use this code to experiment and further investigate the nature of transformations Do not use the straightforward implementation for standard transformation in future codes (it is only an example to help you understand the principles) It is important to understand by now the object handles principles (figure,axis, graphic objects, groups etc.) It is important to understand child-parent relations between objects (visit link) – more on this in hierarchy tutoriallink Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

33 Written by: Itzik Ben Shabat Sources and Refrences Mathworks Documentation Center - http://www.mathworks.com/help/documentation-center.html http://www.mathworks.com/help/documentation-center.html Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering


Download ppt "Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab."

Similar presentations


Ads by Google