Computer Graphics Notes ESM - CSU358 - Shoolini U

Computer Graphics Notes ESM

Course Knowledge Map

            graph TD
                Unit1[Unit 1: Fundamentals] -- Provides Hardware --> Unit2[Unit 2: Drawing Algorithms]
                Unit2 -- Creates Shapes --> Unit3[Unit 3: Transformations]
                Unit3 -- Manipulates --> Unit4[Unit 4: Clipping & Projections]
                Unit4 -- Prepares View --> Unit5[Unit 5: VSD & Animation]
                
                style Unit1 fill:#e1f5fe,stroke:#01579b,stroke-width:2px
                style Unit2 fill:#fff9c4,stroke:#fbc02d,stroke-width:2px
                style Unit3 fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px
                style Unit4 fill:#fce4ec,stroke:#880e4f,stroke-width:2px
                style Unit5 fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
            

How the 5 course units connect to form the Graphics Pipeline.

Computer Graphics End Semester Notes Cover
View Summary 1 View Summary 2 Unit 1: Fundamentals Unit 2: Drawing Algos Unit 3: Transformations Unit 4: Clipping & Projection Unit 5: VSD & Animation Formula Sheet Solved Numericals

1. Introduction to Computer Graphics

Computer Graphics is a domain of computer science concerned with how computers generate, manipulate, and display visual information. Its fundamental purpose is to convert abstract data and mathematical descriptions into visual representations that humans can perceive and understand.

1.1 Definition of Computer Graphics

Computer Graphics deals with the creation, manipulation, and representation of visual images using computers. It focuses on transforming numerical or symbolic data into visual form, typically as pixels on a display device.

At a conceptual level, Computer Graphics acts as a translator between machines (which understand numbers) and humans (who understand images).

1.2 Importance of Computer Graphics

The importance of Computer Graphics arises from the human brain’s ability to process visual information faster and more intuitively than textual or numerical data.

1.3 Applications of Computer Graphics

Computer Graphics finds application wherever visual interpretation improves understanding, realism, or interaction.

1.3.1 Entertainment

Used in animation films, 3D modeling, and special effects to create visually rich and believable content.

1.3.2 Education

Visual aids and simulation-based learning help learners grasp abstract and dynamic concepts effectively.

1.3.3 Medical Imaging

Graphics techniques convert medical scan data such as MRI and CT into interpretable images for diagnosis.

1.3.4 Scientific Visualization

Complex scientific data, such as climate models, is visualized to identify patterns and behaviors.

1.3.5 CAD/CAM

Computer-Aided Design and Manufacturing enable precise engineering design and architectural planning.

1.3.6 Virtual Reality and Gaming

Immersive environments are created by continuously rendering scenes based on user interaction.

2. Graphics Hardware

Graphics hardware consists of physical components that enable input, processing, and output of visual data.

2.1 Input Devices

Input devices allow users to provide data and commands to the graphics system.

2.2 Output Devices

Output devices display or produce the final visual result generated by the computer.

2.3 Frame Buffer

The frame buffer is a dedicated memory area that stores the color information of each pixel on the screen.

Each pixel’s color is represented using a fixed number of bits.

For a screen resolution of $1024 \times 768$ with 24-bit color depth:

$$1024 \times 768 \times 24 \text{ bits} \approx 18 \text{ MB}$$

This memory is continuously read by the display hardware to refresh the screen.

2.4 Graphics Pipeline

The graphics pipeline is an ordered sequence of processing stages that convert 3D objects into a 2D image displayed on the screen.

2.4.1 Stages of the Graphics Pipeline

TWEENING – DETAILED NOTES

1. Introduction

Tweening comes from the word in-betweening. It is a technique used in animation to create smooth movement by automatically generating frames between two important frames.

Instead of drawing every single frame manually, the animator defines only the important moments, and the computer fills the gap.

Tweening is widely used in 2D animation, 3D animation, motion graphics, user interface animations, and computer games.

What is "Tweening" short for, and what does it do?

A: Short for "In-betweening". It automatically generates intermediate frames between two keyframes to create smooth movement.

2. What Are Keyframes?

A keyframe is an important frame in animation where something significant happens.

It defines the starting state and the ending state of an object.

Think of keyframes as checkpoints.

Example:

The animator does not draw the ball moving step by step. Tweening creates those middle steps automatically.

