Sei sulla pagina 1di 56

Computer Numerical Control

Lecture 12
Transformations

Dr Lina Momani
CAD and Geometry
The simplest CAD systems are 2D or 3D drafting tools. They allow
geometry to be created, stored and manipulated.
Example: A line might be stored as two points:
L→P1P2→(x1,y1; x2y2)
Or in matrix notation:

Where:  P1   x1 y1 
 L     
 P2   x 2 y 2 
The graphical representation:
P1   x1 y1 , P2   x2 y2 

07/09/2020 2
CAD and Geometry
Example: Representation of a Triangle: (in 2D ordinary coordinates)
 P1   x1 y1 
 P    P2   x 2 y 2 
 P3   x3 y 3 

Graphical representation:

07/09/2020 3
CAD and Geometry
In this format it is not easy to do matrix manipulation in 2D or 3D
(which is what we want to do). Thus we want homogeneous
coordinates.

Homogeneous Coordinates:
Presents a unified approach to describing geometric transformations.

07/09/2020 4
Homogeneous Coordinates
Assume a 2D point lies in 3D space.

Any 2D point can be represented in such a 3D space as:


P(x, y, z) = P(hx1, hy1, hz)

That is, along a ray from the origin (called homogeneous space).

07/09/2020 5
Homogeneous Coordinates
For instance, consider point P(2, 4) in ordinary coordinates. This can be considered
as:
P(4, 8, 2), where h=2; or P(6, 12, 3), where h=3; or P(2, 4, 1), where h=1 in
homogeneous space.
In general, P(m, n, h) in homogeneous space is P(m/h, n/h, 1) in ordinary coordinates.
Thus, the triangle in 2d space can be represented in homogeneous coordinates as:

 x1 y1 1
P    x 2 y2 1 
 x 3 y3 1 
Why? To help with transformations.

07/09/2020 6
Transformations
Transformation is the backbone of computer graphics, enabling us to
manipulate the shape, size, and location of the object.
It can be used to effect the following changes in a geometric object:
1. Change the location
2. Change the shape
3. Change the size
4. Rotate
5. Copy
6. Generate a surface from a line
7. Generate a solid from a surface
8. Animate the object

07/09/2020 7
Types of transformations
1. Modeling Transformation/ Object Transformation
This transformation alters the coordinate values of the object. Basic operations
are scaling, translation, rotation and combination of one or more of these
basic transformations.
Object transformation = Move (transform) an object in the 3D space.
2. Visual/ Viewing Transformation (Coordinate System Transformation)
In this transformation there is no change in either the geometry or the
coordinates of the object. A copy of the object is placed at the desired
sight, without changing the coordinate values of the object.
Coordinate system transformation = Move (transform) the coordinate system.
View the objects from the new coordinate system.
3. Rigid body transformation:
Moves the whole object, but does not deform an object.

07/09/2020 8
Examples

07/09/2020 9
Examples

07/09/2020 10
Examples
Coordinate System Transformation

07/09/2020 11
Basic Modeling/Object Transformations
Scaling, translation, and Rotation.
Other transformations, which are modification or
combination of any of the basic transformations, are
Shearing, Mirroring, Copy, etc.

Transformation can be expressed as:

[ P*]  [ P ][T ]

[P*]
where, [P ] is the new coordinates matrix
[T ] is the original coordinates matrix, or points matrix
is the transformation matrix

07/09/2020 12
Scaling

07/09/2020 13
Scaling

P ( x, y )  P * ( x*, y*)
x*  xs x , y*  ys y

Or in matrix form:

s x 0 0
P*   x * y * 1   x y 1  0 sy 
0  xs x 
ys y 1
 0 0 1

This is object scaling about the origin.

If sx = sy → → uniform scaling → → Magnify command

07/09/2020 14
Scaling
1. Uniform Scaling
For uniform scaling, the scaling transformation matrix is given as:
 In ordinary 3D coordinate system:

 s 0 0
[Ts ]  0 s 0
0 0 s 

Here, s is the scale factor

 s 0 0 0
In homogeneous 3D coordinates: 0 s 0 0
[Ts ]  
0 0 s 0
 
0 0 0 1

07/09/2020 15
Scaling
2. Non-Uniform Scaling
 Scaling transformation matrix in 3d ordinary coordinates:

sx 0 0
[Ts ]   0 sy 0 
 0 0 sz 
 In 3d Homogeneous Coordinates:

 s x 0 0 0
0 s 0 0 
[Ts ]   y 
 0 0 s z 0
 
 0 0 0 1 
