Chapter4Transformations_第1页
Chapter4Transformations_第2页
Chapter4Transformations_第3页
Chapter4Transformations_第4页
Chapter4Transformations_第5页
已阅读5页,还剩51页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Chapter4 Transformations图形变换图形变换 4.1 Review of Vectors矢量回顾矢量回顾 4.2 Geometric projection Transformations 几何变换(平移变换、放缩变换、旋转变换、错切变换、几何变换(平移变换、放缩变换、旋转变换、错切变换、对称变换、组合变换、几何变换举例对称变换、组合变换、几何变换举例 4.3 2D graphics display process二维图形的显示流程二维图形的显示流程 4.4 the window to viewport transformation窗口到视区的窗口到视区的变换窗口到视区的变换

2、变换窗口到视区的变换 4.5 The Elementary 3D Transformations三维几何变换三维几何变换4.1 4.1 Review of Vectors矢量回顾矢量回顾vectors are objects having length and directiona vector is represented a list of its components: w = (w1, w2, . . . , wn)设有两个矢量U=ux, uy, uz,V=vx, vy, vzsum of two vectors矢量和:U+V=ux+vx, uy+vy, uz+vzscaling a

3、vector矢量数积:KU=K ux, K uy, K uz4.1.1 Operations with vectors矢量基本运算矢量基本运算Example: if a = (2, 5, 6) and b = (-2, 7, 1), we can form the two vectors:a + b = (0, 12, 7)6 a = (12, 30, 36)vector dot product矢量的点积:UV=ux vx + uy vy + uz vz=dThe dot product produces a scalar向量的点积是标量Example:The dot product of (

4、2, 3, 1) and (0, 4, -1) is 11.(2, 2, 2, 2) (4, 1, 2, 1.1) = 16.2. (1, 0, 1, 0, 1) (0, 1, 0, 1, 0) = 0. (169, 0, 43) (0, 375.3, 0) = 0.Properties of the Dot Product点积的性质点积的性质 (1)Symmetry(对称性):the dot product iscommutative(点积可交换):a b = b a (2)Linearity(线性): dot product can be assigned (点积可分配): (a + c)

5、 b = a b + c b (sa) b = s (a b) (3)|b|2 = b b:the dot product of a vector with itself yields the square of the length of the vector向量自身的点击等于其长度的平方。Example : 化简化简Simplification of |a - b|2. By the third property: | a - b |2 = (a - b) (a - b). Using linearity: (a - b) (a - b)=a (a - b) - b (a - b). Us

6、ing symmetry and linearity to simplify a (a - b) - b (a - b).= a a - 2a b + b b. Using the third property above to obtain a a - 2a b + b b = | a |2 - 2 a b + | b |2 the desired result:| a + b |2 = | a |2 + 2a b + | b |24.1.2 Magnitude of a vector矢量度量和单位矢量矢量度量和单位矢量 | U | = UU= ux2 + uy2 + uz2 be defi

7、ned the magnitude(length or size) of vector Uunit vectors单位矢量:the length equal to one长度为1的矢量。For example, the magnitude of w = (4, -2) is 20Note that if w is the vector from point A to point B, then |w| will be the distance from A to Bnormalizing a vector归一化归一化矢量矢量:For example, if a = (3, -4), then

8、| a | = 5 and the normalized version is a = ( 3/5 , -4/5 ).4.1.3 The Angle Between Two Vectorss矢量间的夹角矢量间的夹角 any two vectors b and c lie at angles ?b, and ?cb = ( |b| cos ?b , |b| sin ?b)c = ( |c| cos ?c , |c| sin ?c).Thus their dot product isso we have, for any two vectors b and c:b c = |b| |c| cos(

9、) ,where is the angle from b to c.cos= (b v) / (| b | | c |)=b c 两向量夹角的余弦等于两向量归一化后的点积。 Ex. Find the angle between b = (3, 4) and c = (5, 2).Solution: Form |b| = 5 and |c| = 5.385so that b = (3 / 5, 4 / 5) and c = (.9285, .3714). The dot product:b c = .85422 = cos(), so that = 31.32604.1.4 The Sign o

10、f bc, and Perpendicularity bc的符号和正交性的符号和正交性 Recall that cos() is positive if | is less than 90o, zero if | equals 90o, and negative if | exceeds 90o. therefore observe immediately that two vectors (of any nonzero length) areless than 90o apart if b c 0夹角小于90度;exactly 90o apart if b c = 0;夹角等于90度more

11、 than 90o apart if b c 0夹角大于90度 Definitionding定义定义:Vectors b b and c c are perpendicular(orthogonal and normal正交) if b c b c = 0.The most familiar examples of orthogonal vectors are those aimed along the axes of 2D and 3D coordinatesystems, as shown in Figure.最常见的正交例子是沿坐标轴方向的矢量,如图: Definition: The s

12、tandard unit vectors in 3D have components:三维空间的标准单位矢量有以下分量组成: i = (1, 0, 0), j = (0, 1, 0), and k = (0, 0, 1).Using these definitions any 3D vector such as (a, b, c) can be written in the alternative form有了标准单位向量的定义,就可以把任意一个3维矢量写成另一种形式:(a, b, c) = a i + b j + c kso it simplifies various pencil-and-

13、paper calculations.因此,可以简化许多纸笔计算。4.1.5 The Cross Product of Two Vectors两个矢量的叉积两个矢量的叉积 The cross product (also called the vector product矢量积) of two vectors is another vector。 It has many useful properties, but the one we use most often is that it is perpendicular to both of the given vectors. 叉积与原来两矢

14、量正交。 The cross product is defined only for three-dimensional vectors.叉积只对三维矢量有意义。Definition of a b:a b = i j k ax ay azbx by bz =ayvz - byazbxaz - axbzaxby - bxay algebraic properties of the cross product点积的代数性质(1) i j = k,j k = I,k i = j(2) a b= b a (antisymmetry反对称性)(3) a (b + c) = a b + a c (line

15、arity线性) (sa) b = s(a b)(4) a (a b) = b (a b) =0(orthogonality 正交性)Geometric Interpretation of the Cross Product叉积的几何解释叉积的几何解释 (1)a b is perpendicular (orthogonal) to both a and b.叉积与两矢量垂直; (2) The length of a b equals the area of the parallelogram determined by a and b其长度等于由a、b决定的平行四边形面积. This area

16、 is equal to|a b|=|a|b|sin ()where is the angle between a and b,4.1.6The homogeneous representation of a point and a vector点和向量的齐次坐标表示点和向量的齐次坐标表示vector v = v1a + v2 b + v3 cfour coefficients (v1, v2, v3, 0)point P = p1a + p2b + p3c + ?four coefficients (p1, p2, p3, 1).Here the row matrix captures th

17、e nature of the coordinate frame,行矩阵表示坐标框架。the column vector captures therepresentation of the specific object of interest.列矩阵表示感兴趣的特定对象4.2 Transformations of Objects几何变换几何变换4.2.1 平移变换Translation.dxdydxdyx = x + dxy= y + dy将点P(x, y)沿x轴和y轴方向分别平移距离dx,dy得到 P(x, y)。PP矢量形式为:P= P + Tdyydxxdydxyxyx4.2.2 ro

18、tation旋转变换旋转变换将点P(x, y)绕原点转角度得到 P1(x1, y1)。逆时针为正,顺时针为负。x1 = Lcos(+)y1 = Lsin(+)x = Lcosy = LsinLP(x,y)P1(x1,y1)XYOrotation of a figure(P(x, y) about a given point through some angle cossinsincos11yxyxx1 = Lcos(+)=Lcoscos-Lsinsin=x cos-y siny1 = Lsin(+)=Lsincos+Lcossin=y cos+x sin其矩阵表示:4.2.3 4.2.3 Sc

19、aling放缩变换放缩变换x1 = sx xy1 = sy y yxssyxyx0011 将点P(x, y)沿x轴和y轴方向分别缩放sx和sy倍得到 P1(x1, y1)。矩阵表示:PP1放缩变换是相对于坐标原点,它不仅改变物体的大小也改变了它与原点的距离。4.2.4 对称变换对称变换 reflection transformation (x, y)(x, -y)(x, y)(-x, y)100111yxyx100111yxyx用来求一个图形关于某一镜面的反射图形(即镜像)。关于y轴的对称变换关于x轴的对称变换.5Shearing错切变换错切变换shear along x,x轴

20、向错切dx1 = x+d = x+ytgy1 = y 10111tgyxyx 保持图形上各点的某一坐标值不变,而另一坐标值关于该坐标值呈线性变换。 shear “along y” y轴向错切dx1 = xy1 = y +d = y + xtg10111tgyxyx4.2.6 4.2.6 homogeneous representation齐次坐标齐次坐标10100011111dydxyxyx平移变换Translation1000cossin0sincos1111yxyx旋转变换rotation1000100011111yxyx关于x轴对称变换reflection transformation

21、on x axis 1000100011111yxyx关于y轴对称变换reflection transformation on y axis x轴向错切轴向错切shear “along x”,100010011111tgyxyx y轴向错切轴向错切shear “along y”,100010011111tgyxyx 放缩变换放缩变换Scaling10000001111yxssyxyxsCBAsttfdcebaTyx子阵子阵A完成二维图形的对称、旋转、放缩和错切功能完成二维图形的对称、旋转、放缩和错切功能子阵子阵C完成二维图形的平移功能完成二维图形的平移功能S为全比例放缩因子为全比例放缩因子sy

22、xsyx000100011114.2.7 compound transformation4.2.7 compound transformation组合变换组合变换 EX.Rotating About an Arbitrary Point绕任一点逆时针方向旋转therefore consists of the following three elementary transformations,需要以下三种基本变换。 usually an application requires that we build a compound transformation out of several ele

23、mentary ones.通常的应用都要求几种基本变化构成的组合变换。PPPP”PP”(1)Translate point P平移(2)Rotate about the origin through angle ;绕原点转(3)Translate P back平移回来设图形设图形P顶点坐标为:顶点坐标为:P0(x0, y0), P1(x1, y1), P2(x2, y2), P3(x3, y3) ,旋转中心为旋转中心为(Vx, Vy)。(1)Translate:旋转中心旋转中心(Vx,Vy)坐标原点坐标原点 图形图形P P),(321032101V0100011111VyVxTPVyxyyyy

24、xxxxP(2)Rotate:绕原点逆时针方向旋转绕原点逆时针方向旋转角角 P P”)(1000cossin0sincos RTPPP(3)Translate:旋转中心由坐标原点旋转中心由坐标原点原来位置原来位置 图形图形P” P”)V,V( 1VV010001 yxTPyxPPP” = PT(-Vx, -Vy)TR()T(Vx, Vy)1111010nnyyyxxxP其中,其中,(Vx, Vy)为旋转中心的坐标为旋转中心的坐标T(-Vx, -Vy)TR()T(Vx,V y)= 图形关于任意直线的对称变换图形关于任意直线的对称变换 P0(x0, y0)P1(x1, y1)P(x, y)PPPP

25、”P”P(3)P(4)P(3)1)平移变换T(x, y)使对称轴l过原点;2)旋转变换TR()使之与x轴重合;3) 对称变换T1,求图形关于x轴的对称图形;4)旋转变换T TR(R() ;5)平移变换T T(-x, -y)(-x, -y)使对称轴l回原位置。P0P1PP(5)P(4)P(5) = PT(-x, -y)TR()T1TR()T(x, y)1000100011T1111010nnyyyxxxP,其中,其中,cos= a / csin= b / ca = x1 - x0, b = y1 - y0c2 = a2 + b2例:程序4.1 先平移后旋转Translate2D(1,0);/向右

