• No results found

3D Rendering and Ray Casting

N/A
N/A
Protected

Academic year: 2021

Share "3D Rendering and Ray Casting"

Copied!
69
0
0

Loading.... (view fulltext now)

Full text

(1)

3D Rendering and Ray Casting

Michael Kazhdan (601.457/657)

HB Ch. 13.7, 14.6 FvDFH 15.5, 15.10

(2)

Rendering

• Generate an image from geometric primitives

Geometric Primitives (3D)

(3)

Rendering

• Generate an image from geometric primitives

Rendering

Geometric

Primitives (3D)

Raster Image (2D)

(4)

3D Rendering Example

What issues must be addressed by a 3D rendering system?

(5)

Overview

• 3D scene representation • 3D viewer representation • What do we see?

(6)

Overview

• 3D scene representation • 3D viewer representation • What do we see?

• How does it look?

How is the 3D scene described in a computer?

(7)

3D Scene Representation

• Scene is usually approximated by 3D primitives

 Point  Line segment  Triangles  Polygon  Polyhedron  Curved surface  Solid object  etc.

(8)

3D Point

• Specifies a location

(9)

3D Point

• Specifies a location

 Represented by three coordinates

 Infinitely small struct Point3D { float x , y , z; }; (𝑥𝑥,𝑦𝑦,𝑧𝑧) Origin

(10)

3D Vector

(11)

3D Vector

• Specifies a direction and a magnitude

 Represented by three coordinates

 Magnitude ⃗𝑣𝑣 = 𝑑𝑑𝑥𝑥2 + 𝑑𝑑𝑦𝑦2 + 𝑑𝑑𝑧𝑧2  Has no location ⃗𝑣𝑣 = (𝑑𝑑𝑥𝑥,𝑑𝑑𝑦𝑦,𝑑𝑑𝑧𝑧) struct Vector3D { float dx , dy , dz; };

(12)

• Specifies a direction and a magnitude

 Represented by three coordinates

 Magnitude ⃗𝑣𝑣 = 𝑑𝑑𝑥𝑥2 + 𝑑𝑑𝑦𝑦2 + 𝑑𝑑𝑧𝑧2

 Has no location

• Dot product of two 3D vectors

 ⃗𝑣𝑣1, ⃗𝑣𝑣2 = 𝑑𝑑𝑥𝑥1 ⋅ 𝑑𝑑𝑥𝑥2 + 𝑑𝑑𝑦𝑦1 ⋅ 𝑑𝑑𝑦𝑦2 + 𝑑𝑑𝑧𝑧1 ⋅ 𝑑𝑑𝑧𝑧2  ⃗𝑣𝑣1, ⃗𝑣𝑣2 = ⃗𝑣𝑣1 ⋅ ⃗𝑣𝑣2 ⋅ cos 𝜃𝜃

• Cross product of two 3D vectors

 ⃗𝑣𝑣1 × ⃗𝑣𝑣2 = Vector normal to 𝑣𝑣1 and 𝑣𝑣2

 ⃗𝑣𝑣1 × ⃗𝑣𝑣2 = ⃗𝑣𝑣1 ⋅ ⃗𝑣𝑣2 ⋅ sin 𝜃𝜃

3D Vector

⃗𝑣𝑣1 = (𝑑𝑑𝑥𝑥1, 𝑑𝑑𝑦𝑦1,𝑑𝑑𝑧𝑧1) ⃗𝑣𝑣2 = (𝑑𝑑𝑥𝑥2,𝑑𝑑𝑦𝑦2,𝑑𝑑𝑧𝑧2) 𝜃𝜃

(13)

Cross Product: Review

• Let ⃗𝑣𝑣1 = ⃗𝑣𝑣2 × ⃗𝑣𝑣3:

 𝑑𝑑𝑥𝑥1 = 𝑑𝑑𝑦𝑦2 ⋅ 𝑑𝑑𝑧𝑧3 − 𝑑𝑑𝑧𝑧2 ⋅ 𝑑𝑑𝑦𝑦3  𝑑𝑑𝑦𝑦1 = 𝑑𝑑𝑧𝑧2 ⋅ 𝑑𝑑𝑥𝑥3 − 𝑑𝑑𝑥𝑥2 ⋅ 𝑑𝑑𝑧𝑧3  𝑑𝑑𝑧𝑧1 = 𝑑𝑑𝑥𝑥2 ⋅ 𝑑𝑑𝑦𝑦3 − 𝑑𝑑𝑦𝑦2 ⋅ 𝑑𝑑𝑥𝑥3

• ⃗𝑣𝑣 × 𝑤𝑤 = −𝑤𝑤 × ⃗𝑣𝑣 (remember “right-hand” rule) • We can show:

 ⃗𝑣𝑣 × 𝑤𝑤 = ⃗𝑣𝑣 ⋅ 𝑤𝑤 ⋅ sin 𝜃𝜃 ⋅ 𝑛𝑛,

