Tag Archives: C++

Implementing Midpoint Circle Algorithm in C++

The Midpoint Circle Algorithm (MPC) is an efficient way to draw a circle using raster graphics. It is an improved version of Bresenham’s circle drawing algorithm and avoids using floating-point calculations, making it faster for computer graphics. This blog post explains a C++ program that implements the Midpoint Circle Algorithm using the graphics.h library.

Continue reading Implementing Midpoint Circle Algorithm in C++

Implementing Midpoint Ellipse Algorithm in C++

Ellipses are fundamental shapes in computer graphics, widely used in various applications such as image processing, animation, and CAD systems. In this blog post, we’ll explore how to draw an ellipse using the Midpoint Ellipse Algorithm in C++ with graphics.h.

Introduction to Midpoint Ellipse Algorithm

The Midpoint Ellipse Algorithm is an efficient way to generate an ellipse using only integer operations. It is based on the midpoint method, which determines the next pixel position by evaluating a decision parameter.

This algorithm divides the ellipse into two regions:

  1. Region 1: The slope of the curve is less than 1.
  2. Region 2: The slope of the curve is greater than 1.

Each region is processed separately to ensure a smooth curve.

C++ Code Implementation

Below is the C++ program that implements the Midpoint Ellipse Algorithm. It uses the graphics.h library, which is part of the Turbo C++ environment.

Continue reading Implementing Midpoint Ellipse Algorithm in C++

C++ Program to Implement DDA Line Drawing Algorithm

The Digital Differential Analyzer (DDA) algorithm is one of the simplest line-drawing algorithms in computer graphics. It is an incremental method that determines intermediate points between two given endpoints of a line. In this blog post, we will explore the DDA algorithm, understand its working, and implement it using C++.

What is the DDA Algorithm?

The DDA (Digital Differential Analyzer) algorithm is a rasterization algorithm used to draw lines on a pixel-based display. It works by calculating the intermediate points that form a straight line between two given points and plotting them sequentially. The algorithm uses floating-point arithmetic to incrementally determine the next pixel position.

Steps of the DDA Algorithm:

  1. Calculate the change in x (dx) and y (dy) between the starting and ending points.
  2. Determine the number of steps required for the line. This is the greater value between dx and dy.
  3. Compute the increment values dx/steps and dy/steps to determine how much x and y should increase per step.
  4. Start from the initial point and iteratively plot the next points by adding the increment values.
  5. Stop when the endpoint is reached.

C++ Implementation of DDA Algorithm

Here is a simple C++ program to implement the DDA line drawing algorithm using the graphics.h library:

Continue reading C++ Program to Implement DDA Line Drawing Algorithm

Mix (C++ and Assembly) Program to Sort Numbers in Descending Order

This post demonstrates how to sort an array of integers using inline assembly in C++. We use basic comparison and swap logic in assembly embedded within a C++ program.

#include<iostream.h>
#include<conio.h>
void main()
{
    int a[5], x, y;
    int i, j;
    cout << "\n Enter 5 Numbers:";
    for(i = 0; i < 5; i++)
    {
        cin >> a[i];
    }
    //Sorting
    for(i = 0; i < 4; i++)
    {
        for(j = 0; j < 4; j++)
        {
            x = a[j];
            y = a[j + 1];
            asm {
                mov ax, x
                mov bx, y
                cmp ax, bx
                jge nxt
                mov cx, ax
                mov ax, bx
                mov bx, cx
                mov x, ax
                mov y, bx
            }
            nxt:
            a[j] = x;
            a[j + 1] = y;
        }
    }
    cout << "\n Sorted Array:";
    for(i = 0; i < 5; i++)
        cout << a[i] << " ";
    getch();
}
Continue reading Mix (C++ and Assembly) Program to Sort Numbers in Descending Order