Surfaces Ron Goldman Department of Computer Science Rice University
Representations 1. Parametric Plane, Sphere, Tensor Product x = f (s,t) y = g(s,t) z = h(s,t) 2. Algebraic Plane, Sphere, Torus F(x, y, z) = 0 3. Procedural Fractals (Turtle Programs, Iterated Function Systems), Blends 4. Deformed Ellipsoid, Free-Form Deformations
Advantages and Disadvantages 1. Parametric Generate points on the surface Generate contour lines along the surface 2. Algebraic Point on Surface Test Inside Outside Test 3. Procedural Fractals for modeling natural shapes Difficult to ray trace! 4. Deformed Simple base surface
Problems 1. Converting between different representations a. Parametric to Implicit (Resultants) b. Implicit to Parametric (Difficult) 2. Extracting information from a particular representations a. Surface Normals b. Axes of Symmetry 3. Solving for Intersections a. Ray Surface b. Curve Surface c. Surface Surface 4. Transforming to a different location or shape a. Rigid Motions b. Affine and Projective Transformations c. Non Linear Transformations
1. Algebraic F(x, y, z) = 0 Normals Calculations N = F = F x, F y, F z 2. Parametric ( ) P(s,t) = x(s,t), y(s,t), z(s,t) N = P s P t 3. Fractal??? 4. Transformed P new = P old M N new = N old M T
Algebraic Surfaces Setup F(x, y, z) = 0 Surface ( ) Curve on Surface P(t) = x(t), y(t), z(t) F( x(t), y(t), z(t) ) 0 Constraint Chain Rule F x dx dt + F y dy dt + F z dz dt = df dt = 0 F { { P (t) = F Gradiant x, F y, F z Derivative 14 244 3 Normal vector dx dt, dy dt, dz t 1 42 4 3 Tangent vector = 0 N = F = F x, F y, F z
Parametric Surfaces Tangents and Normals ( ) Surface ( ) Curve on Surface P(s,t) = x(s,t), y(s,t), z(s,t) P(s,t 0 ) = x(s,t 0 ), y(s,t 0 ),z(s,t 0 ) -- P s = x s, y s, z s Tangent Vector P(s 0,t) = ( x(s 0,t), y(s 0,t), z(s 0,t)) Curve on Surface -- P t = N = P s P t x t, y t, z t Tangent Vector Normal Vector
Transformed Surfaces Points and Tangent Vectors P new = P old M Points v new = v old M Tangent Vectors -- v old = Lim h 0 P old (t + h) P old (t) h -- v new = Lim h 0 P new (t + h) P new (t) h Normal Vectors v N T = v N = 0 T (v old M) N new (v old M) (M 1 T N old T = v new N new = 0 ) = T vold N old = 0 T N new = M 1 T N old N new = N old M T
List of Surfaces Planes Quadrics Spheres Ellipsoids Cylinders Cones Tori Extruded Surfaces Cylinders Cones Surfaces of Revolution
Planes Equations Ax + By + Cz + D = 0 N (P Q) = 0 Normal N = (A, B,C) Ray Plane Intersection P(t) = P + tv {ray} N ( P(t) Q) = 0 {solve for t} -- t = N (Q P) N V R = P + tv {compute (x, y, z)}
Point Inside Polygon P 1 P 2 N 23 N 12 Q N 51 P 5 L N 45 N 34 P 3 P 4 Test 1: (Convex Polygons) (Q P i ) N i,i+1 0 for all inward normals N i,i+1 Test 2: (Arbitrary Polygons) #(L Polygon) is odd for any ray L through Q
Quadrics Spheres Cylinders Cones Ellipsoids Paraboloids Hyperboloids
Sphere Equation Distance to Center = Constant P C 2 = R 2 x 2 + y 2 + z 2 = R 2 Normal N = P C Ray Sphere Intersection Algebraic -- Substitution Line Equation into Sphere Equation -- Dangerous Decisions Geometric -- Reduce to Line Circle Intersection -- Robust Decisions and Fast Reject
Line Sphere Intersection Equations P C 2 = R 2 (Sphere) P(t) = At + B (Line) Computation R 2 = P(t) C 2 = At + B C 2 = ( At + B C) ( At + B C) = (A A)t 2 + 2( A (B C) )t + ( B C) ( B C) Solution t = ( A (B C) ) ± ( A (B C) )2 (A A) ( B C) ( B C) R 2 A A { }
Ray Circle Intersection Data C = Circle Center R = Circle Radius P = Point on Line v = Unit Vector for Line Computation w = (P C) = (P C) ((P C) v)v Q = C + w x 2 = R 2 w 2 A = Q + xv B = Q xv R C w R P C x x v A Q B P
Sphere -- Ray Tracing Ray Sphere Intersection Points First check distance between ray and sphere center -- fast reject. If Distance < Radius, -- Compute ray circle intersection points. -- Recover the line parameters from the intersection points. Ray Sphere Intersection Parameters A = P +t 1 v t 1 = (A P) v B = P +t 2 v t 2 = (B P) v
Cylinder Equation Distance to Axis Line = Constant (P Q) A 2 = R 2 x 2 + y 2 = R 2 Normal N = (P Q) {(P Q) A}A Ray Cylinder Intersection First check distance between ray and axis line -- fast reject. Project orthogonally into Q plane and treat as line circle problem. (see sphere) Recover the line parameter to find true intersection points.
Cylinder A N P Q P Q N = (P Q) = (P Q) ((P Q) A)A
Computing True Intersections from Projections Setup L(t) = P + tv (Original Line) L (t) = P + tv (Projected Line) P 0, P1 = Computed Intersection Points -- Projections P 0, P 1 = Original Intersection Points Recovering True Intersections Solve for Intersection Parameters P k = P +tk v t k = (P k P ) v v v Compute Original Intersection Points P k = P + t k v
Cone Equation Distance to Axis Line Distance to Vertex Point = sin(α) (P V) A 2 = P V 2 sin 2 (α) x 2 + y 2 = z 2 Normal N = (P V) P V cos(α) A Ray Cone Intersection Perspective projection from V to a plane normal to A and treat as a line-circle problem (see sphere and cylinder).
Cone A P V cos(α) α α V N P P V N = (P V) P V cos(α) A
Ellipsoid Equation Ellipsoid = Scaled Sphere Ellipsoid = Sphere Scaling Matrix M = Scaling Matrix x 2 a 2 + y 2 b 2 + z2 c 2 =1 Normal N E = N S M T Ray Ellipsoid Intersection Transform Ray by M 1 Intersect Ray with Sphere Transform Ray Sphere Intersection Points by M
Ellipsoid M Sphere x 2 + y 2 + z 2 = 1 Ellipsoid x 2 a 2 + y 2 b 2 + z2 c 2 =1 a 2 0 0 0 0 b 2 0 0 M = 0 0 c 2 0 0 0 0 1
Intersection by Transformation Observation Given a parametric curve and a parametric surface C(t) = Curve S(u, v) = Surface Intersection occurs whenever there are parameters t*,u*,v * such that C(t*)= S(u*,v*). Applying an affine or projective transformation M yields C(t*) M = S(u*,v*) M. Thus if the original curve and surface intersect at t*,u*,v *, so will the transformed curve and surface.
Intersection by Transformation (continued) Conclusions 1. If we do not introduce any new intersections by applying the transformation M, then we can find the original intersections by solving for the parameters t and/or (u,v) of the new transformed curve and surface and then substituting these parameters back into the original equations to find the coordinates of the original intersection points. This is precisely what we do when we solve for the intersection of a line and a cylinder or cone by applying projections into 2 dimensions. 2. Even if we do introduce new intersection points by applying the transformation M, we do not lose any of the old ones. So at worst we need to check whether the parameters representing new intersection points represent original intersection points. This we can do by substituting the parameters back into the original parametric equations and checking whether or not we get the same point on the curve and the surface.
Equation General Quadrics P Q P T = Ax 2 + By 2 + Cz 2 + 2Dxy +L+ J = 0 A D F G D B E H Q = F E C I G H I J = symmetric 4 4 matrix P = (x, y, z,1) = point in homogeneous coordinates Transformations P new = P old M Q new = M 1 Q old M T T P new Q new P new = ( P old M) ( M 1 Q old M T ) ( P old M) T = P old Q old P old T = 0
General Quadrics (continued) Normal Plane P Q R T = 0 P = (x, y, z,1) = arbitrary point Q = symmetric 4 4 matrix R = (r 1, r 2,r 3,1) = point on Q Normal Vector N = R Q N new = N old M T Ray Quadric Intersection Solve a Quadratic Equation R(t) Q R(t) T = 0
Examples of General Quadrics Elliptical Paraboloid x 2 a 2 + y2 b 2 = z Hyperbolic Paraboloid x 2 a 2 y2 b 2 = z Hyperboloid of One Sheet x 2 a 2 y2 b 2 z2 c 2 =1 Hyperboloid of Two Sheets x 2 a 2 + y2 b 2 z2 c 2 =1
Algebraic Surfaces Equation F(x, y, z) = 0 Normal N = F = F x, F y, F z Ray-Algebraic Surface Intersection ( ) = 0 F x(t), y(t), z(t) Examples Quadrics Tori Cyclides
Tori in Canonical Position Equation ( ) 2 + 4d 2 z 2 4a 2 d 2 = 0 F(x, y, z) = x 2 + y 2 + z 2 d 2 a 2 Normal N = F x, F y, F = 4xG(x,y,z),4yG(x,y,z),4z(G(x,y,z)+2d 2 ) z G(x.y, z) = x 2 + y 2 + z 2 d 2 a 2 ( ) Ray-Torus Intersection ( ) = 0 Solve the degree 4 equation F x(t), y(t), z(t) Observe the circular cross sections at z = 0 and z = ±a
Tori in General Position Equation Distance to Circle = Constant 2 (P 14 2 C) 43 A + P C 2 ((P C) A) 2 1444 244443 d { Dist to Plane Dist of Projection to Center Circle Radiaus 2 = a 2 Normal Vector Q = P ((P C) A)A (Project P into Circle Plane) q = Q C = P C 2 ((P C) A) 2 R = C +(d /q)(q C) (Point on Circle Nearest to P) N = P R P R Ray-Torus Intersection Solve quartic equation ((P(t) C) A) 2 + P(t) C 2 (P(t) C) A ( ) 2 d 2 = a 2
A Torus C P C d a R (P C) ((P C) A)A P ((P C) A)A Q
Tori in General Position -- Transformation Approach Data Structure C = Center Point A = Unit Axis Vector d = Central Circle Radius a = Tube Radius Transformation to Canonical Position Translate C to the Origin trans( C) = I 0 C 1 Rotate A to the z-axis rot(u,θ) = cos(θ)i + ( 1 cos(θ) )(u u)+ sin(θ)(u _) u = k A k A cos(θ) = k A
Tori in General Position -- Alternative Approach (continued) Transformations to and from Canonical Position Transformation to Canonical Position M 1 = trans( C) rot(u,θ) Transformation to General Position M = rot(u, θ) trans(c) Ray Torus Intersection Transform Ray by M 1 Intersect Ray with Torus in Canonical Position Transform Intersection Points by M Normal N = N canonical position M T = N canonical position rot(u, θ)
Ray Tracing Transformed Surfaces General Principles If we can ray trace a surface S in canonical position, then we can ray trace the surface R = S in general position. If we can ray trace a surface S, then we can ray trace any affine image R = S M of the surface S. Data Structure for R D = Data Structure for S -- Scalars, Points, Vectors, Equations, K M = Affine Transformation -- 4 4 Matrix Ray-Surface Intersections Transform the ray by M 1 Compute intersections of the transformed ray with S Transform intersection points by M Normals N R = N S M T
Examples Ellipsoids Scaled Spheres Elliptical Cylinders Scaled Cylinders Tori Translated and Rotated from Torus in Canonical Position Elliptical Tori Scaled Tori Translated, Rotated, and Scaled from Torus in Canonical Position
Equation of Transformed Surface Equation F new = F old o M 1 F new (P new ) = 0 F old (P old ) = 0 -- P new = P old M -- F new (P new ) = F old (P new M 1 ) = F old (P old ) = 0 Algorithm Compute M 1. Compute x old,y old,z old in terms of x new,y new,z new. Substitute these equations for x old,y old,z old into the original expression for F old. The resulting expression is F new.
Surfaces of Revolution Parametric Equation R(u,v) = ( f (u)cos(v), f (u)sin(v),g(u)) -- Surface of Revolution D(u) = ( f (u),0, g(u) ) -- Directrix z = g(u) -- Axis (z-axis) Parametric Equation in Arbitrary Position R(u,v) = E + f (u)cos(v)c + f (u)sin(v)b + g(u)a D(u) = E + f (u)c + g(u)a A, B,C orthogonal axes E arbitrary center
Surfaces of Revolution (continued) Examples Cylinder: D(u) = ( 1,0, u) Sphere: D(u) = ( cos(u), 0,sin( u) ) Torus: ( ) D(u) = d + a cos(u),0,a sin(u) Normal N(u,v) = R u R v ( ) N(u,v) = f (u) g (u)cos(v), f (u) g (u)sin(v), f (u) f (u)
Surfaces of Revolution (continued) Equations ( ) -- Surface of Revolution R(u,v) = f (u)cos(v), f (u)sin(v),g(u) ( ) -- Line L(t) = At + B = A x t + B x, A y t + B y, A z t + B z Ray Surface of Revolution Intersection Solve the z equation: A z t + B z = g(u) t = g(u) B z A z {If L(t) is horizontal, then A z = 0 and can solve g(u) = B z for u.} Solve the x, y equations for u, v f 2 (u) = (A x t + B x ) 2 + (A y t + B y ) 2 (solve for u) tan(v) = A yt + B y v = tan 1 A x t + B x A yt + B y A x t + B x
Replacing Trigonometric Functions by Rational Functions Substitutions s = tan(v/ 2) cos(2v) = cos 2 (v) sin 2 (v) = 2cos 2 (v) 1 cos 2 (v / 2) = s 2 +1= tan 2 (v / 2) +1 = sec 2 (v / 2) = cos(v) = 1 s2 1+ s 2 sin(v) = 2s 1+ s 2 1 cos 2 (v /2) = 2 1+ cos(v) 1+ cos(v) 2 Observations Faster computations with rational functions It is often easier to solve polynomial equations than to solve trigonometric equations (e.g. ray tracing, although our ray-surface intersection method solves directly for tan(v))