3. What Is Tweening?

Tweening is the process of generating intermediate frames between two keyframes to create smooth transitions.

It interpolates (calculates values in between) different properties of an object such as:

Main purpose: To reduce manual effort and make motion look smooth and natural.

4. How Tweening Works

Tweening works using simple mathematics. The computer calculates small changes between two values and applies them frame by frame.

Example:

Keyframe 1: Object at $x = 0$

Keyframe 2: Object at $x = 100$

If 10 frames are needed in between, the position changes evenly.

Each frame moves the object by:

$$\frac{100 - 0}{10} = 10$$

So the object moves 10 units per frame until it reaches the final position.

If Frame 1 is at x=0 and Frame 10 is at x=100, how much does the object move per frame?

A: $\frac{100-0}{10} = 10$ units per frame.

5. Morphing

Morphing is a special and more advanced type of tweening.

In morphing, one shape smoothly transforms into another shape by blending intermediate forms.

Example:

This requires matching points carefully to avoid distortion.

How does Morphing differ from standard Tweening?

A: Morphing transforms one shape into another (e.g., circle to square), whereas typical tweening moves/rotates/scales an object.

6. Advantages of Tweening

7. Disadvantages of Tweening

8. Real-Life Examples of Tweening

Mobile and UI Animations:

Cartoons and Animation:

Games:

Web Animations (CSS / JavaScript):

PANNING – DETAILED NOTES

1. Introduction

Panning is a camera movement technique used in computer graphics, animation, and cinematography. In panning, the camera moves or rotates horizontally across a scene.

The important idea is that the camera stays at the same place but changes the direction it is facing.

This creates the feeling that the viewer is “looking around” the scene.

Panning is widely used in:

2. What is Panning?

Definition:

Panning is the horizontal movement of the camera view across a scene from a fixed position. The camera rotates left or right, which shifts what is visible on the screen without moving the camera forward or backward.

Key idea: The camera position does not change, only the viewing direction changes.

Simple Example:

Imagine you are standing at one place and you turn your head to the left or right. Your feet stay in the same position, but your view changes. This action is called panning.

In Panning, does the camera move position?

A: No. The camera stays fixed but rotates (changes direction) to scan the scene.

3. Purpose of Panning

Panning is used to control what the viewer sees and where their attention goes.

4. Panning in Computer Graphics

In computer graphics, panning is achieved by changing the camera’s viewing parameters instead of moving objects.

The scene remains the same, but the visible portion of the scene shifts horizontally.

This is computationally efficient because only the view changes, not the actual object positions.

5. Real-Life Examples of Panning

Animation and Movies:

Video Games:

User Interfaces:

Virtual Tours:

TRANSFORMATIONS – DETAILED NOTES

1. Introduction

In computer graphics, a transformation means changing an object’s position, size, orientation, or shape.

In simple words, transformations answer questions like:

Transformations are applied in both 2D and 3D graphics to move, resize, rotate, or distort objects.

All transformations are performed mathematically using matrix multiplication.

2. Why Matrices Are Used

Computers are good at numbers, not shapes. Matrices provide a uniform and efficient way to represent all transformations.

By multiplying a point with a transformation matrix, the new transformed point is obtained.

3. Types of Transformations

3.1 Translation

Translation moves an object from one position to another without changing its size or orientation.

Think of sliding an object on the screen.

If a point $P(x, y)$ is translated by $T_x$ in the x-direction and $T_y$ in the y-direction:

$$x' = x + T_x$$

$$y' = y + T_y$$

Matrix form (2D):

$$ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix} T_x \\ T_y \end{bmatrix} $$

Use: Moving objects on the screen.

3.2 Scaling

Scaling changes the size of an object.

Think of zooming in or zooming out.

If a point $P(x, y)$ is scaled by factors $S_x$ and $S_y$:

$$x' = x \cdot S_x$$

$$y' = y \cdot S_y$$

Matrix form:

$$ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} S_x & 0 \\ 0 & S_y \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} $$

Types of Scaling:

3.3 Rotation

Rotation turns an object around a fixed point, usually the origin.

Think of rotating a book on a table.

If a point $P(x, y)$ is rotated by angle $\theta$:

$$x' = x\cos\theta - y\sin\theta$$

$$y' = x\sin\theta + y\cos\theta$$

