csce 552 spring 2009 math, physics and collision detection by jijun tang

87
CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Upload: joy-claribel-harvey

Post on 12-Jan-2016

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

CSCE 552 Spring 2009

Math, Physics and Collision Detection

By Jijun Tang

Page 2: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Game Entities

What are game entities? Basically anything in a game world that can be interacted

with More precisely, a self-contained piece of logical interactive

content Only things we will interact with should become game entities

Organization Simple list Multiple databases Logical tree Spatial database

Page 3: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Identification and Communication

Identification Strings Pointers Unique IDs or handles

Communication Simplest method is function calls Many games use a full messaging system Need to be careful about passing and allocating

messages

Page 4: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Applied Trigonometry

Trigonometric functions Defined using right triangle

x

yh

Page 5: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Visualize Vectors

The length represents the magnitude The arrowhead indicates the direction Multiplying a vector by a scalar

changes the arrow’s length

V

2V

–V

Page 6: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Vectors Add and Subtraction

Two vectors V and W are added by placing the beginning of W at the end of V

Subtraction reverses the second vector

V

WV + W

V

W

V

V – W–W

Page 7: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Matrix Representation

The entry of a matrix M in the i-th row and j-th column is denoted Mij

For example,

Page 8: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Invertible

An n n matrix M is invertible if there exists another matrix G such that

The inverse of M is denoted M-1

1 0 0

0 1 0

0 0 1

n

MG GM I

Page 9: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Inverse of 4x4

1 1 1 111 12 13

1 1 1 1 1 121 22 23

1

1 1 1 131 32 33

1 0 0 0 1

x

y

z

R R R

R R R

R R R

R T

R R T R TM

R T

0

Page 10: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Transformations

Calculations are often carried out in many different coordinate systems

We must be able to transform information from one coordinate system to another easily

Matrix multiplication allows us to do this

Page 11: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Illustration

Page 12: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

R S T

Suppose that the coordinate axes in one coordinate system correspond to the directions R, S, and T in another

Then we transform a vector V to the RST system as follows

Page 13: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

2D Example

θ

Page 14: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

2D Rotations

Page 15: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Rotation Around Arbitrary VectorRotation about an arbitrary vector Counterclockwise rotation about an arbitrary vector (lx,ly,lz) normalised so that             

       by an angle α is given by a matrix                                                                            

where

Page 16: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Transformation matrix

We transform back to the original system by inverting the matrix:

Often, the matrix’s inverse is equal to its transpose—such a matrix is called orthogonal

Page 17: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Translation

A 3 3 matrix can reorient the coordinate axes in any way, but it leaves the origin fixed

We must add a translation component D to move the origin:

Page 18: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Homogeneous coordinates

Four-dimensional space Combines 3 3 matrix and translation

into one 4 4 matrix

Page 19: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Direction Vector and Point

V is now a four-dimensional vector The w-coordinate of V determines whether

V is a point or a direction vector If w = 0, then V is a direction vector and the

fourth column of the transformation matrix has no effect

If w 0, then V is a point and the fourth column of the matrix translates the origin

Normally, w = 1 for points

Page 20: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Transformations

The three-dimensional counterpart of a four-dimensional homogeneous vector V is given by

Scaling a homogeneous vector thus has no effect on its actual 3D value

Page 21: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Transformations

Transformation matrices are often the result of combining several simple transformations Translations Scales Rotations

Transformations are combined by multiplying their matrices together

Page 22: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Transformation Steps

Page 23: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Translation

Translation matrix

Translates the origin by the vector T

translate

1 0 0

0 1 0

0 0 1

0 0 0 1

x

y

z

T

T

T

M

Page 24: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Scale

Scale matrix

Scales coordinate axes by a, b, and c If a = b = c, the scale is uniform

scale

0 0 0

0 0 0

0 0 0

0 0 0 1

a

b

c

M

Page 25: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Rotation (Z)

Rotation matrix

Rotates points about the z-axis through the angle

-rotate

cos sin 0 0

sin cos 0 0

0 0 1 0

0 0 0 1

z

M

Page 26: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Rotations (X, Y)

Similar matrices for rotations about x, y

-rotate

1 0 0 0

0 cos sin 0

0 sin cos 0

0 0 0 1

x

M

-rotate

cos 0 sin 0

0 1 0 0

sin 0 cos 0

0 0 0 1

y

M

Page 27: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Transforming Normal Vectors

Normal vectors are transformed differently than do ordinary points and directions

