+ All Categories
Home > Documents > Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of...

Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of...

Date post: 21-Jan-2016
Category:
Upload: caitlin-strickland
View: 218 times
Download: 0 times
Share this document with a friend
Popular Tags:
38
Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology
Transcript
Page 1: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

Advanced Computer Graphics Spring 2009

K. H. Ko

Department of MechatronicsGwangju Institute of Science and Technology

Page 2: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

2

Today’s Topics

Intersection Test MethodsRay/objectObject/object

Page 3: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

3

Introduction

Intersection testing is often used in computer graphics.Click the mouse on an object. (Object

picking)Determine whether two objects collide.Make sure we maintain a constant

height for our viewer as we navigate a building.

Page 4: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

4

Definitions and Tools

A ray r(t) is defined by an origin point o and a direction unit vector, d. r(t) = o + td. The scalar t is a variable that is used to generate diffe

rent points on the ray. t < 0 : points that lie behind the ray origin (not part of the ray). t > 0 : points that lie in front of the origin.

In practice we often store a current distance l, which is the maximum distance we want to search along the ray.

Page 5: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

5

Definitions and Tools

Implicit SurfacesA surface defined by an implicit function

f(p) = f(px,py,pz) = 0. Explicit Surfaces

A surface defined by a vector function f and some parameters rather than a point on the surface

f(u,v) = (fx(u,v),fy(u,v),fz(u,v))

Page 6: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

6

Definitions and Tools

Three Bounding VolumesAABB: Axis-Aligned Bounding BoxOBB: Oriented Bounding Boxk-DOP: k – Discrete Oriented Polytope

Page 7: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

7

Definitions and Tools

AABBAn Axis-aligned Bounding Box (also called rect

angular box), is a box whose faces have normals that coincide with the standard basis axes.

Page 8: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

8

Definitions and Tools

OBBAn Oriented Bounding Box is a box whose face

s have normals that are all pairwise orthogonal. It is an AABB that is arbitrarily rotated.

Page 9: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

9

Definitions and Tools

K-DOP A k-Discrete Oriented Polytope is defined by k/2 (wher

e k is even) normalized normals (orientations), ni, 1 ≤ i ≤ k/2 and with each ni, two associated scalar values di

min and dimax where di

min < dimax.

Each triple(ni,dimin,di

max) describes a slab, Si, which is the volume between the two planes, пi

min : niᆞ x + dimin

= 0 and пimax : niᆞ x + di

max = 0 and where the intersection of all slabs, ∩1≤l ≤k/2 Sl is the actual k-DOP volume.

Page 10: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

10

Definitions and Tools

K-DOPAn 8-DOP in two dimensions

Page 11: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

11

Definitions and Tools

Separating Axis Theorem (SAT)For any two arbitrary, convex, disjoint polyhedr

a, A and B, there exists a separating axis where the projections of the polyhedra, which form intervals on the axis, are also disjoint.

Page 12: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

12

Definitions and Tools

Separating Axis Theorem (SAT) If A and B are disjoint, then they can be

separated by an axis that is orthogonal to either

a face of A a face of B An edge from each polyhedron

Page 13: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

13

Bounding Volume Creation

Given a collection of objects, finding a tight fitting bounding volume is important to minimizing intersection costs.

The chance that an arbitrary ray will hit any convex object is proportional to that objects’ surface area. Minimizing this area increases the efficiency of

any intersection algorithm as a rejection is never slower to compute than an intersection.

It is often better to minimize the volume of BV for collision detection algorithms.

Page 14: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

14

AABB and k-DOP Creation

AABBThe simplest bounding volumes to

create is an AABB.Take the minimum and maximum

extents of the set of polygon vertices along each axis and the AABB is formed.

Page 15: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

15

AABB and k-DOP Creation

k-DOPProject the vertices onto each normal, ni, of th

e k-DOP.Extreme values (min,max) of these projections

are stored in dimin and di

max. These two values define the tightest slab for t

hat direction. Together, all such values define a minimal k-D

OP.

Page 16: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

16

Sphere Creation

Form an AABB for the polygon set and then use the center and the diagonal of this box to form the sphere. This sometimes gives a poor fit, and the fit can