Matrix form:

$$ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} $$

Types of Rotation:

3.4 Reflection

Reflection creates a mirror image of an object.

Think of seeing yourself in a mirror.

Reflection about X-axis:

$$ \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} $$

Reflection about Y-axis:

$$ \begin{bmatrix} -1 & 0 \\ 0 & 1 \end{bmatrix} $$

Reflection about Origin:

$$ \begin{bmatrix} -1 & 0 \\ 0 & -1 \end{bmatrix} $$

3.5 Shearing

Shearing slants or skews the shape of an object.

Think of pushing the top of a rectangle sideways.

Shear in X-direction:

$$ \begin{bmatrix} 1 & Sh_x \\ 0 & 1 \end{bmatrix} $$

Shear in Y-direction:

$$ \begin{bmatrix} 1 & 0 \\ Sh_y & 1 \end{bmatrix} $$

4. Homogeneous Coordinates

Homogeneous coordinates are used to represent translation using matrix multiplication.

A 2D point $(x, y)$ is written as:

$$(x, y, 1)$$

This allows all transformations (translation, scaling, rotation) to be represented using a single matrix format.

5. Composite Transformation

Composite transformation means applying more than one transformation to an object.

Example: Rotate an object, then translate it.

$$ P' = T \cdot R \cdot P $$

Important Rule:

Matrix multiplication is not commutative.

$$A \cdot B \neq B \cdot A$$

This means the order of transformations matters and changes the final result.

Is the order of matrix multiplication important? Why?

A: Yes. Matrix multiplication is not commutative ($A \cdot B \neq B \cdot A$). Rotating then translating gives a different result than translating then rotating.

3D TRANSFORMATIONS, PROJECTION AND VISIBLE SURFACE DETECTION

1. 3D Transformations

3D transformations change the position, size, or orientation of objects in three-dimensional space. Unlike 2D, each point has three coordinates: $(x, y, z)$.

All 3D transformations are performed using 4×4 matrices with homogeneous coordinates.

What size matrix is used for 3D transformations with homogeneous coordinates?

A: A 4×4 Matrix.

1.1 Translation in 3D

Translation moves an object from one position to another in 3D space.

Think of shifting an object left–right, up–down, and forward–backward.

If a point $P(x, y, z)$ is translated by $(T_x, T_y, T_z)$:

$$x' = x + T_x$$

$$y' = y + T_y$$

$$z' = z + T_z$$

1.2 Scaling in 3D

Scaling changes the size of a 3D object.

Think of enlarging or shrinking a 3D model.

If a point $P(x, y, z)$ is scaled by $(S_x, S_y, S_z)$:

$$x' = x \cdot S_x$$

$$y' = y \cdot S_y$$

$$z' = z \cdot S_z$$

1.3 Rotation in 3D

Rotation in 3D is performed around one of the coordinate axes.

Rotation about X-axis:

The object rotates around the X-axis; X remains unchanged.

Rotation about Y-axis:

The object rotates around the Y-axis; Y remains unchanged.

Rotation about Z-axis:

The object rotates in the XY-plane.

Example: Rotation about Z-axis by angle $\theta$

$$ \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} = \begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} $$

1.4 Reflection in 3D

Reflection creates a mirror image of a 3D object about a plane.

Reflection about XY-plane:

Only Z-coordinate changes sign.

$$(x, y, -z)$$

Reflection about YZ-plane:

Only X-coordinate changes sign.

$$( -x, y, z )$$

Reflection about ZX-plane:

Only Y-coordinate changes sign.

$$( x, -y, z )$$

1.5 Shearing in 3D

Shearing slants a 3D object along one or more axes.

3D shearing is more complex and is represented using 4×4 matrices.

It is used in advanced modeling and special visual effects.

2. Projection in Computer Graphics

Projection is the process of displaying a 3D object on a 2D screen.

It converts 3D coordinates $(x, y, z)$ into 2D coordinates $(x', y')$.

This step is essential because screens are two-dimensional.

2.1 Parallel Projection

In parallel projection, all projection lines are parallel to each other.

Features:

2.2 Perspective Projection

In perspective projection, all projection lines meet at a single point called the center of projection.

This matches how human eyes see the real world.

Features:

Basic Concept:

Objects farther from the viewer have smaller projected coordinates.