where, s x , s y , s z , are the scale factors for the x, y, and z coordinates of the
object.

07/09/2020 16
:Example
If the triangle A(1, 1), B(2, 1), C(1, 3) is scaled by a factor
2, find the new coordinates of the triangle.

Solution:
Writing the points (original) matrix in homogeneous 3D
coordinates, we have

1 1 0 1
[P]  2 1 0 1
1 3 0 1

07/09/2020 17
Transformations
The scaling matrix is:
2 0 0 0
0 2 0 0 
[T s ]  
0 0 2 0
 
0 0 0 1

The new points matrix can be evaluated by the equation:


2 2 0 1
[ P*]  [ P ][T ] [P*]  4 2 0 1
2 6 0 1

07/09/2020 18
Translation Transformation

07/09/2020 19
Translation Transformation
x*  x  x
y*  y  y
Or in matrix form (homogeneous coordinates):

 1 0 0
P*   x * y * 1   x y 1  0 1 0 
  x y 1 

You can now see that homogeneous coordinates are needed for
translation transformation.
This is what the Move command does in CAD systems.

07/09/2020 20
Translation Transformation
In translation, every point on an object translates exactly the same
distance. The effect of translation transformation is that the
original coordinate values increase or decrease by the amount of
the translation along the x, y, and z-axes.
The translation transformation matrix has the form:
In 3D Homogeneous Coordinates: 1 0 0 0
0 1 0 0 
[Tt ]   
0 0 1 0
 
 x y  z 1 
where x, y , z are the values of translation in the x, y, and z direction, respectively.
For translation transformation, the matrix equation is:

[ P*]  [ P ][Tt ]

07/09/2020 21
Translation Transformation
Example: Translate the rectangle (2, 2), (2, 8), (10, 8), (10, 2) 2 units along x-
axis and 3 units along y-axis.
Solution: Using the matrix equation for translation, we have:

[ P*]  [ P ][Tt ]
Substituting the numbers, we get

2 2 0 1 1 0 0 0  4 5 0 1
2 8 0 1 0 1 0 0  4 11 0 1
[P*]   
10 8 0 1 0 0 1 0 12 11 0 1
    
10 2 0 1 2 3 0 1 12 5 0 1

Note that the resultant coordinates are equal to the original x and y values plus
the 2 and 3 units added to these values, respectively.

07/09/2020 22
Rotation
We will first consider rotation about the z-axis, which passes
through the origin (0, 0, 0), since it is the simplest transformation
for understanding the rotation transformation. Rotation about an
arbitrary axis, other than an axis passing through the origin,
requires a combination of three or more transformations.
When an object is rotated about the z-axis, all the points on the
object rotate in circular arc, and the center of the arc lies at the
origin. Similarly, rotation of an object about an arbitrary axis has
the same relationship with the axis, i.e., all the points on the
object rotate in circular arc, and the center of rotation lies at the
given point through which the axis is passing.

07/09/2020 23
Rotation
Derivation of the Rotation Transformation Matrix

Original coordinates of point P:

x  r cos  , y  r sin 

07/09/2020 24
Rotation
Derivation of the Rotation Transformation Matrix
The new coordinates:

x*  r cos(  ), y*  r sin(  )
Using the trigonometric relations, we get:

cos(   )  cos  cos  sin  sin 


sin(   )  sin  cos   cos  sin 

We get:

x*  r (cos cos  sin  sin  )  x cos  y sin 


y*  r (cos sin   sin  cos )  x sin   y cos

 cos  sin  
In matrix form:
x* y *   x y 
 sin  cos  
07/09/2020 25
Transformations
Rotation
Derivation of the Rotation Transformation Matrix
In general, the points matrix and the transformation matrix are re-written as
(For 2D objects): [In Homogeneous Coordinates]

 cos  sin  0 0
 sin  cos  0 0
x* y * 0 1   x y 0 1 
 0 0 1 0
 
 0 0 0 1
OR:

 cos  sin  0
x* y * 1   x y 1  sin  cos  0
 0 0 1

07/09/2020 26
Transformations
Rotation
Derivation of the Rotation Transformation Matrix

 For 3D geometry: Rotation about z-axis

 cos  sin  0 0
  sin  cos  0 0 
x * y* z * 1   x y z 1 
 0 0 1 0
 
 0 0 0 1

07/09/2020 27
Transformations
Rotation
Derivation of the Rotation Transformation Matrix

 Transformation matrix for rotation about y-axis:

 cos  0  sin  0
 0 1 0 0 
T R  y  
 sin  0 cos  0
 
 0 0 0 1