26、平移一个单位Rotate2D(45); /旋转45度House( );/显示变换结果 1221011004sin4cos4sin4cos4sin4cos10110001010110004cos4sin0sincos144yx4.3 2D graphics display process二维图形的显示流程二维图形的显示流程 坐标系建立了图形与数之间的关系。 世界坐标系(用户坐标系:用户用来定义图形对象的整个自然空间。) 局部坐标系(相对坐标系:用户用来定义局部图形相对位置的的坐标系。) 屏幕坐标系(设备坐标系:在输出设备上定义的坐标系。) 窗口(用户在世界坐标系中选择一个矩形域来指定要表示的图形

27、。) 视区(用户在屏幕坐标系上选择一个矩形区来表示窗口内的图形。)二维图形的显示流程世界坐世界坐标系内标系内的变换的变换关于窗关于窗口的裁口的裁剪剪窗口到窗口到视区的视区的变换变换扫描转扫描转换换显示显示世界坐标系设备坐标系屏幕坐标系视口视口2viewport2世界坐标系world coordinates屏幕坐标系Screen coordinates窗口world window1窗口到视区变换window to viewport视口视口1viewport14.4 the window to viewport transformation窗口到视区的变换窗口到视区的变换WXLWXRWYBWYTV

28、XLVXRVYBVYT(xw, yw)(xv, yv)WXLWXRWXLxVXLVXRVXLxWvWYBWYTWYByVYBVYTVYByWv变换公式Transformation formulathe window to viewport transformation窗口到视口的变换窗口到视口的变换xv = axw + byv = cyw + d1000011dbcayxyxwwvv式中:a = (VXR VXL)/(WXR-WXL)b=VXL WXL*(VXR VXL)/(WXR WXL)c=(VYT VYB)/(WYT WYB)d=VYB WYB*(VYT VYB)/(WYT WYB) T