3. Visible Surface Detection

Visible Surface Detection determines which surfaces of 3D objects are visible from a given viewpoint and which are hidden.

The computer must draw only the visible surfaces to create a realistic image.

3.1 Why Visible Surface Detection is Needed

Key Idea: When two objects overlap, the one closer to the viewer hides the one behind it.

Z-BUFFER AND A-BUFFER ALGORITHMS & PROJECTION

1. Z-Buffer Algorithm (Depth Buffer)

The Z-Buffer algorithm is one of the most common methods used to determine which surfaces are visible in a 3D scene.

Core idea: For every pixel on the screen, store how far that pixel is from the viewer.

The letter Z represents depth. Smaller Z means the object is closer to the viewer.

2. What is a Z-Buffer?

A Z-buffer is a special memory area that stores the depth (z-value) of every pixel on the screen.

There are two buffers involved:

Only the closest surface at each pixel is displayed.

3. How Z-Buffer Works

The Z-buffer algorithm works in a very systematic way.

Step 1: Initialization

Step 2: Process Each Polygon

Step 3: Depth Comparison

Decision Rule:

Update Rule:

4. Why Z-Buffer Works

At each pixel location, only the closest object matters.

The Z-buffer ensures that farther objects never overwrite nearer ones.

This matches how visibility works in the real world.

5. Advantages of Z-Buffer

6. Disadvantages of Z-Buffer

7. A-Buffer Algorithm (Anti-Aliased Buffer)

The A-buffer is an advanced version of the Z-buffer.

Key idea: Instead of storing only one surface per pixel, store all surfaces that pass through that pixel.

It is also called the Accumulation Buffer.

8. How A-Buffer Works

Each pixel stores a list of fragments instead of a single value.

Each fragment stores:

After all fragments are collected, the final pixel color is computed using alpha blending.

9. Why A-Buffer is Better than Z-Buffer

The A-buffer does not discard hidden surfaces immediately.

Instead, it combines them correctly based on transparency and coverage.

This results in smoother edges and realistic transparency.

10. Advantages of A-Buffer

11. Disadvantages of A-Buffer

12. Projection in Computer Graphics

Projection is the process of converting a 3D object into a 2D image.

This is required because computer screens are two-dimensional.

Projection converts coordinates:

$$(x, y, z) \rightarrow (x', y')$$

13. Why Projection is Needed

Projection defines how 3D space is viewed and interpreted on the screen.

TYPES OF PROJECTION

1. Introduction

Projection is the method used to display a three-dimensional object on a two-dimensional screen.

Since screens are flat, projection decides how depth is represented and how objects appear to the viewer.

Based on how projection lines behave, projection is divided into two major categories.

2. Classification of Projection

Projection is broadly classified into:

3. Parallel Projection

In parallel projection, all projection lines are parallel to each other.

These lines hit the view plane in the same direction.

Key idea: Distance from the viewer does not affect the size of the object.

Easy way to imagine:

Think of sunlight falling on objects. The rays are parallel, so shadows do not shrink or expand with distance.

Main Features:

Use Case:

When accurate measurements matter more than realism.

4. Perspective Projection

In perspective projection, all projection lines meet at a single point.

This point is called the Center of Projection (COP).

This method closely matches how the human eye sees the real world.

Easy way to imagine:

Stand on a straight road. The road appears to narrow and meet at a distant point. That point is a vanishing point.

Main Features:

Use Case:

Used in games, movies, simulations, and virtual reality where realism is important.

ANIMATION – DETAILED NOTES

1. Introduction to Animation

Animation is the technique of creating the illusion of motion by displaying a sequence of images, called frames, one after another at high speed.

The human eye cannot distinguish individual frames when they change rapidly, so the brain perceives continuous motion.

In computer graphics, animation is created by changing an object’s properties over time, such as:

Key idea: Motion = change over time.

2. Frame-by-Frame Animation

Definition:

In frame-by-frame animation, every single frame is drawn or designed manually.

When these frames are played continuously, smooth motion is created.

Easy way to understand:

Like drawing slightly different pictures on each page of a notebook and flipping it quickly.

Examples:

Pros:

Cons:

3. Keyframe Animation

Definition:

In keyframe animation, the animator defines only the important frames (keyframes).

The computer automatically generates the in-between frames.

Easy way to understand:

You decide where an object starts and ends. The computer fills the steps in between.

Examples:

Pros:

Cons:

4. Procedural Animation

Definition:

Procedural animation generates motion automatically using mathematics, algorithms, or physics rules.

The animator defines rules, not individual movements.

Easy way to understand:

You tell the computer “how things behave,” and it creates the motion.

Examples:

Pros:

Cons:

5. Behavioral Animation

Definition:

Behavioral animation uses rule-based or AI-like logic.

Objects or characters react automatically to their environment and other objects.

Easy way to understand:

Characters make decisions instead of following fixed paths.

Examples:

Pros:

Cons:

6. Motion Capture (MoCap)

Definition:

Motion capture records real human movement using cameras or sensors.

The captured motion is applied to digital characters.

Easy way to understand:

A real person moves, and the computer copies that movement to a character.

Examples:

Pros:

Cons:

7. Dynamics Animation

Definition:

Dynamics animation is based on physical laws such as gravity, wind, collisions, and friction.

Motion is calculated using physics simulations.

Easy way to understand:

The computer follows real-world physics to move objects.

Examples:

Pros:

Cons:

DDA, BRESENHAM & TRANSFORMATION — SOLVED PRACTICE NUMERICALS

1. DDA LINE DRAWING — SOLUTIONS

Q1. Line from (3,2) to (11,7) using DDA

Step 1: Identify start and end points

Start: $(x_1,y_1)=(3,2)$

End: $(x_2,y_2)=(11,7)$

Step 2: Compute differences

$\Delta x = 11 - 3 = 8$

$\Delta y = 7 - 2 = 5$

Step 3: Number of steps

Steps = max$(|\Delta x|, |\Delta y|) = 8$

Step 4: Increment values

$x_{inc} = \frac{8}{8} = 1$

$y_{inc} = \frac{5}{8} = 0.625$

Step 5: Generate points

Q2. Line from (1,1) to (4,9) using DDA

Step 1: Differences

$\Delta x = 3$, $\Delta y = 8$

Step 2: Steps

Steps = 8

Step 3: Increments

$x_{inc} = \frac{3}{8} = 0.375$

$y_{inc} = \frac{8}{8} = 1$

Step 4: Points

2. BRESENHAM LINE DRAWING — SOLUTION

Q3. Line from (2,3) to (12,8)

Step 1: Differences

$\Delta x = 10$, $\Delta y = 5$

Step 2: Initial decision parameter

$p_0 = 2\Delta y - \Delta x = 2(5) - 10 = 0$

Step 3: Plot points

3. BRESENHAM CIRCLE DRAWING — SOLUTIONS

Q4. First 8 symmetric points for r = 6

Initial values: $(x,y) = (0,6)$

Symmetric points:

Q5. Circle with r = 10 — first 5 points

4. TRANSFORMATION NUMERICALS — SOLUTIONS

Q6. Translation of Triangle by $T_x=2$, $T_y=5$

Formula: $(x',y') = (x+T_x, y+T_y)$

Q7. Scaling Rectangle by $S_x=2$, $S_y=3$

Formula: $(x',y') = (xS_x, yS_y)$

Q8. Rotate point (5,2) by 90° about origin

Formula:

$x' = -y$, $y' = x$

Result: $(-2,5)$

Q9. Rotate triangle by 45°

Rotation formulas:

$x' = x\cos45° - y\sin45°$

$y' = x\sin45° + y\cos45°$

Using $\cos45°=\sin45°=\frac{1}{\sqrt2}$

Q10. Reflect point (4,5) in Y-axis

Rule: $(x,y) → (-x,y)$

Result: $(-4,5)$

COHEN–SUTHERLAND LINE CLIPPING — SOLVED NUMERICAL

Problem Statement

Line Endpoints:

$P_1 = (2, 8)$, $P_2 = (18, 20)$

Clipping Window:

$x_{min}=5,\; y_{min}=10,\; x_{max}=15,\; y_{max}=25$

(a) Finding Region Codes

Cohen–Sutherland assigns a 4-bit code to each point:

For $P_1(2,8)$:

Region code = $0101_2 = 5$

For $P_2(18,20)$:

Region code = $0010_2 = 2$

Slope Calculation

The slope of the line is:

$$ m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{20 - 8}{18 - 2} = \frac{12}{16} = \frac{3}{4} $$