often be improved by another quick pass. Starting with the center of the AABB as the center of

the sphere BV. Go through all vertices once again and find the one

that is farthest from this center. This is then the new radius.

Page 17: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

17

Sphere Creation

Ritter’s algorithm: a near optimal bounding sphere. Find the vertex that is at the minimum and the vertex at

the maximum along each of the x, y and z axes. For these three pairs of vertices, find the pair with the

largest distance between them. Use this pair to form a sphere with its center at the

midpoint between them and a radius equal to the distance to them.

Go through all the other vertices and check its distance d to the center of the sphere.

If the vertex is outside the sphere’s radius r, move the sphere’s center toward the vertex by (d-r)/2, set the radius to (d+r)/2 and continue.

This step has the effect of enclosing the vertex and the existing sphere in a new sphere.

After this second time through the list, the bounding sphere is guaranteed to enclose all vertices.

Page 18: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

18

Sphere Creation

Welzl’s algorithm Expected to be linear for a randomized list of vertices. The idea is to find a supporting set of points defining

a sphere. When a vertex is found to be outside the current spher

e, its location is added to the supporting set. The new sphere is computed and the entire list is run

through again. This process repeats until the sphere contains all verti

ces. This algorithm guarantees that an optimal bounding sp

here is found.

Page 19: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

19

OBB Creation

Gottschalk’s method A tight-fitting OBB enclosing an object can be found by

computing an orientation from the triangles of the convex hull.

Formulae for computing a good fit OBB using a statistical method

The convex hull of an object must be computed. O(nlog(n)). Quickhull algorithm. This gives us n triangles defined as Δpkqkrk, (vertices of triangle

k), the area of triangle k as ak, and the total area of the convex hull as aH, the sum of ak.

Page 20: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

20

OBB Creation

Gottschalk’s method The convex hull of an object must be computed. O

(nlog(n)). The centroid of the whole convex hull, mH.: the weig

hted mean of the triangle centroids.

Construct a 3 by 3 covariance matrix C.

Page 21: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

21

OBB Creation

Gottschalk’s method Compute the eigenvalues of C, which are the directi

on vectors for a good-fit box, au, av, and aw. Find the center and the half-lengths of the OBB.

This is done by projecting the points of the convex hull onto the direction vectors and finding the minimum and maximum along each direction.

This will determine the size and position of the box and fully specify the OBB according to its definition.

Page 22: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

22

OBB Creation

Eberly’s method A method for computing a minimum-volume OBB using a minimiz

ation technique.- Iterative algorithm. The convex hull need not be computed. For a box with the axis au, av and aw, the points are projected onto

these axes. The min, ku

min and kumax along au are found.

Then, kvmin, kv

max, kwmin, and kw

max are computed similarly. The center of this box is then

Page 23: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

23

OBB Creation

Eberly’s methodThe set of possible directions of the box are s

ampled and the axes are used whose box is smallest as a starting point for the numeric minimizer.

Then Powell’s direction set method is used to find the minimum volume box.

Page 24: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

24

Rules of Thumb

For faster, more robust and more exact intersection tests, Perform computations and comparisons that might

trivially reject or accept various types of intersections to obtain an early escape from further computations.

If possible, exploit the results from previous tests. If more than one rejection or acceptance test is used,

then try changing their internal order, since a more efficient test may result. Do not assume that what appears to be a minor change will have no effect.

Postpone expensive calculations until they are truly needed.

The intersection problem can often be simplified considerably by reducing the dimension of the problem.

Page 25: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

25

Rules of Thumb

For faster, more robust and more exact intersection tests, If a single ray or object is being compared to many other objects

at a time, look for precalculations that can be done just once before the testing begins.

Whenever an intersection test is expensive, it is often good to start with a sphere around the object to give a first level of quick rejection.

Make it a habit always to do timing comparisons on your computer, and use real data and testing situations for the timings.

Try to make your code robust. This means it should work for all special cases and that it will be insensitive to as many floating point precision errors as possible. Be aware of any limitations it may have.

Page 26: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

26

Ray/Sphere Intersection

Mathematical solution A sphere can be defined by a center point, c, and a ra

