Docsity

Ray-Sphere Intersection and Ellipsoid Intersection Algorithms, Study notes of Computer Science

Toggle sidebar
bg1
J. Ross Beveridge, January 28, 1999
CS510 - Computer Graphics, Spring 1999
CS510 - Computer Graphics, Spring 1999 Page:4-1
Ray Tracing Intersections
wRay-to-Surface Intersection Calculations are Key.
wAlgorithms tied to surface type.
ŸSphere
ŸEllipse
ŸCylinder
ŸCone
ŸConvex Polygon
ŸGeneral Polygon
ŸBicubic Surfaces
wFirst pass: General Mathematics
wSecond pass: Highly Optimized Codes
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Ray-Sphere Intersection and Ellipsoid Intersection Algorithms and more Study notes Computer Science in PDF only on Docsity!

^ J. Ross Beveridge, January 28, 1999

Ray Tracing Intersections

w^

Ray-to-Surface Intersection Calculations are Key. w^

Algorithms tied to surface type.^ ü Sphere ü Ellipse ü Cylinder ü Cone ü Convex Polygon ü General Polygon ü Bicubic Surfaces w^

First pass:

General Mathematics

w^

Second pass:

Highly Optimized Codes

^ J. Ross Beveridge, January 28, 1999

Representing a Ray (Hearn)

w^

Defined by a point and a unit vector. w^

The point may be the PRP, w^

It may be the pixel. w^

P If it is the PRP, then ...

P^

sU

=^

U

P^

P

P^

P

pix

prp

pix

prp

=^

^ J. Ross Beveridge, January 28, 1999

Sphere Intersection Continued

w^

Expand to see what is happening. Let

=T

x^ c^

x^0 − y^ c^

y^0 − zc^

z^0 = −

s

u^ x u^ y uz

t^ x t^ y t^ z

s

u^ x u^ y uz

t^ x t^ y t^ z

(^2) r

W W

r ⋅^

−^

2 =^0

W

s u

x^

t^ x − s u

y^

t^ y − s uz

t^ z

+^

+^

(^

s u

x^

t^ x^

2

(^

s u

y^

t^ y^

2

(^

s uz

t^ z^

2

(^2) r

^ J. Ross Beveridge, January 28, 1999

Sphere Intersection Continued

w^

After multiplying out, expand and collect s terms.

(^

+^

u^ x 2

(^2) uz

u^ y 2

(^2) s

(^

−^

−^

2 t

uy^

y^

2 t

ux^

x^

2 t

uzz^

s

−^

+^

(^2) t x

(^2) r

(^2) t z

(^2) t y

w^

Which may more simply be written as:^ s

U T s

T^

r

2

2

2

−^

(^

−^

^ J. Ross Beveridge, January 28, 1999

Actual Sphere Intersection Points w^

Compute the two

s^

values for the two intersections:

s^

U T

U T

T^

r

s^

U T

U T

T^

r

1

2

2

2

2

2

2

2

(^

(^

(^

(^

9 multiplies/squares6 additions1 square root

w^

Compute the actual positions along the ray:^ s^

s^

s

P^

P^

s U

  • *^

min(

= =^

1

2

0

3 multiplies/squares3 additions1 min

^ J. Ross Beveridge, January 28, 1999

Representing a Ray (Foley)

w^

Defined by two points, P

and P 0

P t

P^

t P

P

x t y t z t

x^

t x

x

y^

t y

y

z^

t z

z

o^

o

o^

o

o^

o

+^

(^

+^

(^

+^

(^

+^

(^

0

1

0

(^111)

w^

Advantages:^ ü Easier to carry two points between coordinates. ü More general for intersection computaions.

^ J. Ross Beveridge, January 28, 1999

More on Spheres

w^

Closest point based upon

t^ values.

w^

Example of ray intersection with a sphere..

r C

r R

√ R

d^

C R D^

dR C

b^

D

a^

b^

r^

a^

r^

b

P^

d^

a R =^ i

⋅

(^

=^

−^

=

+^

=^

⇒^

=^

−

=^

−(

) r r^

r^

r

√^ , √

√

2

2

2

2

2

r D a

d^

a − (^

)^

r

3 multiplies, 2 additions3 multiplies, 3 additions3 multiplies, 2, additions, 1 root1 multiply, 1 addition, 1 root3 multiplies, 1 additions.

^ J. Ross Beveridge, January 28, 1999

Charlie’s Method

w^

Simplify by recognizing some similar triangles.

r C

r R

BySimilar Triangles

and

Solve for

whereand

v^

b^

c^

a^

b^

r

t

t^

v^

a^

v^

C R

a^

r^

b^

t^

v^

r^

b

b^

c^

v^

t^

v^

r^

c^

v

c^

C C

t^

v^

r^

C C

v

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2

+^

=^

+^

=

=^

−^

=^

⋅

=^

−^

⇒^

=^

−^

−

=^

−^

⇒^

=^

−^

−^

−

(^

=^

⋅^

⇒^

=^

−^

−^

⋅^

−

(^

r^

r

r^

r^

r^

r

d a

c^

C C =^

r^ r ⋅

r

7 multiplies, 6 additions, 1 square root

t

v

^ J. Ross Beveridge, January 28, 1999

Ellipsoids - Change the World

w^

An alternative, and arguably better way is to transform theray into a world in which the ellipsoid is a shere.

(^

′^

P^

t^

P^

t P

P

P^

M P

M

k^

x

l^

y m^

z

i^

i

c c c

0

1

0 1

w^

The equation of the Ellipsoid is now transformed:

+^

+^

k^ (

−x x

(^2) c

l^ (

−y y

(^2) c

m^

(^

−z z

(^2) c

(^2) r

+^

+^

(^

x^0

t dx

(^2)

(^

y^0

t dy

(^2)

(^

z^0

t dz

(^2)

(^2) r

^ J. Ross Beveridge, January 28, 1999

Intersect a Polygon Face

w^

For polygonal objects there are two parts.^ ü Find point of intersection P on infinite plane. ü Is point P inside polygon. w^

General equation for a plane in 3D:^ N

P

N^

P

⋅^

−^

=^

⋅^

+^

+^

n^ x^

(^

x^0

t dx

n^ y^

(^

y^0

t dy

nz^

(^

z^0

t dz

ρ^

+^

+^

+^

(^

+^

n^ x^

dx

n^ y^

dy

nz^

dz

t

n^ x^

x^0

n^ y^

y^0

nz^

z^0

ρ^

=−t

+^

+^

n^ x^

x^0

n^ y^

y^0

nz^

z^0

ρ

+^

n^ x^

dx

n^ y^

dy

nz^

dz

t^

N^

P

N^

P^

P

=^

⋅^

⋅^

(^

0 1

ρ^0