0% found this document useful (0 votes)
25 views

3D Basic Mathematics for Computer Graphics

Uploaded by

huma shadmeen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

3D Basic Mathematics for Computer Graphics

Uploaded by

huma shadmeen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

BIRLA INSTITUTE OF TECHNOLOGY,

PATNA

CA-305 Computer Graphics


Assignment

Name – Akarsh
Srivastava RollNo –
BCA/15033/22 Course –
BCA – V
3D Basic Mathematics for Computer
Graphics
Introduction
Computer graphics, as a field, is founded on a rich
set of mathematical principles that allow for the
creation and manipulation of images, models, and
animations in 2D and 3D space. These principles
enable the rendering of virtual objects with realism,
providing the tools needed for games, movies,
simulations, and augmented reality experiences.
Without a solid mathematical foundation, developing
these systems becomes significantly more
challenging. This document aims to introduce the
basic mathematics required to understand and work
with 3D graphics, emphasizing vectors, matrices,
transformations, and lighting models.

While advanced techniques like ray tracing and


global illumination are crucial for generating realistic
images, they are built on simpler concepts like
coordinate systems, vector algebra, and matrix
transformations. By mastering the foundational
math, you’ll be better equipped to understand more
complex algorithms and systems.
Throughout this document, we will explore both the
theory
and practical applications of these mathematical
principles in computer graphics.

Vectors and Points in 3D Space


At the core of 3D graphics is the concept of space and
how we represent positions and directions within it.

describe any point in 3D space with three values: xxx,


The Cartesian coordinate system allows us to

yyy, and zzz. These coordinates are relative to the


origin (0, 0, 0), which serves as the reference point for
positioning objects within the scene.

can be represented as P(2,5,−3)P(2, 5, -3)P(2,5,−3),


For example, the position of a vertex in a 3D model

meaning it is located 2 units along the x-axis, 5 units


along the y-axis, and
-3 units along the z-axis. While points represent static
positions, vectors allow us to describe movement or
directions. A vector can be thought of as the

have two points P1(1,2,3)P_1(1, 2, 3)P1 (1,2,3) and


difference between two points. For example, if you

P2(4,6,8)P_2(4, 6, 8)P2
(4,6,8), the vector P1P2→\
overrightarrow{P_1P_2}P1 P2 is
calculated as (4−1,6−2,8−3)=(3,4,5)(4-1, 6-2, 8-3)
= (3, 4,
5)(4−1,6−2,8−3)=(3,4,5).
Vectors can be manipulated in a variety of ways that
are crucial to 3D graphics. For instance, vectors can
be scaled by multiplying them by a scalar value. This
is useful when you want to increase or decrease the

If you multiply the vector (3,4,5)(3, 4, 5)(3,4,5) by a


magnitude of a vector without changing its direction.

scalar of 2, the resulting vector will be (6,8,10)(6, 8,


10)(6,8,10), which points in the same direction but
has twice the magnitude.

Another important operation in graphics is vector


normalization. A normalized vector has a length (or
magnitude) of 1, which is useful when calculating unit
directions, such as light or view directions in
rendering. To normalize a vector, you divide each

example, to normalize the vector (3,4,5)(3, 4, 5)


component of the vector by its magnitude. For

(3,4,5), first calculate its magnitude as:

∣v∣=32+42+52=50≈7.07|v| = \sqrt{3^2 + 4^2 + 5^2} = \


sqrt{50}
\approx 7.07∣v∣=32+42+52 =50 ≈7.07

Then, the normalized vector becomes:

(37.07,47.07,57.07)≈(0.42,0.57,0.71)\left( \frac{3}{7.07},
\frac{4}{7.07}, \frac{5}{7.07} \right) \approx (0.42, 0.57,
0.71)(7.073 ,7.074 ,7.075 )≈(0.42,0.57,0.71)
Dot Product and Cross Product
In vector algebra, two key operations are used extensively in
3D graphics: the dot product and the cross product. The dot
product of two vectors is a scalar quantity that reflects the
degree of alignment between them. If two vectors point in
the same direction, their dot product will be positive and at
its maximum value. If the vectors are perpendicular, the dot
product will be zero. If they point in opposite directions, the
dot product will be negative. The formula for the dot product
is:

A⋅B=∣A∣∣B∣cos⁡(θ)A \cdot B = |A| |B| \cos(\


theta)A⋅B=∣A∣∣B∣cos(θ)

where θ\thetaθ is the angle between vectors AAA and BBB.


A common use of the dot product in graphics is in calculating
the intensity of light hitting a surface. The angle between the
light source direction and the surface's normal (a vector
perpendicular to the surface) affects how much light the
surface receives, and thus how bright it appears.

For instance, if a light source is directly overhead and the


surface is flat, the angle between the light vector and the
surface normal is 0 degrees, meaning the dot product is at
its maximum, and the surface will be fully lit. As the angle
increases (the light source moves to the side), the dot
product decreases, and the surface becomes darker.
The cross product produces a vector that is perpendicular
to the plane defined by two vectors. This operation is
essential for calculating normals to surfaces, which are used

two vectors AAA and BBB is:


for lighting calculations in rendering. The cross product of

A×B=∣A∣∣B∣sin⁡(θ)n^A \times B = |A| |B| \sin(\theta)


\hat{n}A×B=∣A∣∣B∣sin(θ)n^

