Lecture Notes on Plane Geometry - Computer Graphics | CS 307, Study notes of Computer Graphics

Material Type: Notes; Class: Computer Graphics; Subject: Computer Science; University: Wellesley College; Term: Unknown 1998;

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-zrv-2
koofers-user-zrv-2 🇺🇸

10 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture on Plane Geometry1
As we’ve seen, CG usually breaksdown a model into a large numberof planar regions (quads and triangles). Even
curved surfaces are ultimately rendered as a large number of planar facets.
Very often the CG system then needs to do some additional geometry with the planes, such as determining if a ray
of light (say from a spotlight), intersects the planar region. To do that, we need a bit of geometry.
To motivate this, we will look at the following demo:
˜cs307/public_html/demos/animation/Laser.cc
This program has an animation of a “UFO” flying over a field with a bar on it. It has a “photon torpedo” that it fires a
random downward directions. We can animate the moving photon torpedo, but we need to determine when and where
the torpedo intersects the field or the barn, so that we can draw the explosion.
1 Implicit Equation of a Plane
First, let’s see how to define the implicit equation of a plane. Let

be a specific point on the plane, any point, but
one where we know the coordinate. Let
be the normal vector for the plane. Here is an example:
 

Now, note that any vector lying in the plane must be perpendicular to the normal vector. If we let P be a variable
standing for every point in the plane:
 !
Then we know that:
"
$#
&%' (
With a little abuse of notation, we can derive:
"
)#
*%
)#

Using our example:
"
+#
,%' -

#!.
/ ! %10

#!.
 % % %20
 %4356 %7438 %
935-:35 %
.

#
3*
#
73;<
#
10
935-:35 %!
Note that this is an implicit equation of a plane. It can tell us whether a point is on the plane or not, but it doesn’t
easily generate points on the plane. Also, the implicit equation doesn’t generalize to higher dimensions (but that’s a
problem for mathematicians, not us).
In general, the equation of a plane in 3D is:
=
>35?@3BAC :3BD>
"
1Some of this development is helped and improved by Dan Sunday’s work at
http://geometryalgorithms.com/Archive/algorithm_0104/algorithm_0104.htm
1
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Lecture Notes on Plane Geometry - Computer Graphics | CS 307 and more Study notes Computer Graphics in PDF only on Docsity!

Lecture on Plane Geometry^1 As we’ve seen, CG usually breaks down a model into a large number of planar regions (quads and triangles). Even curved surfaces are ultimately rendered as a large number of planar facets. Very often the CG system then needs to do some additional geometry with the planes, such as determining if a ray of light (say from a spotlight), intersects the planar region. To do that, we need a bit of geometry. To motivate this, we will look at the following demo: ˜cs307/public_html/demos/animation/Laser.cc This program has an animation of a “UFO” flying over a field with a bar on it. It has a “photon torpedo” that it fires a random downward directions. We can animate the moving photon torpedo, but we need to determine when and where the torpedo intersects the field or the barn, so that we can draw the explosion.

1 Implicit Equation of a Plane

First, let’s see how to define the implicit equation of a plane. Let ^ be a specific point on the plane, any point, but one where we know the coordinate. Let  be the normal vector for the plane. Here is an example:

       

Now, note that any vector lying in the plane must be perpendicular to the normal vector. If we let P be a variable standing for every point in the plane:

Then we know that: "   $# &%'^ (

With a little abuse of notation, we can derive: "   )# *%^ )# 

Using our example: "   +# ,%'^ -     (^) #!.  /  ! %       (^) #!.  %   %  %    % 435 6 % 7438  %   935-:35 % . (^) #3* (^) #73;< (^) #  935-:35 % !

Note that this is an implicit equation of a plane. It can tell us whether a point is on the plane or not, but it doesn’t easily generate points on the plane. Also, the implicit equation doesn’t generalize to higher dimensions (but that’s a problem for mathematicians, not us). In general, the equation of a plane in 3D is:

=

>35?@3BAC :3BD>

(^1) Some of this development is helped and improved by Dan Sunday’s work at http://geometryalgorithms.com/Archive/algorithm_0104/algorithm_0104.htm

2 Parametric Equation of a Plane

Another way to define a plane is by a point on the plane and two vectors that lie in the plane. (This works in higher dimensional spaces, not just 3D.) Let the two vectors be and . We can then define the equation:

^  ^   ^3 ^ ^3 ^ 

A very common situation for this is when we have a triangle of three points, , , , and we develop it like this:

^  ^ %' ^  ^ %'        3  (^) 3    %  %    3   3 

This is a nice equation using only the three points we started with, plus two parameters. Notice that the point  ^  is inside the triangle when:"  "     3   

The point is on the perimeter if :^ ,  

or ^3 ^  . Each condition corresponds to one edge. For a parallelogram, we have:

  ^  

Of course, if we want the implicit equation, we can take the cross product of and  to find  , and proceed from there.

3 Fun Facts

3.1 Any Point

Notice that the argument for the implicit equation works for any point on the plane, so that if we used  ^ instead of , we should get the same equation: (^) "  

" $# *%^ $# 

+# ^ $# 

This means that the constant term, D, in the equation, is the same for any point on the plane. The normal vector dotted with any point on the plane yields this same value.

3.2 Finding the Normal Vector

Notice that you can just read off a normal vector to a plane from its implicit equation. Very convenient!

3.3 Normalized Normal Vector

In the development, you notice that we just chose an arbitrary normal vector. What happens if we choose a different one (a scalar multiple)? "    (^)   #&%' -

 D % +# 

 D % = 3 5?   3 8A 