where 𝑛𝑛 is the unit vector normal to ⃗𝑣𝑣 and 𝑤𝑤

(14)

3D Line Segment

• Linear path between two points

(15)

3D Line Segment

• Use a linear combination of two points

 Parametric representation: » 𝑝𝑝 𝑡𝑡 = 𝑝𝑝1 + 𝑡𝑡 ⋅ (𝑝𝑝2 − 𝑝𝑝1), (0 ≤ 𝑡𝑡 ≤ 1) struct Segment3D { Point3D p1 , p2; }; 𝑝𝑝1 𝑝𝑝2 Origin

(16)

3D Ray

• Line segment with one endpoint at infinity

 Parametric representation: » 𝑝𝑝 𝑡𝑡 = 𝑝𝑝1 + 𝑡𝑡 ⋅ ⃗𝑣𝑣, (0 ≤ 𝑡𝑡 < ∞) 𝑝𝑝1 ⃗𝑣𝑣 Origin struct Ray3D { Point3D p1; Vector3D v; };

(17)

3D Line

• Line segment with both endpoints at infinity

 Parametric representation: » 𝑝𝑝 𝑡𝑡 = 𝑝𝑝1 + 𝑡𝑡 ⋅ ⃗𝑣𝑣, (−∞ < 𝑡𝑡 < ∞) 𝑝𝑝1 struct Line3D { Point3D p1; Vector3D v; }; ⃗𝑣𝑣 Origin

(18)

Origin

3D Plane

• A linear combination of three points

𝑝𝑝1

𝑝𝑝3 𝑝𝑝2

(19)

Origin

3D Plane

• A linear combination of three points

 Implicit representation:

» Φ 𝑝𝑝 = 𝑎𝑎𝑥𝑥 + 𝑏𝑏𝑦𝑦 + 𝑐𝑐𝑧𝑧 − 𝑑𝑑 = 0

» Φ 𝑝𝑝 = 𝑝𝑝, 𝑛𝑛 − 𝑑𝑑 = 0

 𝑛𝑛 is the plane normal

» (May be) unit-length vector » Perpendicular to plane

 𝑑𝑑 is the signed (weighted) distance

of the plane from the origin.

struct Plane3D { Vector3D n; float d; }; 𝑛𝑛 = (𝑎𝑎,𝑏𝑏,𝑐𝑐) 𝑑𝑑 𝑝𝑝1 𝑝𝑝3 𝑝𝑝2

(20)

3D Polygon

• Area “inside” a sequence of coplanar points

 Triangle  Quadrilateral  Convex  Star-shaped  Concave  Self-intersecting

 Holes (use > 1 polygon struct)

struct Polygon3D {

Point3D *points; int npoints;

};

(21)

3D Sphere

• All points at distance 𝑟𝑟 from center point 𝑐𝑐 = (𝑐𝑐𝑥𝑥, 𝑐𝑐𝑦𝑦, 𝑐𝑐𝑧𝑧)

 Implicit representation: » Φ 𝑝𝑝 = 𝑝𝑝 − 𝑐𝑐 2 − 𝑟𝑟2 = 0  Parametric representation: » 𝑥𝑥 𝜙𝜙, 𝜃𝜃 = 𝑟𝑟 ⋅ cos 𝜙𝜙 ⋅ sin𝜃𝜃 + 𝑐𝑐𝑥𝑥 » 𝑦𝑦 𝜙𝜙, 𝜃𝜃 = 𝑟𝑟 ⋅ cos 𝜙𝜙 ⋅ sin 𝜃𝜃 + 𝑐𝑐𝑦𝑦 » 𝑧𝑧 𝜃𝜃, 𝜙𝜙 = 𝑟𝑟 ⋅ sin𝜙𝜙 + 𝑐𝑐𝑧𝑧 struct Sphere3D { Point3D center; float radius; }; 𝑟𝑟 Origin 𝑐𝑐

(22)

Other 3D primitives

• Cone • Cylinder • Ellipsoid • Box • Etc.
(23)

3D Geometric Primitives

• More detail on 3D modeling later in course

 Point  Line segment  Triangle  Polygon  Polyhedron  Curved surface  Solid object  etc.

(24)

Overview

• 3D scene representation • 3D viewer representation • What do we see?

• How does it look?

How is the viewing device described in a computer?

(25)

Camera Models

• The most common model is pin-hole camera

 All captured light rays arrive along paths toward focal point without lens distortion (everything is in focus)

Other models consider ... Depth of field Motion blur Lens distortion View plane Eye position (focal point)

(26)

Camera Parameters

(27)

Camera Parameters

right back Up direction Eye Position View Plane “Look at” Point • Position

 Eye position: Point3D eye

• Orientation

 View direction: Vector3D view

 Up direction: Vector3D up

• Aperture

 Field of view angle: float xFov , yFov

 Resolution of film plane: int width , height

 Distance of film plane

(28)

Other Models: Depth of Field

Close Focused Distance Focused

(29)

Other Models: Motion Blur