dius r. f(p) = ||p-c|| - r = 0, p is any point on the sphere’s surface.

Given a ray r(t), we can find the intersections as follows:

f(r(t)) = ||r(t) –c|| - r = 0.

Page 27: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

27

Ray/Sphere Intersection

Mathematical solutionThe equation is of quadratic form

t2+2tb+c=0, b=dᆞ (o-c), c = (o-c)ᆞ (o-c) - r2.

Page 28: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

28

Ray/Sphere Intersection

For the other quadrics, e.g., the cylinder, ellipsoid, cone and hyperboloid, the mathematical solutions to their intersection problems are almost as straightforward as for the sphere.

Sometimes, it is necessary to bound a surface (cylinder).

Page 29: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

29

Ray/Sphere Intersection

Optimized Solution Intersections behind the ray origin are not nee

ded. Compute a vector l = c – o, the vector from the ray

origin to the center of the sphere. The squared length of the vector : l2 = lᆞ l.

If l2 < r2, the ray origin is inside the sphere. This guarantees that the ray hits the sphere.

Page 30: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

30

Ray/Sphere Intersection

Optimized Solution Compute the projection of l onto the ray direction d:

s = lᆞ d. If s < 0 and the ray origin is outside the sphere, then the

sphere is behind the ray origin and we can reject the intersection.

Otherwise, the squared distance from the sphere center to the projection is computed using the Pythagorean theorem: m2 = l2-s2.

If m2 > r2 the ray will definitely miss the sphere and the rest of the calculations can safely be omitted.

If the sphere and ray pass this last test, then the ray is guaranteed to hit the sphere.

Page 31: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

31

Ray/Sphere Intersection

Optimized SolutionComputation of the real intersection points

Calculate the squared distance q2 = r2 – m2. Since m2 <= r2, q = q1/2

The distances to the intersections are t = s ± q If we are interested in only the first, positive

intersection point, then t1 = s – q for the case where the ray origin is outside

the sphere. t2 = s + q when the ray origin is inside.

Page 32: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

32

Ray/Sphere Intersection

Optimized SolutionComputation of the real intersection

points

Page 33: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

33

Ray/Box Intersection

Three methods for determining whether a ray intersects a box are introduced.

1. Both AABBs and OBBs2. Faster than the first one but can deal with on

ly the simpler AABB.3. Based on the separating axis theorem and h

andles only line segments versus AABBs.

Page 34: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

34

Ray/Box Intersection (Slabs Method)

A slab is the volume between the two parallel planes.

A box is considered to be a set of three slabs in 3D (2 in 2D)

Page 35: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

35

Ray/Box Intersection (Slabs Method) For each slab, there is a minimum and a maximum t-valu

e and these are called tmini and tmax

i i = u, v, w. The next step is to compute the variables as follows

tmin = max(tminu,tmin

v,tminw)

tmax = min(tmaxu,tmax

v,tmaxw)

The clever test: If tmin ≤ tmax, then the ray intersects the box. Otherwise it misses.

A generalized of the slabs method can be used to compute the intersection of a ray with a k-DOP, frustum, or any convex polyhedron.

Page 36: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

36

Ray/Box Intersection (Woo’s Method) Some smart optimizations for finding the

intersection between a ray and an AABB. Given a ray and an AABB, denoted B, the idea is

to identify three candidate planes out of the six planes composing the AABB.

For each pair of parallel planes, the back-facing plane can be omitted from further consideration.

After finding these three planes, we compute the intersection distances (t-values) between the ray and the planes. The largest of these distances corresponds to a potential

hit.

Page 37: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

37

Ray/Box Intersection (Woo’s Method)

If a potential hit is found, the actual intersection point is computed.

If it is located on the corresponding face of B, then it is a real hit.

do

Page 38: Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology.

38

Ray/Box Intersection (Line Segment/Box Overlap Test) The separating axis theorem can be used to dete

rmine whether a line segment overlaps an AABB. The line segment has finite length in contrast to

a ray. The line segment is defined by a center c and a half v

ector w. Both the AABB, denoted B, and the line segment

have been translated so the AABB’s origin is (0,0,0).

The size of the box is (2hx,2hy,2hz), h is the half vector of the box.


Recommended