This is just our implicit equation! So, the key thing is that if the normal vector is unit length, the implicit equation gives the distance from the point to the line.

4 Intersecting a Ray with a Plane

Suppose we have a point  not on the plane (we’ll reserve for points on the plane), and a vector  indicating a ray starting at . Does the ray intersect the plane? If so, where? How far? We could solve this many ways. We will do it by creating a parametric equation of the ray and intersecting that with the implicit equation of the plane. That is, we combine these two equations:

   "    3    =935?@3BAC 3 8D

And we get: (^) "  =

  3  (^) 35?-   3 38A  3 38D

This is an equation just in , so we solve for  and we’re almost home. Let’s do an example, with   ^  ^ and   % ^ ^ and using our plane from before: "   % 38 ( 3  3 8  3 8  %    (^) %  43

3  3 ; 3 B  % !

 

The fact that  is negative tells us that the ray does not intersect the plane. The photon torpedo is moving away from the plane. If we reverse , we would get a positive  and the photon torpedo would intersect the plane. If we compute this intersection parameter with several planes, we know that the torpedo will hit them in the order of the parameter values. Thus, it will blow up the one with the smallest parameter.

5 Intersecting a Ray with a Plane Again

The math in the last section is fine, but here’s a better way, again thanks to geometryalgorithms.com. Given a line defined by  and and a plane defined by and (all knowns; I’ve dropped the subscripts for convenience), we can substitute the parametric representation of a line into one of our representations of a plane:

  3   #   #

From there, we can use some reasonable algebra to solve for :

w

v

w

v

Figure 2: Two projections of one vector onto another.

 # 3 C ;#   #

 C ;#   # %  #

 C ,#   ,%   #

  ,%^   #

Not exactly intuitive, but simple to compute! We should check for special cases:  A ray parallel to the plane (which means there’s no intersection). If that’s the case, the ray will be perpendicular to the surface normal, or ;# 

. So, we just check that the denominator is not zero.  A ray lying in the plane. If that happens, not only will the ray be parallel to the plane, but the point will lie on the plane. That means (P-Q) is a vector lying in the plane and therefore the dot product with the normal vector is zero. Thus, in this case, the numerator is zero.

6 Intersecting a Ray with a Triangle

But we don’t care about whether the ray intersects the plane, we care whether it intersects a triangle or a quad. We can compute the point of intersection (from the parameter and our parametric equation of the ray), and then try to compute the  and  values so that we can use the constraints in section 2.

6.1 Dot Products as Projections

Before we develop the code for finding the intersection point within a triangle, it’s helpful to have as a building block a more complete understanding the usefulness of the dot product. We know that the dot product gives us something like the cosine of the angle between two vectors. In fact, for unit vectors, it gives us exactly the cosine of the angle between them. Let’s start with unit vectors. Suppose we have unit vectors and . If we compute the following:

   #   

u

v

u’ w

tv

a

b

Figure 4: Taking the dot product of  with ^ (shown as  ). We start with known vectors , and  , where  is some linear combination of  and :   ^3 . We first find ^ , the perpendicular to  lying in the plane (denoted  in the figure). Taking the dot product finds , the amount of vector that is in the linear combination of  and to make up .

By similar triangles, the vector  is to as = is to ?: 

Therefore, we can find   =?^. Here it is again, purely algebraically:

^ ^ ^ ^93 ^

 ;#    ^93  # 

  !  #   43 C >#   

  C >#   

  #^  

Note that, because the numerator and denominator both have   in them, it doesn’t matter whether ^ is a unit vector, because the scale factor to normalize it appear in both the numerator and denominator and therefore would cancel. Similarly, we can solve for  by finding a  that is perpendicular to and lies in the plane t.

    # ^ 

^ 

How can we find these perpendicular vectors? Since they lie in the plane, they must be perpendicular to the plane normal,. Since the cross product finds a vector perpendicular to two others, we have:

     ^ ^ ^ 

Next, they introduce a computational shortcut. It turns out that there is an identity for cross products, namely:

=  ?C  A  = #?? % <? #A=

We’re not even going to think about proving that; we’re just going to use it. Consequently,

      )     +  #  %  # ^ ^  ^  ^  ^ ^  ^ ^  ^ 

^ 

^ %

^ 



And now we can compute  and  using only dot products.

  ^  # ^   ;#  % ># C^  #/

^  %  #^ C^ ># 

   #^  ;#   %  #/^  # 

^  %  #^ C^ # 

Notice the similarity between the two calculations. Thus, the complete calculation only requires five distinct dot products. We need to check for special cases where the triangle is degenerate:  One way this can happen is if two of the points defining the triangle are the same. If this happens, either  or will be the zero vector, and  #+^

(^) or # 

.  Another way is if the three points are colinear, in which case  is a scalar multiple of . One way to test for this is to test whether the cosine of the angle between  and is 1, which happens when the angle is zero.

 #  ^    #     #     #  C (^) #    #  %   #  C (^) # 

Since the quantity on the left is the denominator of our fractions to compute  and , all we need to do is check for zero before dividing.

7 Photon Torpedoes

Let’s look at the photon torpedo (Laser) demo.  Notice how the animation of the motion of the UFO is done. We give it an initial location and direction, controlled by global variables. The display function uses the location variable and the idle callback updates it.  Notice how the random direction of the laser is generated. Feel free to use ideas like that if you want random numbers in your own animation.  Notice how the laser is drawn, using twNormalizeVector and twVectorScale to ensure that the barrel is always 20 units long.  Look at the implementation of blast. First, we find the nearest “fragment,” using twNearestFragment. We’ll look at the code for that function, which is in ˜cs307/public_html/tw/tw-geometry.cc