Brostow & Essa

• Mimics effect of open camera shutter

• Gives perceptual effect of high-speed motion • Generally involves temporal super-sampling

(30)

Traditional Pinhole Camera

• The film sits behind the pinhole of the camera.

• Rays come in from the outside, pass through the pinhole, and hit the film plane.

(31)

Traditional Pinhole Camera

• The film sits behind the pinhole of the camera.

• Rays come in from the outside, pass through the pinhole, and hit the film plane.

Film Plane Pinhole

(32)

Virtual Camera

• The film sits in front of the pinhole of the camera. • Rays come in from the outside, pass through the

film plane, and hit the pinhole.

Film Plane Pinhole

(33)

Virtual Camera

• The film sits in front of the pinhole of the camera. • Rays come in from the outside, pass through the

film plane, and hit the pinhole.

Film Plane Pinhole

(34)

Overview

• 3D scene representation • 3D viewer representation • Ray Casting

 Where are we looking?

 What do we see?

(35)

Ray Casting

• For each sample …

 Where: Construct ray from eye through view plane

 What: Find first surface intersected by ray through pixel

(36)

Ray Casting

• Simple implementation:

Image RayCast( Camera camera , Scene scene , int width , int height) {

Image image = new Image( width , height );

for( int i=0 ; i<width ; i++ ) for( int j=0 ; j<height ; j++ ) {

Ray ray = ConstructRayThroughPixel( camera , i , j );

Intersection hit = FindIntersection( ray , scene ); image[i][j] = GetColor( hit );

}

return image; }

(37)

Ray Casting

Where?

Image RayCast( Camera camera , Scene scene , int width , int height) {

Image image = new Image( width , height );

for( int i=0 ; i<width ; i++ ) for( int j=0 ; j<height ; j++ ) {

Ray ray = ConstructRayThroughPixel( camera , i , j );

Intersection hit = FindIntersection( ray , scene ); image[i][j] = GetColor( hit );

}

return image; }

(38)

Constructing a Ray Through a Pixel

right back Up direction 𝒑𝒑𝟎𝟎 View Plane 𝒗𝒗 𝒑𝒑 𝒊𝒊 [𝒋𝒋]
(39)

Constructing a Ray Through a Pixel

right back

Up direction View

Plane

The ray originates at 𝑝𝑝0 (the position of the camera).

So the equation for the ray is:

Ray 𝑡𝑡 = 𝑝𝑝0 + 𝑡𝑡 ⋅ ⃗𝑣𝑣

𝒑𝒑𝟎𝟎

𝒗𝒗

(40)

Constructing a Ray Through a Pixel

right back

Up direction View

Plane

If the ray passes through the point

𝑝𝑝 𝑖𝑖 [𝑗𝑗], then the solution for ⃗𝑣𝑣 is:

⃗𝑣𝑣 = 𝑝𝑝 𝑖𝑖 [𝑗𝑗]−𝑝𝑝0

𝑝𝑝 𝑖𝑖 [𝑗𝑗]−𝑝𝑝0

𝒑𝒑𝟎𝟎

𝒗𝒗

(41)

Constructing a Ray Through a Pixel

right back

Up direction View

Plane

If 𝑝𝑝 𝑖𝑖 [𝑗𝑗] represents the (𝑖𝑖, 𝑗𝑗)-th pixel of the image, what is its position?

𝒑𝒑𝟎𝟎

𝒗𝒗

(42)

Constructing Ray Through a Pixel

• 2D Example: Side view of camera at 𝑝𝑝0

 Where is the 𝑖𝑖-th pixel, 𝑝𝑝[𝑖𝑖]? (𝑖𝑖 ∈ [0, height))

𝑑𝑑

towards 𝑝𝑝0

up 𝜃𝜃 = field of view angle (given)

𝑑𝑑 = distance to view plane (arbitrary = you pick)

(43)

Constructing Ray Through a Pixel

• 2D Example: Side view of camera at 𝑝𝑝0

 Where is the 𝑖𝑖-th pixel, 𝑝𝑝[𝑖𝑖]? (𝑖𝑖 ∈ [0, height))

𝑝𝑝2 𝑝𝑝1 2 ⋅𝑑𝑑 ⋅ tan 𝜃𝜃 /2

𝜃𝜃 = field of view angle (given)

𝑑𝑑 = distance to view plane (arbitrary = you pick) 𝑝𝑝1 = 𝑝𝑝0 + 𝑑𝑑 ⋅ towards − 𝑑𝑑 ⋅ tan𝜃𝜃2 ⋅ up 𝑝𝑝2 = 𝑝𝑝0 + 𝑑𝑑 ⋅ towards + 𝑑𝑑 ⋅ tan𝜃𝜃2 ⋅ up 𝑑𝑑 towards 𝑝𝑝0 up 𝜃𝜃

(44)

Constructing Ray Through a Pixel

