In this section, we will explore how three-dimensional objects are represented in computer graphics. Understanding these representations is crucial for creating, manipulating, and rendering 3D models. We will cover the following key concepts:

  1. Basic Geometric Primitives
  2. Mesh Representations
  3. Surface Representations
  4. Volume Representations

  1. Basic Geometric Primitives

Points

  • Definition: A point in 3D space is defined by its coordinates (x, y, z).
  • Example:
    point = (1.0, 2.0, 3.0)
    

Lines

  • Definition: A line is defined by two points in space.
  • Example:
    line = [(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)]
    

Planes

  • Definition: A plane can be defined using a point and a normal vector.
  • Example:
    point_on_plane = (1.0, 2.0, 3.0)
    normal_vector = (0.0, 1.0, 0.0)
    

Polygons

  • Definition: A polygon is a flat shape consisting of straight, non-intersecting lines that form a closed loop.
  • Example:
    polygon = [(1.0, 2.0, 3.0), (4.0, 5.0, 6.0), (7.0, 8.0, 9.0)]
    

  1. Mesh Representations

Definition

  • A mesh is a collection of vertices, edges, and faces that defines the shape of a 3D object.

Types of Meshes

  • Triangle Meshes: The simplest type of mesh, consisting of triangles.
  • Quad Meshes: Meshes made up of quadrilaterals.
  • Polygonal Meshes: Meshes that can have polygons with more than four sides.

Example: Triangle Mesh

vertices = [
    (0.0, 0.0, 0.0),  # Vertex 0
    (1.0, 0.0, 0.0),  # Vertex 1
    (0.0, 1.0, 0.0)   # Vertex 2
]

triangles = [
    (0, 1, 2)  # Triangle made up of vertices 0, 1, and 2
]

Exercise: Create a Quad Mesh

  • Task: Define a quad mesh using four vertices and two triangles.
  • Solution:
    vertices = [
        (0.0, 0.0, 0.0),  # Vertex 0
        (1.0, 0.0, 0.0),  # Vertex 1
        (1.0, 1.0, 0.0),  # Vertex 2
        (0.0, 1.0, 0.0)   # Vertex 3
    ]
    
    quads = [
        (0, 1, 2, 3)  # Quad made up of vertices 0, 1, 2, and 3
    ]
    

  1. Surface Representations

Parametric Surfaces

  • Definition: Surfaces defined by parametric equations.
  • Example: A parametric equation for a sphere.
    def sphere(u, v, radius=1.0):
        x = radius * math.sin(u) * math.cos(v)
        y = radius * math.sin(u) * math.sin(v)
        z = radius * math.cos(u)
        return (x, y, z)
    

Implicit Surfaces

  • Definition: Surfaces defined by an equation F(x, y, z) = 0.
  • Example: The equation of a sphere.
    def is_on_sphere(x, y, z, radius=1.0):
        return x**2 + y**2 + z**2 == radius**2
    

  1. Volume Representations

Voxel Grids

  • Definition: A voxel grid is a 3D grid of values, where each voxel represents a value at a point in space.
  • Example:
    voxel_grid = [
        [[0, 0, 0], [0, 1, 0], [0, 0, 0]],
        [[0, 1, 0], [1, 1, 1], [0, 1, 0]],
        [[0, 0, 0], [0, 1, 0], [0, 0, 0]]
    ]
    

Exercise: Create a Simple Voxel Grid

  • Task: Define a 3x3x3 voxel grid with a single voxel set to 1 in the center.
  • Solution:
    voxel_grid = [
        [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
        [[0, 0, 0], [0, 1, 0], [0, 0, 0]],
        [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
    ]
    

Conclusion

In this section, we have covered the fundamental ways to represent 3D objects, including basic geometric primitives, mesh representations, surface representations, and volume representations. Understanding these concepts is essential for working with 3D graphics and will serve as a foundation for more advanced topics in 3D modeling and rendering. In the next section, we will delve into projections and views, which are crucial for visualizing 3D objects on a 2D screen.

© Copyright 2024. All rights reserved