컴퓨터그래픽스

[23-1 컴퓨터 그래픽스 정리] transformations

begong 2023. 7. 13. 21:58
반응형
본 글은 국민대학교 김준호 교수님의 "컴퓨터 그래픽스" 강의자료 정리 목적으로 만들었습니다.
글 자료의 모든 권한은 김준호 교수님께 있습니다.

Affine Space & Homogeneous Coordinates

OpenGL ES uses Homogeneous coordinate System

Graphics cards support homogeneous coordinates

  • 4 X 1 vectors for 3D points & 3D vectors
    • point (position) : 마지막에 무조건 1이 붙음
    • vector : 마지막에 무조건 0을 넣음Screenshot 2023-04-22 at 10 42 37 PM
  • In general, the following holds
    • it is related to projective geometryScreenshot 2023-04-22 at 10 42 40 PM

point-point = vector

point = vector + point

point+point, point+숫자 는 정의할 수 없음.

Affine Space

Scalar ⊕ Vector ⊕ Point

Operations

  • vector-vector addition
  • scalar-vector multiplication
  • point-vector addition
  • scalar-scalar opertionsfor any point define
  • 1 * p = p
  • 0 * p = 0(zero vector)

Scalars

Scalars represent the concept of quantity

  • 단순 양을 나타내는 숫자
    • ex > 7, 3.14, -1
  • combined with two basic operations
    • addition
    • multiplicationScalars alone have no geometric propoeries
  • 스칼라는 혼자서는 방향성, 형태가 없다.

Vectors

A vector is a quantity of two attributes

  • Direction
  • magnitute

A vector usually represented with a directed line segment

Examples include

물리량을 표현하기도 한다
  • force
  • velocity

Vectors Lack Point

  • Vector는 위치에 상관이 없다
    • 위치에 상관없이 방향과 힘이 같다면 같은 벡터이다.

Points

Location in space

Operations allowed between points and vectors

  • Point-point subtraction yields a vector
    • p-q =v
    • p+q : no physical meaning
    • p와 q는 Point
  • Equivalenmt to point- vector addtion
    • Q+v=p

Homogeneous Coordinates

Homogeneous coordinate systems clearly distnguish the concepts of vectors and points

  • nD point is represented with a (n+1)D vector, whose last component is 1
  • nD Vector is reprented with a (n+1)D vector, whose last component is 0

Screenshot 2023-04-22 at 10 42 40 PM

마지막 숫자 덕분에 깔끔해진다.

연산 가능한 것과 불가능 한것도 구분된다

OpenGL에서는 homogeneous coordinate를 지원한다.

행렬, 백터는 위에서 아래로 먼저 읽는다.

Screenshot 2023-04-22 at 10 59 48 PM

Linear Transformations

Transformation

In computer graphics, transformation refer to

  • Change of shape
    • Linear transformation : line to line
      • 변환해도 선이다
    • None-linear transformation : line to curve
      • 변환하면 곡선이 된다
      • 굳이 할거면 미분해서 하면 됨.Linear TransformationStandard transformation
      • It can be represented as linear a matrix
  • Translation / rotation / scalingComposition of linear transformation is linear

Translation

Move (translate, displace) a point to a new location

  • Translation of an object : every point displaced by same vectorDisplacement determined by a vector d
  • Three degrees of freedom for d, in 3D case : d=(dx,dy,dz)
  • x' = x+d

Translation matrix T

  • Translation can also be expressed by using a 4X4 matrix T in homogeneous coordinates
  • x'=Tx
    • T = T(dx,dy,dz)Screenshot 2023-04-22 at 11 05 28 PM
  • glTranslate(dx,dy,dz)

Translation 행렬의 해석

Screenshot 2023-04-22 at 11 06 52 PM

행렬을 쪼갠 submetrix도 성립

Screenshot 2023-04-22 at 11 06 58 PM

vector는 이동해도 동일하기때문에 똑같은 [V 0]이 나오는것이 맞다.

Rotation

Screenshot 2023-04-22 at 11 13 58 PM

원점이 기준점이다

Screenshot 2023-04-22 at 11 14 19 PM

vector는 위치가 중요하지않음. 방향만 바뀌면 됨

Screenshot 2023-04-22 at 11 14 55 PM

2차원까지는 복소수 i로 회전을 나타낼 수 있었음

  • I 하나에 90도3차원 부터는 quaternion으로 나타낼 수 있음
  • 참고
  • 길이는 항상 1이다. 회전을하지 늘리는것이 아니기 때문

Screenshot 2023-04-22 at 11 15 01 PM

Scaling

Scaling matrix S

  • Expand or contract along each axis
  • x'=Sx
    • s=s(sx,sy,sz) =Screenshot 2023-04-22 at 11 20 02 PM
  • glScale(sx,sy,sz)

Screenshot 2023-04-22 at 11 22 05 PMScreenshot 2023-04-22 at 11 22 56 PM

Model Transformations

Screenshot 2023-04-22 at 11 25 17 PM

항상 scale => rotation => translation 순으로 연산을 진행해야 함.

순서가 바뀌면 원하는 값이 나오지 않을 수 있음.

Screenshot 2023-04-22 at 11 28 27 PMScreenshot 2023-04-22 at 11 28 32 PM

물체가 원점에서 떨어져 있을 경우, rotation scaling을 진행할 시에 원하는 결과가 나오지 않음

물체를 원점에 가져다 놓고 진행을 해야 올바른 결과를 얻을 수 있음.

Instancing

In modeling, we often start with a simple object coentered at the origin, oriented with the axis, and at a standard size

We apply an instance transformation to its vertices to

  • scale
  • orient
  • locate동일한 물체를 여러개 표현하고 싶을 때 모델 데이터 하나를 가지고, scale rotate translation을 이용해 표현할 수 있다.
  • 랜더링 횟수는 그대로다. 메모리에 모델 정보를 적게 들어가게 하기위해 하는 것
  • Instancing은 동일한 물체(모델)을 복사하는 것

Screenshot 2023-04-22 at 11 33 29 PM

View Transformations

뷰어의 입장에서 생각해보자

Coordinate System (Frame)

A Coordinate system (or Frame) consist of a set of basis vectors and an origin

  • A set of basis vectors: v1,v2,...,vn (기저벡터)
  • an origin : o (원점)

Screenshot 2023-04-22 at 11 41 07 PM

u : 기저백터를 조합해서 u를 만든다

p : 원점기준으로 얼마만큼씩 이동해야 하나를 나타낸다

In OpenGl ES, we just care about orthonormal frames

  • Ortho means that the basis vectors are orthogonal to each other
    • x-axis ⊥ y-axis ⊥ z-axis
  • normal means that the length of each basis vector is 1
    • the unit length of each axis is equal to 1카메라는 무조건 Orthonormal 좌표계 사용, 오른손 좌표계 사용.
    • xyz가 오른손 좌표계를 따르면 되는거지 어디를 가르키느냐는 중요하지 않다.

Screenshot 2023-04-22 at 11 45 42 PM

Inside of gluLookAt()

when we apply gluLookAt()

  • Rotate the camera frame on the world frame : Rc
  • Translate the camera frame on the world frame : Tc
  • therefore, v=TcRc and gluLookAt generates V-1=Rc-1Tc-1
    • v=tr을 카메라 기준으로 바꾼 것이다.

Screenshot 2023-04-22 at 11 54 13 PMScreenshot 2023-04-22 at 11 54 25 PM

역함수 취하면 행렬이 저렇게 됨

화살표의 방향은 카메라의 각 축이 가르키는 방향

반응형