• 2D Example: Side view of camera at 𝑝𝑝0

 Where is the 𝑖𝑖-th pixel, 𝑝𝑝[𝑖𝑖]? (𝑖𝑖 ∈ [0, height))

𝑝𝑝 𝑖𝑖 = 𝑝𝑝1 + 𝑖𝑖height+ 0.5 ⋅ 𝑝𝑝2 − 𝑝𝑝1 𝜃𝜃 = field of view angle (given)

𝑑𝑑 = distance to view plane (arbitrary = you pick) 𝑝𝑝1 = 𝑝𝑝0 + 𝑑𝑑 ⋅ towards − 𝑑𝑑 ⋅ tan𝜃𝜃2 ⋅ up 𝑝𝑝2 = 𝑝𝑝0 + 𝑑𝑑 ⋅ towards + 𝑑𝑑 ⋅ tan𝜃𝜃2 ⋅ up 𝑝𝑝2 𝑝𝑝1 𝑑𝑑 towards 𝑝𝑝0 up 𝑝𝑝[𝑖𝑖] 𝜃𝜃 2 ⋅𝑑𝑑 ⋅ tan 𝜃𝜃 /2

(45)

Constructing Ray Through a Pixel

• 2D Example:

The ray passing through the 𝑖𝑖-th pixel is defined by:

Ray 𝑡𝑡 = 𝑝𝑝0 + 𝑡𝑡 ⋅ ⃗𝑣𝑣

 𝑝𝑝0: camera position

 ⃗𝑣𝑣: direction to the 𝑖𝑖-th pixel:

⃗𝑣𝑣 = 𝑝𝑝 𝑖𝑖 − 𝑝𝑝𝑝𝑝 𝑖𝑖 − 𝑝𝑝0

0  𝑝𝑝[𝑖𝑖]: 𝑖𝑖-th pixel location:

𝑝𝑝 𝑖𝑖 = 𝑝𝑝1 + 𝑖𝑖height+ 0.5 ⋅ 𝑝𝑝2 − 𝑝𝑝1

 𝑝𝑝1 and 𝑝𝑝2 are the endpoints of the view plane:

𝑝𝑝1 = 𝑝𝑝0 + 𝑑𝑑 ⋅ towards − 𝑑𝑑 ⋅ tan𝜃𝜃/2 ⋅ up 𝑝𝑝2 = 𝑝𝑝0 + 𝑑𝑑 ⋅ towards + 𝑑𝑑 ⋅ tan𝜃𝜃/2 ⋅ up 𝑝𝑝2 𝑝𝑝1 𝑑𝑑 towards 𝑝𝑝0 up 𝑝𝑝[𝑖𝑖] 𝜃𝜃 2 ⋅𝑑𝑑 ⋅ tan 𝜃𝜃 /2

(46)

Constructing Ray Through a Pixel

(47)

Constructing Ray Through a Pixel

Figuring out how to do this in 3D is assignment 2 Note:

 Given the vertical field of view angle, 𝜃𝜃𝑣𝑣

(48)

Constructing Ray Through a Pixel

Figuring out how to do this in 3D is assignment 2 Note:

 Given the vertical field of view angle, 𝜃𝜃𝑣𝑣

 And the aspect ratio, 𝑎𝑎𝑟𝑟 = ℎ𝑒𝑒𝑖𝑖𝑒𝑒ℎ𝑒𝑒

𝑤𝑤𝑖𝑖𝑤𝑤𝑒𝑒ℎ

(49)

Constructing Ray Through a Pixel

Figuring out how to do this in 3D is assignment 2 Note:

 Given the vertical field of view angle, 𝜃𝜃𝑣𝑣

 And the aspect ratio, 𝑎𝑎𝑟𝑟 = ℎ𝑒𝑒𝑖𝑖𝑒𝑒ℎ𝑒𝑒

𝑤𝑤𝑖𝑖𝑤𝑤𝑒𝑒ℎ

The horizontal field of view angle, 𝜃𝜃, satisfies:

tan 𝜃𝜃𝑣𝑣/2

tan 𝜃𝜃/2 = 𝑎𝑎𝑟𝑟

𝜽𝜽𝒉𝒉 𝜽𝜽𝒗𝒗

(50)

Ray Casting

Where?

Image RayCast( Camera camera , Scene scene , int width , int height) {

Image image = new Image( width , height );

for( int i=0 ; i<width ; i++ ) for( int j=0 ; j<height ; j++ ) {

Ray ray = ConstructRayThroughPixel( camera , i , j );

Intersection hit = FindIntersection( ray , scene ); image[i][j] = GetColor( hit );

}

return image; }

(51)

Ray Casting

What?

Image RayCast( Camera camera , Scene scene , int width , int height) {

Image image = new Image( width , height );

for( int i=0 ; i<width ; i++ ) for( int j=0 ; j<height ; j++ ) {

Ray ray = ConstructRayThroughPixel( camera , i , j );

Intersection hit = FindIntersection( ray , scene ); image[i][j] = GetColor( hit );

}

return image; }

(52)

