Lecture-09: Line Drawing (CGA)

 Line Drawing


Straight Line

A straight line is the shortest distance between two points.
In coordinate geometry and computer graphics, a straight line is represented using an equation.

A line can be:

  • Horizontal
  • Vertical
  • Slanting (inclined)

 

Equation of a Straight Line

The most common form is the slope-intercept form:

Where:

  • = slope (gradient) of the line
  • = y-intercept (point where line crosses the y-axis)



 Slope of a Straight Line

Slope tells how steep the line is.

m = (y2- y1)/ (x2-x1) =Δy/Δx = dy/dx​


Where:

    • and are two points on the line.
    • Δx = x2-x1, Δy = y2- y1

 

Types of Straight Lines

1. Horizontal Line

Equation:

    • Slope
    • Parallel to x-axis

Example:


2. Vertical Line

Equation:


    • Slope is undefined
    • Parallel to y-axis

Example:


3. Positive Slope Line

If slope :

    • Line rises from left to right.

Example:


4. Negative Slope Line

If slope :

    • Line falls from left to right.

Example:


Equation Using Two Points

If two points are known, the equation is:

This is called the two-point form of a line.

 

Example

Find the equation of the line passing through and .

Step 1: Find slope



Step 2: Use slope-intercept form



Substitute point :




So, the equation becomes:

Y = (3/2)​x + 3/1​

 

Algorithm for line Drawing:

1.    Direct use of line equation

2.    DDA (Digital Differential Analyzer)

3.    Bresenham's Algorithm

DDA Algorithm

DDA stands for Digital Differential Analyzer. It is an incremental method of scan conversion of line. In this method calculation is performed at each step but by using results of previous steps.

 

Algorithm

Step 1:

Slope



 

Step 2:




 

Step 3:

Case I:

If



Assign



Then,


Case II:

If



Assign



Then,




Question: Calculate the points between the starting point (1,1) and ending point (4,3) using DDA algorithm.

 

For the DDA line drawing algorithm:

Starting point:



Ending point:



 

Step 1: Calculate and




 

 

Step 2: Find the number of steps




 

Step 3: Calculate increments




 

Step 4: Calculate points

Initial point:



Step

x

y

Rounded Point

0

1.00

1.00

(1,1)

1

2.00

1.67

(2,2)

2

3.00

2.34

(3,2)

3

4.00

3.01

(4,3)

 

Final DDA Points



 

Similar Practice Questions

1.   Calculate the points between the starting point and ending point using DDA algorithm.

2.   Calculate the points between the starting point and ending point using DDA algorithm.

3.   Calculate the points between the starting point and ending point using DDA algorithm.

4.   Calculate the points between the starting point and ending point using DDA algorithm.


 

 

 

 

 

 

 

Post a Comment

0 Comments