(b) Step-by-Step Clipping

Step 1: $P_1$ has code 5 (Left + Bottom).

We clip against the Left boundary first: $x = 5$.

Intersection formula:

$$ y = y_1 + m(x_{clip} - x_1) $$

$$ y = 8 + \frac{3}{4}(5 - 2) = 8 + \frac{3}{4} \cdot 3 = 8 + 2.25 = 10.25 $$

New point:

$P_1' = (5, 10.25)$

This point lies inside the window → region code = 0.


Step 2: $P_2$ has code 2 (Right).

Clip against the Right boundary: $x = 15$.

$$ y = 10.25 + \frac{3}{4}(15 - 5) = 10.25 + \frac{3}{4} \cdot 10 = 10.25 + 7.5 = 17.75 $$

New point:

$P_2' = (15, 17.75)$

This point also lies inside the window → region code = 0.

(c) Intersection Points

(d) Final Clipped Line Segment

Final visible line segment:
$[(5,\;10.25)\;\text{to}\;(15,\;17.75)]$

COHEN–SUTHERLAND LINE CLIPPING — SOLVED NUMERICAL (Q2)

Problem Statement

Line Endpoints:

$P_1 = (6, 2)$, $P_2 = (16, 32)$

Clipping Window:

$x_{min}=4,\; y_{min}=6,\; x_{max}=20,\; y_{max}=28$

(a) Finding Region Codes

Cohen–Sutherland region codes:

For $P_1(6,2)$:

Region code = $0100_2 = 4$

For $P_2(16,32)$:

Region code = $1000_2 = 8$

Slope Calculation

$$ m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{32 - 2}{16 - 6} = \frac{30}{10} = 3 $$

(b) Step-by-Step Clipping

Step 1: $P_1$ has code 4 (Bottom).

Clip against the Bottom boundary: $y = 6$.

Intersection formula:

$$ x = x_1 + \frac{y_{clip} - y_1}{m} $$

$$ x = 6 + \frac{6 - 2}{3} = 6 + \frac{4}{3} = 7.3333 $$

New point:

$P_1' = (7.3333, 6)$

This point lies inside the window → region code = 0.


Step 2: $P_2$ has code 8 (Top).

Clip against the Top boundary: $y = 28$.

$$ x = 16 + \frac{28 - 32}{3} = 16 - \frac{4}{3} = 14.6667 $$

New point:

$P_2' = (14.6667, 28)$

This point also lies inside the window → region code = 0.

(c) Intersection with Top / Bottom Boundary

(d) Final Visible Portion

Final clipped line segment:
$[(7.3333,\;6)\;\text{to}\;(14.6667,\;28)]$

Exact fractional form:
$\left[\left(\frac{22}{3},\,6\right)\;\text{to}\;\left(\frac{44}{3},\,28\right)\right]$

COHEN–SUTHERLAND LINE CLIPPING — SOLVED NUMERICAL (Q3)

Problem Statement

Line Segment:

$P_1 = (12, 5),\; P_2 = (40, 15)$

Clipping Window:

$x_{min}=10,\; y_{min}=10,\; x_{max}=30,\; y_{max}=20$

(a) Region Codes

Cohen–Sutherland outcode bit convention:

For $P_1(12,5)$:

Region code = $0100_2 = 4$

For $P_2(40,15)$:

Region code = $0010_2 = 2$

Slope Calculation

$$ m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{15 - 5}{40 - 12} = \frac{10}{28} = \frac{5}{14} $$

(b) Step-by-Step Clipping

Step 1: $P_1$ has code 4 (Bottom).

Clip against the Bottom boundary: $y = 10$.

Intersection formula:

$$ x = x_1 + \frac{y_{clip} - y_1}{m} $$

$$ x = 12 + \frac{10 - 5}{5/14} = 12 + \frac{5 \times 14}{5} = 12 + 14 = 26 $$

New point:

$P_1' = (26, 10)$

This point lies inside the window → region code = 0.


Step 2: $P_2$ has code 2 (Right).

Clip against the Right boundary: $x = 30$.

Intersection formula:

$$ y = y_1' + m(x_{clip} - x_1') $$

$$ y = 10 + \frac{5}{14}(30 - 26) = 10 + \frac{20}{14} = 10 + \frac{10}{7} = 11.4286 $$