A normal vector represents the direction pointing out of a surface

A normal vector is perpendicular to the tangent plane

If a matrix M transforms points from one coordinate system to another, then normal vectors must be transformed by (M-1)T

Page 28: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Orderings

Page 29: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Orderings

Orderings of different type is important A rotation followed by a translation is different from a translation followed by a rotation

Orderings of the same type does not matter

Page 30: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Geometry -- Lines

A line in 3D space is represented by

S is a point on the line, and V is the direction along which the line runs

Any point P on the line corresponds to a value of the parameter t

Two lines are parallel if their direction vectors are parallel

t t P S V

Page 31: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Plane

A plane in 3D space can be defined by a normal direction N and a point P

Other points in the plane satisfy

PQ

N

Page 32: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Plane Equation

A plane equation is commonly written

A, B, and C are the components of the normal direction N, and D is given by

for any point P in the plane

Page 33: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Properties of Plane

A plane is often represented by the 4D vector (A, B, C, D)

If a 4D homogeneous point P lies in the plane, then (A, B, C, D) P = 0

If a point does not lie in the plane, then the dot product tells us which side of the plane the point lies on

Page 34: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Distance from Point to a Line

Distance d from a point P to a lineS + t V

P

VS

d

Page 35: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Distance from Point to a Line

Use Pythagorean theorem:

Taking square root,

If V is unit length, then V 2 = 1

Page 36: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Line and Plane Intersection

Let P(t) = S + t V be the line Let L = (N, D) be the plane We want to find t such that L P(t) = 0

Careful, S has w-coordinate of 1, and V has w-coordinate of 0

x x y y z z w

x x y y z z

L S L S L S Lt

L V L V L V

L S

L V

Page 37: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Formular

If L V = 0, the line is parallel to the plane and no intersection occurs

Otherwise, the point of intersection is

t

L S

P S VL V

Page 38: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Real-time Physics in Game at Runtime:

Enables the emergent behavior that provides player a richer game experience

Potential to provide full cost savings to developer/publisher

Difficult May require significant upgrade of game engine May require significant update of asset creation pipelines May require special training for modelers, animators, and

level designers Licensing an existing engine may significantly

increase third party middleware costs

Page 39: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Engines

Commercial Game Dynamics SDK (Havok.com) Renderware Physics (renderware.com) NovodeX SDK (novodex.com)

Free Open Dynamic Engine (ODE) (ode.org) Tokamak Game Physics SDK (tokamakphysics.

com) Newton Game Dynamics SDK (newtondynamics.

com)

Page 40: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Particle Physics

What is a Particle? A sphere of finite radius with a perfectly smooth,

frictionless surface Experiences no rotational motion (or assume the

sphere has no size) Particle Kinematics

Defines the basic properties of particle motion Position, Velocity, Acceleration

Page 41: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Location of Particle in World Space SI Units: meters (m)

Changes over time when object moves

Particle Position

zyx ppp ,,p

Page 42: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Particle Velocity and Acceleration

Velocity (SI units: m/s) First time derivative of position:

Acceleration (SI units: m/s2) First time derivative of velocity Second time derivative of position

)()()(

lim)(0

tdt

d

t

tttt

tp

ppV

)()()(2

2

tdt

dt

dt

dt pVa

Page 43: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Newton’s 2nd Law of Motion

Paraphrased – “An object’s change in velocity is proportional to an applied force”

The Classic Equation:

m = mass (SI units: kilograms, kg) F(t) = force (SI units: Newtons)

tmt aF

Page 44: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

What is Physics Simulation?

The Cycle of Motion: Force, F(t), causes acceleration Acceleration, a(t), causes a change in velocity Velocity, V(t) causes a change in position

Physics Simulation:Solving variations of the above equations over time to emulate the cycle of motion

Page 45: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Concrete Example: Target Practice

F = w eig ht = m gTarget

Projectile LaunchPosition, pinit

Page 46: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Choose Vinit to Hit a Stationary Target ptarget is the stationary target location We would like to choose the initial velocity, Vinit, required to hi

t the target at some future time, thit. Here is our equation of motion at time thit:

Target Practice

22

1inithitinithitinitinittarget tttt gVpp

Page 47: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Equation Problem

Solution in general is a bit tedious to derive…

Infinite number of solutions! Hint: Specify the magnitude of Vinit, sol

ve for its direction

Page 48: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

969.31

Example 1

Vinit = 25 m/sValue of Radicand of tan equation:Launch angle : 19.4 deg or 70.6 deg

0.00

5.00

10.00

15.00

20.00

25.00

30.00

35.00

40.00

45.00

0.00 20.00 40.00 60.00

Horizontal Position (m)

Ver

tica

l P

osi

tio

n (

m) Projectile Launch

Position

Target Position

Trajectory 1 - HighAngle, Slow Arrival

Trajectory 2 - LowAngle, Fast Arrival

Page 49: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Finite Difference Methods-I

The Explicit Euler Integrator:

Properties of object are stored in a state vector, S Use the above integrator equation to incrementally update S over

time as game progresses Must keep track of prior value of S in order to compute the new For Explicit Euler, one choice of state and state derivative for particle:

)( 2

derivative statestateprior statenew

tOtdt

dtttt

SSS

pVS ,m VFS ,dtd

Page 50: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Finite Difference Methods-II

The Verlet Integrator:

Must store state at two prior time steps, S(t) and S(t-t) Uses second derivative of state instead of the first Valid for constant time step only (as shown above) For Verlet, choice of state and state derivative for a particle:

pS aFS mdtd /22

derivative state

2

22

2 stateprior 1 stateprior state new

)(2

t

dt

dtttttt SSSS

Page 51: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Errors

Exact

Euler

Page 52: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Generalized Rigid Bodies

Key Differences from Particles Not necessarily spherical in shape Position, p, represents object’s center-of-mass location Surface may not be perfectly smooth and friction forces

may be present Experience rotational motion in addition to translational

(position only) motion

Center of Mass

worldX

worldZ

objectX

objectZ

Page 53: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Additional forces

Linear Spring Viscous Damping Aerodynamic Drag Friction …

Page 54: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Linear Springs

dllkF restspring )(

Page 55: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Viscous Damping

ddVVcF epepdamping ))(( 12

Page 56: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Aerodynamic Drag

S: projected front area

CD: drag coefficient

Page 57: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Friction

Page 58: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Collision Detection and Resolution

Page 59: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

What is Collision Detection

A fundamental problem in computer games, computer animation, physically-based modeling, geometric modeling, and robotics.

Including algorithms: To check for collision, i.e. intersection, of

two given objects To calculate trajectories, impact times and

impact points in a physical simulation.

Page 60: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Collision Detection

Complicated for two reasons Geometry is typically very complex, potentially

requiring expensive testing Naïve solution is O(n2) time complexity, since

every object can potentially collide with every other object

Two basic techniques Overlap testing: Detects whether a collision has

already occurred Intersection testing: Predicts whether a collision

will occur in the future

Page 61: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Overlap Testing (a posteriori)

Overlap testing: Detects whether a collision has already occurred, sometime is referred as a posteriori

Facts Most common technique used in games Exhibits more error than intersection testing

Concept For every (small) simulation step, test every pair

of objects to see if they overlap Easy for simple volumes like spheres, harder for

polygonal models

Page 62: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Overlap Testing Results

Useful results of detected collision Pairs of objects will have collision Time of collision to take place Collision normal vector

Collision time calculated by moving object back in time until right before collision Bisection is an effective technique

Page 63: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Bisect Testing: collision detected

B B

t1

t0.375

t0.25

B

t0

I te r a tio n 1F o r w ar d 1 /2

I te r a tio n 2Bac k w ar d 1 /4

I te r a tio n 3F o r w ar d 1 /8

I te r a tio n 4F o r w ar d 1 /1 6

I te r a tio n 5Bac k w ar d 1 /3 2

I n itia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Page 64: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Bisect Testing: Iteration I

B B

t1

t0.375

t0.25

B

t0

I te r a tio n 1F o r w ar d 1 /2

I te r a tio n 2Bac k w ar d 1 /4

I te r a tio n 3F o r w ar d 1 /8

I te r a tio n 4F o r w ar d 1 /1 6

I te r a tio n 5Bac k w ar d 1 /3 2

I n itia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Page 65: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Bisect Testing: Iteration II

B B

t1

t0.375

t0.25

B

t0

I te r a tio n 1F o r w ar d 1 /2

I te r a tio n 2Bac k w ar d 1 /4

I te r a tio n 3F o r w ar d 1 /8

I te r a tio n 4F o r w ar d 1 /1 6

I te r a tio n 5Bac k w ar d 1 /3 2

I n itia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Page 66: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Bisect Testing: Iteration III

B B

t1

t0.375

t0.25

B

t0

I te r a tio n 1F o r w ar d 1 /2

I te r a tio n 2Bac k w ar d 1 /4

I te r a tio n 3F o r w ar d 1 /8

I te r a tio n 4F o r w ar d 1 /1 6

I te r a tio n 5Bac k w ar d 1 /3 2

I n itia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Page 67: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Bisect Testing: Iteration IV

B B

t1

t0.375

t0.25

B

t0

I te r a tio n 1F o r w ar d 1 /2

I te r a tio n 2Bac k w ar d 1 /4

I te r a tio n 3F o r w ar d 1 /8

I te r a tio n 4F o r w ar d 1 /1 6

I te r a tio n 5Bac k w ar d 1 /3 2

I n itia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Page 68: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Bisect Testing: Iteration V

B B

t1

t0.375

t0.25

B

t0

I te r a tio n 1F o r w ar d 1 /2

I te r a tio n 2Bac k w ar d 1 /4

I te r a tio n 3F o r w ar d 1 /8

I te r a tio n 4F o r w ar d 1 /1 6

I te r a tio n 5Bac k w ar d 1 /3 2

I n itia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Time right before the collision

Page 69: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Overlap Testing: Limitations

Fails with objects that move too fast Thin glass vs. bulltes Unlikely to catch time slice during overlap

t0t -1 t1 t2

b u lle t

w in d o w

Page 70: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Solution for This Limitation

Speed of the fastest object multiplies the time step should be smaller than the smallest objects in the scene

Possible solutions Design constraint on speed of objects: ha

rd to apply without affecting the play Reduce simulation step size: too expensi

ve

Page 71: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Intersection Testing (a priori)

Predict future collisions When predicted:

Move simulation to time of collision Resolve collision Simulate remaining time step

Page 72: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Intersection Testing:Swept Geometry

Extrude geometry in direction of movement Swept sphere turns into a “capsule” shape

t0

t1

Page 73: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Intersection Testing:Sphere-Sphere Collision

Q 1

Q 2

P 1

P 2

P

Q

t= 0

t= 0

t= 1

t= 1

t

,

2

2222

B

rrΑBt

QP

BAΒΑ .QQPPB

QPA

1212

11

d

Page 74: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Special Cases

No collision:

B2 = 0: both objects are stationary, or they are traveling at parallel

When will collision occur?

02222 QP rrΑBBA

02222 QP rrΑBBA

Page 75: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Intersection Testing:When to Collide

Smallest distance ever separating two spheres:

If

there is a collision

2

222

BAd

BA

22QP rrd

Page 76: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Intersection Testing:Limitations

Issue with networked games Future predictions rely on exact state of

world at present time Due to packet latency, current state not

always coherent Assumes constant velocity and zero

acceleration over simulation step Has implications for physics model and

choice of integrator

Page 77: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Dealing with Complexity

Two issues1. Complex geometry must be simplified

2. Reduce number of object pair tests

Page 78: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Simplified Geometry

Approximate complex objects with simpler geometry, like this ellipsoid or bounding boxes

Page 79: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Minkowski Sum

By taking the Minkowski Sum of two complex volumes and creating a new volume, overlap can be found by testing if a single point is within the new volume

Page 80: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Minkowski Sum

Y}B and :{ XABAYX

X Y =YX X Y =

Page 81: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Using Minkowski Sum

t0

t1

t0

t1

Page 82: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Bounding Volumes

Bounding volume is a simple geometric shape Completely encapsulates object If no collision with bounding volume, no

more testing is required Common bounding volumes

Sphere Box

Page 83: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Box Bounding Volumes

Ax is - Alig n ed Bo u n d in g Bo x O r ien ted Bo u n d in g Bo x

Page 84: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

More Examples

Page 85: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Using Bounding Box in Game

Complex objects can have multiple bounding boxes Human object can have one big bounding box

for the whole body Human object can have one bounding box per

limb, head, etc Bounding box can be hierarchical:

Test the big first if possible collision, test the smaller ones

Page 86: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Reduce Number of Detections

O(n) Time Complexity can be achieved.

One solution is to partition space

Page 87: CSCE 552 Spring 2009 Math, Physics and Collision Detection By Jijun Tang

Achieving O(n) Time Complexity

Another solution is the plane sweep algorithm

Requires (re-)sorting in x (y) coordinate

C

B

R

A

x

y

A 0 A 1 R 0 B0 R 1 C 0 C 1B1

B0

B1A 1

A 0

R 1

R 0

C 1

C 0