29、he constants A and B scale the x and y coordinates, and C and D shift (or translate) them。常数A和B缩放x,y坐标,C和D平移x,y。 The mapping can be used with any point (x, y) inside or outside the window. Points inside the window map to points inside the viewport, and points outside the window map to points outside

30、 the viewport. 该映射可以用于所有点,窗口内映射视口内,窗口外映射是口外。Ex. Consider the window and viewport of Fig.The window has (W.l, W.r, W.b, W.t) = (0, 2.0, 0, 1.0) and the viewport has (V.l, V.r, V.b, V.t) = (40, 400, 60, 300).Using the formulas,we obtainA = 180, C = 40,B = 240, D = 60The center of the window (1.0, 0.5)

31、 maps to the center of the viewport (220, 180 ). Thus, the window to viewport mapping is:sx = 180 x + 40sy = 240 y + 60 Each corner of the window is mapped to the corresponding corner of the viewport. For example, (2.0,1.0) maps to (400, 300). The center of the window (1.0, 0.5) maps to the center o

32、f the viewport (220, 180 ).Doing it in OpenGL the world window is set by the function gluOrtho2D(), prototype: void gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, Gldouble top) the viewport is set by the function glViewport(), prototype: void glViewport(GLint x, GLint y, GLint width, GLi

33、nt height) Because OpenGL uses matrices to set up all its transformations, gluOrtho2D()3 must be preceded by two “set up” functions glMatrixMode(GL_PROJECTION) and glLoadIdentity().OpenGL是通过矩阵进行变换的,必须先调这两个函数。 Ex.glMatrixMode(GL_PROJECTION);设置可视空间glLoadIdentity();/设置当前矩阵为单位矩阵gluOrtho2D(0.0, 2.0, 0.0,

34、 1.0); / sets the windowglViewport(40, 60, 360, 240); / sets the viewport4.5 The Elementary 3D Transformations三维几何变换三维几何变换stttlihgkfedjcbaTzyx 三维几何变换是二维几何变换的推广,其几何变换矩阵可用T3d表示。从变换功能上T3d可分为四个子矩阵。产生比例、旋转、错切等变换产生投影变换产生平移变换产生整体比例变换4.5.1 Translation平移变换平移变换1000100010 x001),(zyTzyxThe call glTranslatef (x,

35、 y, z) generates T1000-100-010 x-001),(1 -zyTzyx4.5.2 Scaling放缩变换放缩变换1000000000000zyxS10000100001000011 -zyxSThe call glScalef (x, y, z) generates S如glScalef(2.0f,3.0f,4.0f);将模型按x,y,z方向分别拉伸了2,3,4倍。Notice that S-1 is defined only if x, y, and z are all nonzero当缩放参数为负值时,该函数为对称矩阵(反射矩阵)如glScalef(1.0f,1.

36、0f,-1.0f);将模型关于z轴翻转了180(即关于xy轴所在平面对称);4.5.3 Rotations旋转变换10000cossin00sincos00001 )00 , 1glRotatef(:,xyz10000cos0sin00100sin0cos:)01 , 0 ,glRotatef(,1000010000cossin00sincos)10 ,0 ,glRotatef(:,在右手坐标系下相对坐标原点绕坐标轴旋转角的变换公式。Ex.第一个白色三角形是原始三角形,第二个红色三角形是白三角沿X 负轴平移后的三角形,第三个绿色三角形是白三角分别沿X轴和Y轴比例变换后的三角形,第四个蓝色三角形

37、是白三角绕Z正轴逆时针转90度后的三角形,第五个黄色三角形是白三角沿Y轴方向缩小一倍且相对于X轴作反射后形成的三角形。#include#include/#pragma comment(lib, OpenGL32.lib) /#pragma comment(lib, Glu32.lib) #pragma comment(lib, GlAux.lib) void myinit(void); void draw_triangle(void); void CALLBACK display(void); void CALLBACK myReshape(GLsizei w, GLsizei h); void draw_triangle(void) /绘三角形 glBegin(GL_LINE_LOOP); glVertex2f(0.0, 25.0); glVertex2f(25.0, -25.0); glVertex2f(-25.0, -25.0); glEnd(); void C

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论