多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > 2D Transformations

2D Transformations

來源:程序員人生   發布時間:2015-06-06 08:21:15 閱讀次數:6293次

       以下是關于2D的1些理論和推導進程,詳細描寫了圖象的平移、縮放和旋轉等;

This article is from: 2D Transformations

Transformaions are a fundamental part of computer graphics. Transformations are used to position objects, to shape objects, to change viewing positions, and even to change how something is viewed (e.g. the type of perspective that is used).

 

In 3D graphics, we must use 3D transformations. However, 3D transformations can be quite confusing so it helps to first start with 2D.

There are 4 main types of transformations that one can perform in 2 dimensions:

  • translations
  • scaling
  • rotation
  • shearing

These basic transformations can also be combined to obtain more complex transformations. In order to make the representation of these complex transformations easier to understand and more efficient, we introduce the idea of homogeneous coordinates.

Representation of Points/Objects

A point p in 2D is represented as a pair of numbers: p= (xy) where x is the x-coordinate of the point p and y is the y-coordinate of p . 2D objects are often represented as a set of points (vertices), {p1,p2,...,pn}, and an associated set of edges {e1,e2,...,em}. An edge is defined as a pair of points e = {pi,pj}. What are the points and edges of the triangle below?

We can also write points in vector/matrix notation as

Translations

Assume you are given a point at (x,y)=(2,1). Where will the point be if you move it 3 units to the right and 1 unit up? Ans: (x',y') = (5,2). How was this obtained? - (x',y') = (x+3,y+1). That is, to move a point by some amount dx to the right and dy up, you must add dx to the x-coordinate and add dy to the y-coordinate.

What was the required transformation to move the green triangle to the red triangle? Here the green triangle is represented by 3 points

triangle = { p1=(1,0), p2=(2,0), p3=(1.5,2) }

What are the points and edges in this picture of a house? What are the transformation is required to move this house so that the peak of the roof is at the origin? What is required to move the house as shown in animation?

 click here for animation

Matrix/Vector Representation of Translations

A translation can also be represented by a pair of numbers, t=(tx,ty) where tx is the change in the x-coordinate and ty is the change in y coordinate. To translate the point p by t, we simply add to obtain the new (translated) point q = p + t.

q = p + t = + = 

Scaling

Suppose we want to double the size of a 2-D object. What do we mean by double? Double in size, width only, height only, along some line only? When we talk about scaling we usually mean some amount of scaling along each dimension. That is, we must specify how much to change the size along each dimension. Below we see a triangle and a house that have been doubled in both width and height (note, the area is more than doubled).

 

The scaling for the x dimension does not have to be the same as the y dimension. If these are different, then the object is distorted. What is the scaling in each dimension of the pictures below?

 

And if we double the size, where is the resulting object? In the pictures above, the scaled object is always shifted to the right. This is because it is scaled with respect to the origin. That is, the point at the origin is left fixed. Thus scaling by more than 1 moves the object away from the origin and scaling of less than 1 moves the object toward the origin. This can be seen in the animation below.

 click here for animation

This is because of how basic scaling is done. The above objects have been scaled simply by multiplying each of its points by the appropriate scaling factor. For example, the point p=(1.5,2) has been scaled by 2 along x and .5 along y. Thus, the new point is

q = (2*1.5,.5*2) = (3,1).

Matrix/Vector Representation of Translations

Scaling transformations are represented by matrices. For example, the above scaling of 2 and .5 is represented as a matrix:

scale matrix: s =  = 

new point: q = s*p =  = 

Scaling about a Particular Point

What do we do if we want to scale the objects about their center as show below? Answer

 

Rotation

Below, we see objects that have been rotate by 25 degrees.

 

Again, we see that basic rotations are with respect to the origin:

 click here for animation

Matrix/Vector Representation of Translations

counterclockwise rotation of a degrees = 

Shear

 click here for animation

Matrix/Vector Representation of Translations

shear along x axis = 

shear along y axis = 

Combining Transformations

We saw that the basic scaling and rotating transformations are always with respect to the origin. To scale or rotate about a particular point (the fixed point) we must first translate the object so that the fixed point is at the origin. We then perform the scaling or rotation and then the inverse of the original translation to move the fixed point back to its original position. For example, if we want to scale the triangle by 2 in each direction about the point fp = (1.5,1), we first translate all the points of the triangle by T = (⑴.5,⑴), scale by 2 (S) , and then translate back by -T=(1.5,1). Mathematically this looks like

q =  ( +

Order Matters!

Notice the order in which these transformations are performed. The first (rightmost) transformation is T and the last (leftmost) is -T. If you apply these transformations in a different order then you will get very different results. For example, what happens when you first apply T followed by -T followed by S? Here T and -T cancel each other out and you are simply left with S

.Sometimes (but be careful) order does not matter, For example, if you apply multiple 2D rotations, order makes no difference:

R1 R2 = R2 R1

But this will not necessarily be true in 3D!!

Homogeneous Coordinates

In general, when you want to perform a complex transformation, you usually make it by combining a number of basic transformations. The above equation for q, however, is awkward to read because scaling is done by matrix multiplication and translation is done by vector addition. In order to represent all transformations in the same form, computer scientists have devised what are called homogeneous coordinates. Do not try to apply any exotic interpretation to them. They are simply a mathematical trick to make the representation be more consistent and easier to use.


Homogeneous coordinates (HC) add an extra virtual dimension. Thus 2D HC are actually 3D and 3D HC are 4D. Consider a 2D point p = (x,y). In HC, we represent p as p = (x,y,1). An extra coordinate is added whose value is always 1. This may seem odd but it allows us to now represent translations as matrix multiplication instead of as vector addition. A translation (dx, dy) which would normally be performed as q = (x,y) + (dx, dy) now is written as

q = T p =  

Now, we can write the scaling about a fixed point as simply a matrix multiplication:

q = (-T) S T p = A p,

where A = (-T) S T

The matrix A can be calculated once and then applied to all the points in the object. This is much more efficient than our previous representation. It is also easier to identify the transformations and their order when everything is in the form of matrix multiplication.

The matrix for scaling in HC is

S = 

and the matrix for rotation is

R = 

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 久久天天| 新武则天一级淫片免费放 | 日韩欧美精品有码在线观看 | 国产不卡的一区二区三区四区 | 欧美精品一区二区在线观看 | 免费在线观看成年人视频 | 欧美一区二区三区高清视频 | 性做久久久久免费观看 | 中文在线视频观看 | 日韩精品一区二区三区毛片 | 男人懂得成a人v网站 | 美国特级成人毛片 | 最近中文字幕无免费 | 亚洲欧美国产视频 | 亚洲黄色视屏 | 亚洲天堂成人在线观看 | 欧美一级欧美一级在线播放 | 噜噜噜私人影院 | 波多野结衣免费在线视频 | xxx在线视频| 亚洲欧美色综合一区二区在线 | 伊人中文| 日韩欧美一区二区三区中文精品 | 亚洲国产日本 | 波多野结衣一区在线 | 欧美另类69xxxxx极品 | 国产综合区| 久久99精品久久久久久三级 | 字幕网中文最新在线 | 中文字幕视频在线观看 | 国产三区二区 | 精品久久一区二区三区 | 亚洲天堂第一页 | 性久久久久久久久久 | 中文字幕在线观看一区二区三区 | 国产永久免费爽视频在线 | 欧美色就色 | 国产欧美亚洲精品 | 欧美日韩视频 | 国产妖精视频 | 亚洲国产欧美在线人网站 |