07/09/2020 28
Transformations
Rotation
Derivation of the Rotation Transformation Matrix
 Translation matrix for rotation about x-axis:

1 0 0 0
0 cos  sin  0 
T R  x 
0  sin  cos  0
 
0 0 0 1

07/09/2020 29
Transformations
Rotation
Derivation of the Rotation Transformation Matrix

 For use with 2D geometry:

[ P]   x y 0 1,  [ P*]   x * y * 0 1

 For use with 3D geometry:

[ P]   x y z 1,  [ P*]   x * y * z * 1

This is what the Rotate command does in CAD system.

07/09/2020 30
Transformations
Rotation of an Object about an Arbitrary Axis
Rotation of a geometric model about an arbitrary axis, other than any of
the coordinate axes, involves several rotational and translational
transformations. When we rotate an object about the origin (in
2D), we in fact rotate it about z-axis. Every point on the object
rotates along a circular path, with the center of rotation at the
origin. If we wish to rotate an object about an arbitrary axis,
which is perpendicular to the xy-plane, we will have to first
translate the axis to the origin and then rotate the model, and
finally, translate so that the axis of rotation is restored to its initial
position.

07/09/2020 31
Transformations
Rotation of an Object about an Arbitrary Axis
Thus, the rotation of an object about an arbitrary axis, involves three
steps:
Step 1: Translate the fixed axis so that it coincides with the z-axis
Step 2: Rotate the object about the axis
Step 3: Translate the fixed axis back to the original position (reverse
translation)

Note: When the fixed axis is translated, the object is also translated. The
axis and the object go through all the transformations
simultaneously.

07/09/2020 32
Transformations
Rotation of an Object about an Arbitrary Axis
Example:
Rotate the rectangle (0, 0), (2, 0), (2, 2), (0, 2) shown
below, 30o ccw about its centroid and find the new
coordinates of the rectangle.

07/09/2020 33
Transformations
Rotation of an Object about an Arbitrary Axis

07/09/2020 34
Transformations
Rotation of an Object about an Arbitrary Axis

07/09/2020 35
Transformations
Rotation of an Object about an Arbitrary Axis

07/09/2020 36
Transformations
Rotation about an Arbitrary Point (in xy-plane)
In order to rotate an object about a fixed point, the point is first moved
(translated) to the origin. Then, the object is rotated around the origin.
Finally, it is translated back so that the fixed point is restored to its original
position. For rotation of an object about an arbitrary point, the sequence of
the required transformation matrices and the condensed matrix is given as:

[T cond ]  [Tt ][ T r ][ T  t ]
OR:

1 0 0 0  cos sin 0 0 1 0 0 0
0 1 0 0  sin cos 0 0 0 1 0 0
[Tcond ]  
0 0 1 0  0 0 1 0 0 0 1 0
   
 x  y 0 1  0 0 0 1  x y 0 1
where is the angle of rotation and the point (x, y) lies in the xy-plane.

07/09/2020 37
Transformations
Rotation about an Arbitrary Point (in xy-plane)
Solution: We first translate the point (3, 2) to the origin, then rotate the rectangle about the
origin, and finally, translate back so that the original point is restores to its original
position (3, 2). The new coordinates of the rectangle are found as follows:

[ P*]  [ P][Tt ][Tr ][Tt ] 


1 1 0 1  1 0 0 0 0.866 0.5 0 0 1 0 0 0
2 1 0 1  0 1 0 0   0.5 0.866 0 0 0 1 0 0
 
2 3 0 1  0 0 1 0  0 0 1 0  0 0 1 0
    
1 3 0 1  3  2 0 1  0 0 0 1  3 2 0 1
1.77 0.13 0 1
0.77 1.87 0 1

1.63 2.37 0 1
 
 2.63 0.63 0 1

These are the new coordinates of the rectangle after the rotation.

07/09/2020 38
Transformations
Mirroring (Reflection)
In modeling operations, one frequently used operation is mirroring an object.
Mirroring is a convenient method used for copying an object while
preserving its features. The mirror transformation is a special case of a
negative scaling, as will be explained below.
Let us say, we want to mirror the point A(2, 2) about the x-axis (i.e., xz-plane). The point
matrix [P*]=[2 -2] can be obtained with the matrix transformation given below:

07/09/2020 39
Transformations
Mirroring (Reflection)

1 0 0 0
0  1 0 0
[ P*]   2 2 0 1    2  2 0 1
0 0 1 0
 
0 0 0 1

The transformation matrix above is a special case of non-uniform scaling with


sx=1 and sy=-1.