Ray-Scene Intersection

• Intersections with geometric primitives

 Sphere

(53)

Ray-Sphere Intersection

Ray: 𝑝𝑝 𝑡𝑡 = 𝑝𝑝0 + 𝑡𝑡 ⋅ ⃗𝑣𝑣, (0 ≤ 𝑡𝑡 < ∞) Sphere: Φ 𝑝𝑝 = 𝑝𝑝 − 𝑐𝑐 2 − 𝑟𝑟2 = 0 𝑝𝑝0 𝒗𝒗 𝑐𝑐 𝑝𝑝 𝑟𝑟 𝑝𝑝′
(54)

Ray-Sphere Intersection

Ray: 𝑝𝑝 𝑡𝑡 = 𝑝𝑝0 + 𝑡𝑡 ⋅ ⃗𝑣𝑣, (0 ≤ 𝑡𝑡 < ∞)

Sphere: Φ 𝑝𝑝 = 𝑝𝑝 − 𝑐𝑐 2 − 𝑟𝑟2 = 0

Substituting for 𝑝𝑝, we get:

Φ 𝑡𝑡 = 𝑝𝑝0 + 𝑡𝑡 ⋅ ⃗𝑣𝑣 − 𝑐𝑐 2 − 𝑟𝑟2 = 0

Solve quadratic equation:

𝑎𝑎 ⋅ 𝑡𝑡2 + 𝑏𝑏 ⋅ 𝑡𝑡 + 𝑐𝑐 = 0 where: 𝑎𝑎 = 1 𝑏𝑏 = 2 ⃗𝑣𝑣, 𝑝𝑝0 − 𝑐𝑐 𝑐𝑐 = 𝑝𝑝0 − 𝑐𝑐 2 − 𝑟𝑟2 𝑝𝑝0 𝒗𝒗 𝑐𝑐 𝑝𝑝 𝑟𝑟 𝑝𝑝𝑝

(55)

Ray-Sphere Intersection

Ray: 𝑝𝑝 𝑡𝑡 = 𝑝𝑝0 + 𝑡𝑡 ⋅ ⃗𝑣𝑣, (0 ≤ 𝑡𝑡 < ∞)

Sphere: Φ 𝑝𝑝 = 𝑝𝑝 − 𝑐𝑐 2 − 𝑟𝑟2 = 0

Substituting for 𝑝𝑝, we get:

Φ 𝑡𝑡 = 𝑝𝑝0 + 𝑡𝑡 ⋅ ⃗𝑣𝑣 − 𝑐𝑐 2 − 𝑟𝑟2 = 0

Solve quadratic equation:

𝑎𝑎 ⋅ 𝑡𝑡2 + 𝑏𝑏 ⋅ 𝑡𝑡 + 𝑐𝑐 = 0 where: 𝑎𝑎 = 1 𝑏𝑏 = 2 ⃗𝑣𝑣, 𝑝𝑝0 − 𝑐𝑐 𝑐𝑐 = 𝑝𝑝0 − 𝑐𝑐 2 − 𝑟𝑟2 𝑝𝑝0 𝒗𝒗 𝑐𝑐 𝑝𝑝 𝑟𝑟 𝑝𝑝𝑝

Generally, there are two solutions to the quadratic equation, giving two points of intersection, 𝑝𝑝 and 𝑝𝑝𝑝.

(56)

Ray-Sphere Intersection

𝑝𝑝0 ⃗𝑣𝑣 𝑐𝑐 𝑝𝑝 𝑟𝑟 𝑛𝑛

• Need normal vector at intersection for lighting calculations:

(57)

Ray-Sphere Intersection

• More generally, if the shape is given as the set of points 𝑝𝑝 satisfying:

Φ 𝑝𝑝 = 0

for some function Φ: ℝ3 → ℝ, then the normal of the surface will be parallel to the gradient.

(58)

Ray-Scene Intersection

• Intersections with geometric primitives

 Sphere

(59)

Ray-Triangle Intersection

1. Intersect ray with plane

2. Check if the point is inside the triangle

𝑝𝑝

𝑝𝑝0 ⃗𝑣𝑣

(60)

Ray-Plane Intersection

Ray: 𝑝𝑝 𝑡𝑡 = 𝑝𝑝0 + 𝑡𝑡 ⋅ ⃗𝑣𝑣, (0 ≤ 𝑡𝑡 < ∞)

Plane: Φ 𝑝𝑝 = 𝑝𝑝, 𝑛𝑛 − 𝑑𝑑 = 0

Substituting for 𝑝𝑝, we get:

Φ 𝑡𝑡 = 𝑝𝑝0 + 𝑡𝑡 ⋅ ⃗𝑣𝑣, 𝑛𝑛 − 𝑑𝑑 = 0 Solution: 𝑡𝑡 = − 𝑝𝑝0,⃗𝑣𝑣𝑛𝑛 − 𝑑𝑑, 𝑛𝑛 𝑛𝑛 𝑝𝑝 𝑝𝑝0 ⃗𝑣𝑣 Algebraic Method