New point:

$P_2' = (30, 11.4286)$

This point lies inside the window → region code = 0.

(c) Intersection Points

(d) Final Clipped Coordinates

Final visible line segment:
$[(26,\;10)\;\text{to}\;(30,\;11.4286)]$

Exact fractional form:
$\left[(26,\;10)\;\text{to}\;\left(30,\;\frac{80}{7}\right)\right]$

COHEN–SUTHERLAND LINE CLIPPING — SOLVED NUMERICAL (Q4)

Problem Statement

Line Segment:

$P_1 = (0,0),\; P_2 = (25,35)$

Clipping Window:

$x_{min}=5,\; y_{min}=5,\; x_{max}=20,\; y_{max}=30$

(a) Region Codes

Cohen–Sutherland outcode convention:

For $P_1(0,0)$:

Region code = $0101_2 = 5$

For $P_2(25,35)$:

Region code = $1010_2 = 10$

Slope Calculation

$$ m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{35 - 0}{25 - 0} = \frac{35}{25} = 1.4 $$

(b) Cohen–Sutherland Clipping Steps

Step 1: $P_1$ has code 5 (Left + Bottom).

Clip against the Left boundary first: $x = 5$.

Intersection formula:

$$ y = y_1 + m(x_{clip} - x_1) $$

$$ y = 0 + 1.4(5 - 0) = 7 $$

New point:

$P_1' = (5, 7)$

This point lies inside the window → region code = 0.


Step 2: $P_2$ has code 10 (Top + Right).

First try clipping against the Top boundary: $y = 30$.

$$ x = x_2 + \frac{y_{clip} - y_2}{m} = 25 + \frac{30 - 35}{1.4} = 25 - 3.5714 = 21.4286 $$

This $x$ value is outside the window $(>20)$, so clipping with Top is invalid.

Now clip against the Right boundary: $x = 20$.

$$ y = y_2 + m(x_{clip} - x_2) = 35 + 1.4(20 - 25) = 35 - 7 = 28 $$

New point:

$P_2' = (20, 28)$

This point lies inside the window → region code = 0.

(c) Intersection Points

(d) Final Accepted Line

Final clipped line segment:
$[(5,\;7)\;\text{to}\;(20,\;28)]$

COHEN–SUTHERLAND LINE CLIPPING — SOLVED NUMERICAL (Q5)

Problem Statement

Line Segment:

$P_1 = (8,25),\; P_2 = (40,5)$

Clipping Window:

$x_{min}=10,\; y_{min}=10,\; x_{max}=30,\; y_{max}=20$

(a) Region Codes

Cohen–Sutherland outcode bit convention:

For $P_1(8,25)$:

Region code = $1001_2 = 9$

For $P_2(40,5)$:

Region code = $0110_2 = 6$

Slope Calculation

$$ m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{5 - 25}{40 - 8} = \frac{-20}{32} = -\frac{5}{8} = -0.625 $$

(b) Step-by-Step Clipping

Step 1: $P_1$ has code 9 (Left + Top).

Clip against the Left boundary first: $x = 10$.

$$ y = y_1 + m(x_{clip} - x_1) = 25 + (-0.625)(10 - 8) = 25 - 1.25 = 23.75 $$

New point:

$P_1' = (10, 23.75)$

This point is still above the window ($y > 20$) → new code = $1000_2$ (Top).


Step 2: Clip this point against the Top boundary: $y = 20$.

$$ x = x_1' + \frac{y_{clip} - y_1'}{m} = 10 + \frac{20 - 23.75}{-0.625} = 10 + \frac{-3.75}{-0.625} = 10 + 6 = 16 $$

New point:

$P_1'' = (16, 20)$

This point lies inside the window → region code = 0.


Step 3: $P_2$ has code 6 (Right + Bottom).

Clip against the Right boundary first: $x = 30$.

$$ y = y_2 + m(x_{clip} - x_2) = 5 + (-0.625)(30 - 40) = 5 + 6.25 = 11.25 $$

New point:

$P_2' = (30, 11.25)$

This point lies inside the window → region code = 0.

(c) Intersection with Right & Bottom Boundaries

(d) Final Clipped Segment

Final visible line segment:
$[(16,\;20)\;\text{to}\;(30,\;11.25)]$

Semester Recap