07/09/2020 40
Transformations
Mirroring (Reflection)
Transformation Matrix for Mirroring about x-axis:

1 0 0 0
0  1 0 0
Tm  x 
0 0 1 0
 
0 0 0 1
Transformation Matrix for Mirroring about y-axis:

 1 0 0 0
0 1 0 0
Tm  y 
0 0 1 0
 
0 0 0 1

07/09/2020 41
Transformations
Mirroring about an Arbitrary Plane
If mirroring is required about an arbitrary plane, other than one defined by the
coordinate axes, translation and/or rotation can be used to align the given
plane with one of the coordinate planes. After mirroring, translation or
rotation must be done in reverse order to restore the original geometry of
the axis.
We will use the figure shown below, to illustrate the procedure for mirroring an
object about an arbitrary plane. We will mirror the given rectangle about
a plane passing through the line AB and perpendicular to xy-plane.

07/09/2020 42
Transformations
Mirroring about an Arbitrary Plane

07/09/2020 43
Transformations
Mirroring about an Arbitrary Plane
It should be noted that in each of the
transformations, the plane and the rectangle
have a fixed relationship, i.e., when we move
the plane (or line AB), the rectangle also
moves with it.
Note: We are using line AB to represent the plane,
which passes through it. Mirroring can be
done only about a plane, and not about a line.

07/09/2020 44
Transformations
Mirroring about an Arbitrary Plane
Procedure for mirroring the rectangle about the plane:
Step 1: Translate the line AB (i.e., the plane) such that it passes through the origin, as
shown by the dashed line.
Step 2: Next, rotate the line about the origin (or the z-axis) such that it coincides with x
or y axes (we will use the x-axis).
Step 3: Mirror the rectangle about the x-axis.
Step 4: Rotate the line back to its original orientation.
Step 5: Translate the line back to its original position
The new points matrix, in terms of the original points matrix and the five transformation
matrices is given as:
[P*] = [P][Tt][Tr][Tm][T-r][T-t]
Where, the subscripts t, r, and m represent the translation, rotation, and mirror operations,
respectively.
Note: A negative sign is used in the subscripts to indicate a reverse transformation.

07/09/2020 45
Transformations
Coordinate System Transformation
Coordinate frame moves to a new location.

07/09/2020 46
Coordinate System Transformation

P  x y z
The origin has been translated (moved) from (0, 0, 0) to (a, b, c)
Or:
For coordinate system:
x   a , y  b, z   c
For the object:
x  a , y  b, z  c
[ P*]  [ P ][T ]

1 0 0 0
 0 1 0 0
Tt  
 0 0 1 0
 
 a  b  c 1

07/09/2020 47
Transformations
Coordinate System Transformation

 [ P*]   x  a y  b z  c 1

Note: The sign in the T matrix need to be changed

07/09/2020 48
Transformations
Example: Coordinate Transformation
If the coordinate system has been rotated about z-axis by -30 o, then
translated to [a b c], what is the coordinates of the point
[x y z] in the new coordinate system?

07/09/2020 49
Transformations
Example: Coordinate Transformation

Solution:

 cos 30 o sin 30o 0 0  1 0 0 0


 
 sin 30 o
cos 30o 0 0  0 1 0 0
[ P*]   x y z 1  
 0 0 1 0  0 0 1 0 
  
 0 0 0 1  a  b  c 1
  x * y * z * 1

07/09/2020 50
Transformations
Coordinate system transformation-Viewing

We need to understand that our CAD model is defined


within a world or global coordinate system (WCS),
usually 3D, but we view it through a flat screen which
will have its own device coordinate system (DCS).

This is usually done through a neutral stage or a virtual or


normalized coordinate system (NCS). Thus we map as
follows:

07/09/2020 51
Transformations
Coordinate system transformation-Viewing

07/09/2020 52
Transformations
Coordinate system transformation-Viewing
We will not see all the component at one time. Thus we need
to define a window.

07/09/2020 53
Transformations
Coordinate system transformation-Viewing

07/09/2020 54
Transformations
Coordinate system transformation-Viewing
We can map this to the viewport by:

xv  xv min x w  x w min

xv max  xv min x w max  x w min
And
y v  y v min y w  y w min

y v max  y v min y w max  y w min

07/09/2020 55
Transformations
Coordinate system transformation-Viewing
When the Aspect Ratio (AR) of both is equal no distortion
(scaling occurs).

x max  x min
AR 
y max  y min

By mapping a smaller window on the viewport, we can get a


“zooming effect”.

07/09/2020 56

Potrebbero piacerti anche