Graphics Graphics Korea University kucg.korea.ac.kr Geometric Primitives 고려대학교 컴퓨터 그래픽스 연구실
KUCG Graphics Korea University kucg.korea.ac.kr Scalar, Points, and Vectors Scalar real number ex) length of line segment Points location in space fundamental geometric object Vectors quantity with direction and magnitude ex) velocity, force
KUCG Graphics Korea University kucg.korea.ac.kr Mathematical View Vector space entities: vectors and scalars operations: vector-vector addition, vector-scalar multiplication Affine space entities: vectors, scalars, and points operations: vector-vector addition, vector-scalar multiplication, vector-point addition, point-point subtraction Euclidean space + measure of size or distance
KUCG Graphics Korea University kucg.korea.ac.kr Geometric ADTs (1/2) ADT: abstract data type Entities scalars: real numbers points: locations in space vectors: directed line segments Operations magnitude magnitude of a vector: real number magnitude of vector-scalar multiplication zero magnitude: zero vector
KUCG Graphics Korea University kucg.korea.ac.kr Geometric ADTs (2/2) Operations (cont’) subtraction of two points – yields a vector point-vector addition vector-vector addition visualization:head-to-tail rule u+v v u P – R P – Q Q – R P Q R
KUCG Graphics Korea University kucg.korea.ac.kr Lines Line in an affine space sum of a point and a vector subtraction of two points
KUCG Graphics Korea University kucg.korea.ac.kr Affine Sums In affine space O: vector-vector addition, vector-scalar multiplication, vector-point addition X: addition of two points, point-scalar multiplication Affine addition
KUCG Graphics Korea University kucg.korea.ac.kr Convexity Convex object any point lying on the line segment connecting any two points in the object is also in the object (chap.2) Use affine sums convex object such as line segment convex hull P(α) Q R
KUCG Graphics Korea University kucg.korea.ac.kr Dot Products Inner products – orthogonal: magnitude of a vector: angle between two vectors: orthogonal projection: v θ u |v|cosθ
KUCG Graphics Korea University kucg.korea.ac.kr Cross Products Outer products – right-handed coordinates system direction of the thumb of the right hand v u u v
KUCG Graphics Korea University kucg.korea.ac.kr Planes Extension of line P Q R normal to the plane P0P0 v u n P
KUCG Graphics Korea University kucg.korea.ac.kr 3D Primitives (1/2) Curves, surfaces, volumetric objects Curves Volumetric objects Surfaces
KUCG Graphics Korea University kucg.korea.ac.kr 3D Primitives (2/2) Three conditions of 3D objects to fit well with existing computer graphics hardware and software described by surface and thought of as being hollow need 2D primitives to model 3D objects specified through a set of vertices in 3D use a pipeline architecture to process vertices at high rate composed of or approximated by flat convex polygons most graphics system require that user specify simple planner polygons tessellation, exception – CSG
KUCG Graphics Korea University kucg.korea.ac.kr CSG Constructive solid geometric build object from a small set of volumetric objects through set operations union intersection
KUCG Graphics Korea University kucg.korea.ac.kr Coordinate Systems 3D vector space scalar component : 1, 2, 3 basis vector : v 1, v 2, v 3 define a coordinate system the origin : fixed reference point representation: column matrix v2v2 v1v1 v3v3 Coordinate System
KUCG Graphics Korea University kucg.korea.ac.kr Frames Basis set of vectors and a particular point P 0 more general representation fix the origin at P 0 homogeneous coordinates avoid the difficulties caused by vectors having magnitude and direction but no fixed position represent points and vectors with matrices maintain a distinction between points and vectors vector : point : v2v2 v1v1 v3v3 Frame origin
KUCG Graphics Korea University kucg.korea.ac.kr Changes of Coordinate Systems (1/2) Two basis: { v 1, v 2, v 3 }, { u 1, u 2, u 3 } matrix
KUCG Graphics Korea University kucg.korea.ac.kr Changes of Coordinate Systems (2/2) Vector: w
KUCG Graphics Korea University kucg.korea.ac.kr Change of Basis Origin unchanged rotation and scaling of a set of basis vectors Origin changed translation of the origin, or change of frame homogeneous coordinates v2v2 v1v1 v3v3 v’ 2 v’ 1 v’ 3 v2v2 v1v1 v3v3 v’ 2 v’ 1 v’ 3
KUCG Graphics Korea University kucg.korea.ac.kr Example of Change Basis (1/2) Suppose a vector: w a = [ ] T 3 basis vectors : v 1, v 2, v 3 new basis : u 1, u 2, u 3
KUCG Graphics Korea University kucg.korea.ac.kr Example (2/2) Change of basis
KUCG Graphics Korea University kucg.korea.ac.kr Homogeneous Coordinates (1/2) Confusion between points and vectors !! Point P and vector v in frame ( v 1, v 2, v 3, P 0 )
KUCG Graphics Korea University kucg.korea.ac.kr Homogeneous Coordinates (2/2) Change of frames ( v 1, v 2, v 3, P 0 ), ( u 1, u 2, u 3, Q 0 )
KUCG Graphics Korea University kucg.korea.ac.kr Example of Change in Frames Change of frames ( v 1, v 2, v 3, P 0 ), ( u 1, u 2, u 3, Q 0 ) Point p = [ ] T p’ = [ ] T
KUCG Graphics Korea University kucg.korea.ac.kr Another Example Change of frames ( v 1, v 2, v 3, P 0 ), ( u 1, u 2, u 3, Q 0 ) Point p = [ ] T p’ = [ ] T
KUCG Graphics Korea University kucg.korea.ac.kr Drawing a Rotating Cube Tasks to generate the image modeling converting to the camera frame clipping projecting removing hidden surfaces rasterizing
KUCG Graphics Korea University kucg.korea.ac.kr Modeling a Cube Surface-based model outward-pointing face right-hand rule: counterclockwise order Data structure geometry: location of vertices topology: connectivity GLfloat vertices[8][3]= { {-1.0, -1.0, -1.0}, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0}, {-1.0, -1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0}}; glBegin(GL_POLYGON); glVertex3fv(vertices[0]); glVertex3fv(vertices[3]); glVertex3fv(vertices[2]); glVertex3fv(vertices[1]); glEnd();
KUCG Graphics Korea University kucg.korea.ac.kr Color Cube (1/2) typedef Glfloat point3[3]; Point3 vertices[8]= { {-1.0, -1.0, -1.0}, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0}, {-1.0, -1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0}}; Glfloat colors[8][3] = { {0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {0.0, 1.0, 1.0}}; void quad(int a, int b, int c, int d) { glBegin(GL_QUADS); glColor3fv(colors[a]); glVertex3fv(vertices[a]); glColor3fv(colors[b]); glVertex3fv(vertices[b]); glColor3fv(colors[c]); glVertex3fv(vertices[c]); glColor3fv(colors[d]); glVertex3fv(vertices[d]);
KUCG Graphics Korea University kucg.korea.ac.kr Color Cube (2/2) Bilinear interpolation glEnd(); } void display() { quad(0, 3, 2, 1); quad(2, 3, 7, 6); quad(0, 4, 7, 3); quad(1, 2, 6, 5); quad(4, 5, 6, 7); quad(0, 1, 5, 4); } C1C1 C2C2 C3C3 C0C0 C 23 (α) C 01 (α) C 45 (α) C4C4 C5C5