Introduction to Computer Graphics
Lecture 4
Computer Graphics 3D Primitives

Don Herbison-Evans
don@it.uts.edu.au

(updated 23 August 2006)

3D Entities

  • Points - Vertices 3 numbers (x,y,z) Left Handed Cartesian coordinates

  • Lines - Edges
  • infinite: 1 point and 3 direction cosines (6 numbers)
    or
  • finite: 2 points (6 numbers)
  • Planes/Polygons - Faces
  • infinite: 4 numbers (A,B,C,D) where Ax + By + Cz + D = 0 or
  • finite: list of 3 or more points (vertices), and/or lines (edges)

         Beware: 4 points or more may not be co-planar.
         Only 3 are guaranteed flat.

  • Solids - Polyhedra
  • Boundary Representation (B.Rep): lists of-
    1. vertices
    2. edges
    3. faces
  • Volume Representation
    1. lot of voxels
    2. octree
    3. BSP (Binary Space Partitioning) tree
  • Operations

  • Vector Dot Product p . q = px*qx + py*qy + py*qy
            = |p|*|q|*cos(theta)
    where theta is the angle between the vectors  p and q.
    Note that the result is a scalar.
    If one of the vectors is of unit length, the answer is the length of the projection of the other vector onto the unit vector direction.
  • Vector Cross Product (p x q)x = py*qz - pz*qy
    (p x q)y = pz*qx - px*qz
    (p x q)z = px*qy - py*qx
    Note that the result is a vector at right angles to both  p and q, and hence it is normal to the plane containing  p and q.
    The length of the resultant vector is
    |p|*|q|*sin(theta)
    where theta is the angle between the vectors  p and q.

    More about Planes

    Three points specify a plane.
    Consider the points v1 = (x1,y1,z1)
    v2 = (x2,y2,z2)
    v3 = (x3,y3,z3)
    To find the coefficients ( A,B,C,D ) of that plane: 2 algorithms :-

    (1)

    Set up the equations: A*x1 + B*y1 + C*z1 + D = 0
    A*x2 + B*y2 + C*z2 + D = 0
    A*x3 + B*y3 + C*z3 + D = 0
          and
    A*A + B*B + C*C = 1

    Solve by using just the first 3 equations with D=1, then scaling resulting values of A,B,C, (and D) by dividing by r:

    r = (A2+B2+C2)1/2

    Alternatively, solve them by evaluating 3x3 determinants of a matrix composed of the components of the points and columns of '1's. See book for details.

    (2) Form vectors of 2 of the edges joining the points :- e12 = v1 -v2
    e23 = v2 -v3
    Take their cross product:
    a = e12 x e23 Normalise a by dividing its components by the square root of the sum of their squares :- r = (ax2 + ay2 + az2)1/2
    n = a/r
    Then n is the unit surface normal of the plane. Its components are the plane coefficients A,B,C: A = nx
    B = ny
    C = nz
    The value of D is the distance from the origin to the nearest point on the plane to the origin,
    and so is the projection of any point on the plane onto the unit surface normal n:- D = -n . vj      for any j = 1,2 or 3
    Note that if the points are transformed by some matrix, the equation coefficients need to be transformed by the transpose of that matrix.
    Points are Ket vectors in Quantum Mechanics and Contravariant vectors in Relativity.
    Plane coefficients are Bra vectors in Quantum Mechanics and Covariant vectors in Relativity.

    For any point in 3D space, the value of ' f ' :-

    f = Ax + By +Cz + D tells which side of the plane the point is on.
    If f > 0, the point is on the side opposite to the origin.
    If f < 0, the point is on the same side of the plane as the origin.

    BRep Tables

    For each polyhedron in a scene, could have 9 tables:

  • vertices, edges, and faces in the polyhedron,
  • edges and faces for each vertex
  • vertices and faces for each edge
  • vertices and edges for each face

    Save space using the Winged-Edge system:

  • list of faces, each with coefficients, colours, etc, and a link to one component edge
  • list of vertices, each with their coordinates and a link to one incident edge
  • list of edges, each with links to
  • vertices at each end
  • faces at each side
  • next edges clockwise and anticlockwise at each end
  • Where does a line strike a face?

    Express the line as:

    P = P1 + u*(P2 - P1) Then N.P + D = 0 so u = (-D - N.P1)/ (N.(P2-P1)

    Check if the resulting point is on the face by projecting it and the vertices of the face into 2 dimensions (eg by ignoring the z coordinate), and doing the 2D test of a point being in a polygon.

    Is a point inside a polyhedron?

    2 algorithms :-

    (1)

    Create a finite line from the point   p1 to another point definitely outside the polyhedron    p2.
    Count the number of intersections of that line with the faces of the polyhedron.
    Each intersection must be within the length of the line and within the face of the polyhedron to be counted.
    If the number is odd, the point is inside.
    If the number is even, the point is outside.
    (2) Ensure firstly that all the surface normals of the polyhedron faces all point outward.
    Then for each face take the dot product of the surface normal with a vector from the point to some vertex on that face.
    If all dot products are negative, the point is inside.
    If any dot product is positive, the point is outside.
    Creating polyhedra

    (1) Use 5 Platonic solids directly from OpenGL
    (2) Use sweeping plus a polygon to create a prism
    (3) Use CSG (Constructive Solid Geometry: union, intersection, difference)
    (4) Use Shape Grammar and CSG.

    Validating a polyhedron

    To check absence of holes or partly attached faces, edges, and vertices, ensure that:

    (1) Every vertex appears in at least 3 edge lists
    (2) Every vertex appears in at least 3 face lists
    (3) Every edge appears in exactly 2 vertex lists
    (4) Every edge appears in exactly 2 face lists
    (5) Every face has at least 3 vertices
    (6) Every face has at least 3 edges

    ~~~~~~~~~~~~~~~~~~~~~~~~