(61)

Ray-Triangle Intersection I

• Check for point-triangle intersection algebraically:

 Generate planes through the ray

source and each edge

 Check if the point of intersection is

above each of these planes

𝑝𝑝0

𝑣𝑣2 𝑣𝑣3

For each edge:

𝑛𝑛𝑖𝑖 = (𝑣𝑣𝑖𝑖+1−𝑝𝑝0) × (𝑣𝑣𝑖𝑖 − 𝑝𝑝0) if ( 𝑝𝑝 − 𝑝𝑝0, 𝑛𝑛𝑖𝑖 < 0 ) return FALSE; 𝑛𝑛1 𝑣𝑣1 𝑝𝑝

(62)

Ray-Triangle Intersection II

• Check for point-triangle intersection parametrically

In general, given 𝑝𝑝 ∈ ℝ3 and given

three points 𝑣𝑣1, 𝑣𝑣2, 𝑣𝑣3 ⊂ ℝ3

(in general position) we can

solve for 𝛼𝛼, 𝛽𝛽, 𝛾𝛾 ∈ ℝ such that:

𝑝𝑝 = 𝛼𝛼𝑣𝑣1 + 𝛽𝛽𝑣𝑣2 + 𝛾𝛾𝑣𝑣3

𝑝𝑝 is in the plane spanned by 𝑣𝑣1, 𝑣𝑣2, 𝑣𝑣3 iff.:

𝛼𝛼 + 𝛽𝛽 + 𝛾𝛾 = 1

𝑝𝑝 is inside the triangle with vertices {𝑣𝑣1, 𝑣𝑣2, 𝑣𝑣3} iff.:

𝛼𝛼, 𝛽𝛽, 𝛾𝛾 ≥ 0 𝑝𝑝 𝑣𝑣1 𝑣𝑣2 𝑣𝑣3 𝛼𝛼 𝛽𝛽 𝛾𝛾

(63)

Ray-Triangle Intersection II

• Check for point-triangle intersection parametrically

In general, given 𝑝𝑝 ∈ ℝ3 and given

three points 𝑣𝑣1, 𝑣𝑣2, 𝑣𝑣3 ⊂ ℝ3

(in general position) we can

solve for 𝛼𝛼, 𝛽𝛽, 𝛾𝛾 ∈ ℝ such that:

𝑝𝑝 = 𝛼𝛼𝑣𝑣1 + 𝛽𝛽𝑣𝑣2 + 𝛾𝛾𝑣𝑣3

To get 𝛼𝛼, 𝛽𝛽, 𝛾𝛾, solve the system:

𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑥𝑥 𝑣𝑣3𝑥𝑥 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑦𝑦 𝑣𝑣3𝑦𝑦 𝑣𝑣1𝑧𝑧 𝑣𝑣2𝑧𝑧 𝑣𝑣3𝑧𝑧 𝛼𝛼 𝛽𝛽 𝛾𝛾 = 𝑝𝑝𝑥𝑥 𝑝𝑝𝑦𝑦 𝑝𝑝𝑧𝑧 ⇔ 𝛼𝛼 𝛽𝛽 𝛾𝛾 = 𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑥𝑥 𝑣𝑣3𝑥𝑥 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑦𝑦 𝑣𝑣3𝑦𝑦 𝑣𝑣1𝑧𝑧 𝑣𝑣2𝑧𝑧 𝑣𝑣11 −1 𝑝𝑝𝑥𝑥 𝑝𝑝𝑦𝑦 𝑝𝑝𝑧𝑧 𝑝𝑝 𝛼𝛼 𝛽𝛽 𝛾𝛾 𝑣𝑣1 𝑣𝑣2 𝑣𝑣3

(64)

Ray-Triangle Intersection II

• Check for point-triangle intersection parametrically

In general, given 𝑝𝑝 ∈ ℝ3 and given

three points 𝑣𝑣1, 𝑣𝑣2, 𝑣𝑣3 ⊂ ℝ3

(in general position) we can

solve for 𝛼𝛼, 𝛽𝛽, 𝛾𝛾 ∈ ℝ such that:

𝑝𝑝 = 𝛼𝛼𝑣𝑣1 + 𝛽𝛽𝑣𝑣2 + 𝛾𝛾𝑣𝑣3

To get 𝛼𝛼, 𝛽𝛽, 𝛾𝛾, solve the system:

𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑥𝑥 𝑣𝑣3𝑥𝑥 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑦𝑦 𝑣𝑣3𝑦𝑦 𝑣𝑣1𝑧𝑧 𝑣𝑣2𝑧𝑧 𝑣𝑣3𝑧𝑧 𝛼𝛼 𝛽𝛽 𝛾𝛾 = 𝑝𝑝𝑥𝑥 𝑝𝑝𝑦𝑦 𝑝𝑝𝑧𝑧 ⇔ 𝛼𝛼 𝛽𝛽 𝛾𝛾 = 𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑥𝑥 𝑣𝑣3𝑥𝑥 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑦𝑦 𝑣𝑣3𝑦𝑦 𝑣𝑣1𝑧𝑧 𝑣𝑣2𝑧𝑧 𝑣𝑣31 −1 𝑝𝑝𝑥𝑥 𝑝𝑝𝑦𝑦 𝑝𝑝𝑧𝑧 𝑝𝑝 𝛼𝛼 𝛽𝛽 𝛾𝛾 𝑣𝑣1 𝑣𝑣2 𝑣𝑣3

(65)

Ray-Triangle Intersection II

• Check for point-triangle intersection parametrically

In general, given 𝑝𝑝 ∈ ℝ3 and given

three points 𝑣𝑣1, 𝑣𝑣2, 𝑣𝑣3 ⊂ ℝ3

(in general position) we can

solve for 𝛼𝛼, 𝛽𝛽, 𝛾𝛾 ∈ ℝ such that:

𝑝𝑝 = 𝛼𝛼𝑣𝑣1 + 𝛽𝛽𝑣𝑣2 + 𝛾𝛾𝑣𝑣3

To get 𝛼𝛼, 𝛽𝛽, 𝛾𝛾, solve the system:

𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑥𝑥 𝑣𝑣3𝑥𝑥 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑦𝑦 𝑣𝑣3𝑦𝑦 𝑣𝑣1𝑧𝑧 𝑣𝑣2𝑧𝑧 𝑣𝑣3𝑧𝑧 𝛼𝛼 𝛽𝛽 𝛾𝛾 = 𝑝𝑝𝑥𝑥 𝑝𝑝𝑦𝑦 𝑝𝑝𝑧𝑧 ⇔ 𝛼𝛼 𝛽𝛽 𝛾𝛾 = 𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑥𝑥 𝑣𝑣3𝑥𝑥 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑦𝑦 𝑣𝑣3𝑦𝑦 𝑣𝑣1𝑧𝑧 𝑣𝑣2𝑧𝑧 𝑣𝑣3𝑧𝑧 −1 𝑝𝑝𝑥𝑥 𝑝𝑝𝑦𝑦 𝑝𝑝𝑧𝑧 𝑝𝑝 𝛼𝛼 𝛽𝛽 𝛾𝛾 𝑣𝑣1 𝑣𝑣2 𝑣𝑣3

This will fail if the vertices 𝑣𝑣1, 𝑣𝑣2, 𝑣𝑣3 lie in a plane through the origin.

(66)

Ray-Triangle Intersection II

• Check for point-triangle intersection parametrically

Embrace the problem case by translating the whole system to the origin:

𝑝𝑝 𝑣𝑣1 𝑣𝑣 2 𝑣𝑣3 𝛼𝛼 𝛾𝛾𝛽𝛽 𝑝𝑝 − 𝑣𝑣1 𝑣𝑣2 − 𝑣𝑣1 𝑣𝑣3 − 𝑣𝑣1 𝛼𝛼 𝛾𝛾𝛽𝛽 𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑥𝑥 𝑣𝑣3𝑥𝑥 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑦𝑦 𝑣𝑣3𝑦𝑦 𝑣𝑣1𝑧𝑧 𝑣𝑣2𝑧𝑧 𝑣𝑣3𝑧𝑧 𝛼𝛼 𝛽𝛽 𝛾𝛾 = 𝑝𝑝𝑥𝑥 𝑝𝑝𝑦𝑦 𝑝𝑝𝑧𝑧 0 𝑣𝑣2𝑥𝑥 − 𝑣𝑣1𝑥𝑥 𝑣𝑣3𝑥𝑥 − 𝑣𝑣1𝑥𝑥 0 𝑣𝑣2𝑦𝑦 − 𝑣𝑣1𝑦𝑦 𝑣𝑣3𝑦𝑦 − 𝑣𝑣1𝑦𝑦 0 𝑣𝑣2𝑧𝑧 − 𝑣𝑣1𝑧𝑧 𝑣𝑣3𝑧𝑧 − 𝑣𝑣1𝑧𝑧 𝛼𝛼 𝛽𝛽 𝛾𝛾 = 𝑝𝑝𝑥𝑥 − 𝑣𝑣1𝑥𝑥 𝑝𝑝𝑦𝑦 − 𝑣𝑣1𝑦𝑦 𝑝𝑝𝑧𝑧 − 𝑣𝑣1𝑧𝑧

(67)

Ray-Triangle Intersection II

• Check for point-triangle intersection parametrically

Embrace the problem case by translating the whole system to the origin:

𝑝𝑝 𝑣𝑣1 𝑣𝑣 2 𝑣𝑣3 𝛼𝛼 𝛾𝛾𝛽𝛽 𝑝𝑝 − 𝑣𝑣1 𝑣𝑣2 − 𝑣𝑣1 𝑣𝑣3 − 𝑣𝑣1 𝛼𝛼 𝛾𝛾𝛽𝛽 𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑥𝑥 𝑣𝑣3𝑥𝑥 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑦𝑦 𝑣𝑣3𝑦𝑦 𝑣𝑣1𝑧𝑧 𝑣𝑣2𝑧𝑧 𝑣𝑣3𝑧𝑧 𝛼𝛼 𝛽𝛽 𝛾𝛾 = 𝑝𝑝𝑥𝑥 𝑝𝑝𝑦𝑦 𝑝𝑝𝑧𝑧 𝑣𝑣2𝑥𝑥 − 𝑣𝑣1𝑥𝑥 𝑣𝑣3𝑥𝑥 − 𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑦𝑦 − 𝑣𝑣1𝑦𝑦 𝑣𝑣3𝑦𝑦 − 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑧𝑧 − 𝑣𝑣1𝑧𝑧 𝑣𝑣3𝑧𝑧 − 𝑣𝑣1𝑧𝑧 𝛽𝛽 𝛾𝛾 = 𝑝𝑝𝑥𝑥 − 𝑣𝑣1𝑥𝑥 𝑝𝑝𝑦𝑦 − 𝑣𝑣1𝑦𝑦 𝑝𝑝𝑧𝑧 − 𝑣𝑣1𝑧𝑧

(68)

Ray-Triangle Intersection II

• Check for point-triangle intersection parametrically

Embrace the problem case by translating the whole system to the origin:

𝑝𝑝 𝑣𝑣1 𝑣𝑣 2 𝑣𝑣3 𝛼𝛼 𝛾𝛾𝛽𝛽 𝑝𝑝 − 𝑣𝑣1 𝑣𝑣2 − 𝑣𝑣1 𝑣𝑣3 − 𝑣𝑣1 𝛼𝛼 𝛾𝛾𝛽𝛽 𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑥𝑥 𝑣𝑣3𝑥𝑥 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑦𝑦 𝑣𝑣3𝑦𝑦 𝑣𝑣1𝑧𝑧 𝑣𝑣2𝑧𝑧 𝑣𝑣3𝑧𝑧 𝛼𝛼 𝛽𝛽 𝛾𝛾 = 𝑝𝑝𝑥𝑥 𝑝𝑝𝑦𝑦 𝑝𝑝𝑧𝑧 This is an over-constrained system!

This is an over-constrained system!

In general, we can’t express a 3D point as the linear combination of two 3D points.

This is not the general case!

A solution exists since 𝑝𝑝 is in the plane spanned by {𝑣𝑣1, 𝑣𝑣2, 𝑣𝑣3} After solving for 𝛽𝛽 and 𝛾𝛾, we can set:

𝛼𝛼 = 1 − 𝛽𝛽 − 𝛾𝛾 𝑣𝑣2𝑥𝑥 − 𝑣𝑣1𝑥𝑥 𝑣𝑣3𝑥𝑥 − 𝑣𝑣1𝑥𝑥 𝑣𝑣2𝑦𝑦 − 𝑣𝑣1𝑦𝑦 𝑣𝑣3𝑦𝑦 − 𝑣𝑣1𝑦𝑦 𝑣𝑣2𝑧𝑧 − 𝑣𝑣1𝑧𝑧 𝑣𝑣3𝑧𝑧 − 𝑣𝑣1𝑧𝑧 𝛽𝛽 𝛾𝛾 = 𝑝𝑝𝑥𝑥 − 𝑣𝑣1𝑥𝑥 𝑝𝑝𝑦𝑦 − 𝑣𝑣1𝑦𝑦 𝑝𝑝𝑧𝑧 − 𝑣𝑣1𝑧𝑧

(69)

Other Ray-Primitive Intersections

• Cone, cylinder, ellipsoid:

 Similar to sphere

• Box

 Intersect 3 front-facing planes, return closest

• Convex polygon

» Find the intersection of the ray with the plane

» Check that the intersection is above every triangle generated by the ray source and polygon edge. • Concave polygon

 Same plane intersection

References

Related documents

This study primarily deals with crucial issues surrounding the impact of national fiscal policy and the regulatory framework on local governments’ expenditure behaviour and their

The psoas muscle transversal diameter predicts mortality in patients with cirrhosis on a waiting list for liver transplantation A retrospective cohort study.4. The psoas

The finding of the present study also subscribed to the fact that motivation may be expressed in various ways such as pull, push, intrinsic and extrinsic factors and these

Wheeled vehicles (2011), air defence system (2012), tracked vehicles (2013), combat training center (2013), cost overruns in Norwegian subsidiary (2014) Cost overruns Political

Project Definition : Basic design, general arrangement drawings, project management, manufacturing management &amp; erection management &amp; commissioning Technical Details

CSL/CBR Professional Development Funds are open to all faculty members and community partners in Arts that identify and pursue opportunities that advance knowledge, capacity

Our main role in the consulting field is to act as Client Project Engineer [CPE] – We complement the Client’s team to provide advice, control &amp; support through all stages

Written by: John Williams. Darth