where n^\hat{n}n^ is the unit vector perpendicular to both


AAA and BBB. A practical example of the cross product is in
calculating the surface normal of a polygon. If you have two
edges of a triangle represented by vectors, the cross
product of those vectors will give the normal vector to the
surface. This normal is crucial for determining how light
interacts with the surface, affecting shading and reflections.
Matrices in 3D Graphics
Matrices are indispensable tools in computer
graphics, particularly for handling transformations. A
matrix is a rectangular array of numbers arranged in
rows and columns, and they can be used to perform
operations like translation, rotation, and scaling in 3D
space. These transformations can be combined
through matrix multiplication, making matrices highly
efficient for handling multiple transformations
simultaneously.

A 3×33 \times 33×3 matrix is typically used for

we use 4×44 \times 44×4 matrices to handle


transformations in 2D graphics, but in 3D graphics,

transformations in homogeneous coordinates, which


will be discussed later. Matrices allow you to
transform an object's position, size, and orientation
in space by multiplying the matrix with the object's
coordinates.

One of the most important properties of matrices is


their ability to combine multiple transformations into a
single matrix. For example, if you want to rotate an
object and then translate it, you can multiply the
rotation matrix by the translation matrix to create a
single matrix that performs both transformations in
one step. This is highly efficient,
especially when rendering scenes with thousands of
objects.

RRR and a translation matrix TTT. If you want to


Consider the case where you have a rotation matrix

apply both transformations to an object, you can


multiply the matrices together:

M=T×RM = T \times RM=T×R

Now, applying this combined matrix MMM to the


object's coordinates will result in both the translation
and rotation being applied at once.
Transformations in 3D Graphics
Transformations are the building blocks of 3D
modeling and animation. By applying
transformations, you can move, rotate, and scale
objects in a 3D scene. Translation moves an object
from one position to another. For example, to move
an object 5 units along the x-axis, you use a
translation matrix that shifts the object's coordinates
by that amount.

Rotation is more complex because it involves


changing an object's orientation around a specific
axis. In 3D space, objects can be rotated around the
x-axis, y-axis, or z-axis, and each rotation is
represented by a different matrix.
Rotations are essential for animations, such as turning
a

instance, to rotate an object around the z-axis by θ\


character’s head or spinning a car’s wheels. For

thetaθ degrees, the corresponding rotation matrix is:

Rz(θ)=(cos⁡θ−sin⁡θ0sin⁡θcos⁡θ0001)R_z(\theta) =
\begin{pmatrix} \cos\theta & -\sin\theta & 0 \\ \
sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \
end{pmatrix}Rz (θ)=
cosθsinθ0 −sinθcosθ0 001

Similarly, scaling changes the size of an object. A


scaling matrix increases or decreases the size of the
object along
the x, y, and z axes. If you want to double the size of
an object in all directions, you use a scaling matrix
like:

S=(200020002)S = \begin{pmatrix} 2 & 0 & 0 \\ 0


&2&0
\\ 0 & 0 & 2 \end{pmatrix}S= 200 020 002
This matrix will make the object twice as large along
all axes.

Combining these transformations is crucial in


complex scenes. For example, when animating a
character walking, you might need to translate the
character forward while simultaneously rotating its
limbs.

Homogeneous Coordinates
Homogeneous coordinates are a mathematical trick
that allows us to handle translation, rotation, scaling,
and
framework. By adding a fourth coordinate www, we
perspective projection using the same matrix

can represent points and vectors in a way that


simplifies the combination of transformations.

(x,y,z)(x, y, z)(x,y,z) is represented as (x,y,z,1)(x, y, z,


In homogeneous coordinates, a point in 3D space

1)(x,y,z,1), and a
vector is represented as (x,y,z,0)(x, y, z, 0)(x,y,z,0).
This fourth coordinate allows translation to be
represented as a matrix multiplication, just like
rotation and scaling. For instance, a translation
matrix in homogeneous coordinates looks like this:

T=(100tx010ty001tz0001)T = \begin{pmatrix} 1 &


0&0&
tx \\ 0 & 1 & 0 & ty \\ 0 & 0 & 1 & tz \\ 0 & 0 &
0&1
\end{pmatrix}T= 1000 0100 0010 txtytz1
where tx, ty, and tz are the translation amounts along
the x, y, and z axes. Using homogeneous
coordinates also makes it easier to apply
perspective projections, which are essential for
creating realistic images. In perspective projection,
objects farther away from the camera appear smaller,
just like in the real world. The perspective
transformation matrix includes terms that scale the
object's coordinates based on its distance from the
camera, creating the illusion of depth.
Conclusion
Understanding the mathematical principles behind 3D
computer graphics is crucial for anyone aspiring to
create or manipulate visual representations in the
digital world. From vectors and matrices to
transformations and lighting models, these concepts
form the backbone of 3D rendering. By mastering
these fundamental ideas, you will be able to create
realistic, immersive scenes and animations, whether
for video games, simulations, or visual effects.

As the field of computer graphics continues to evolve,


new techniques and technologies will build upon the
mathematical foundations outlined in this note.
Whether you're interested in real-time rendering,
animation, or visual effects, a solid understanding of
3D basic mathematics will serve as a powerful tool in
your toolkit, enabling you to push the boundaries of
what is possible in the world of digital visuals.

You might also like