Clipping
Clipping
Institute of Engineering
Thapathali Campus, Thapathali
Submitted by:
Name: Chitra Raj Joshi
Roll No.: THA080BEI018
Submitted to:
Department of Electronics and Computer Engineering
Submission Date: February 7, 2025
Title: Ellipse Using Midpoint Algorithm
Theory:
The Midpoint Algorithm for drawing an ellipse is an efficient method that uses
integer-based calculations to determine the points on the ellipse's boundary. It is an
extension of the Midpoint Circle Drawing Algorithm, designed to handle the elliptical
shape by considering both the major and minor axes.
An ellipse is a geometric shape defined by two axes: the major axis (longer axis) and
the minor axis (shorter axis). The general equation for an ellipse with its center at the
origin is:
(x / a)2 + (y / b)2 = 1
Where:
The midpoint algorithm for ellipse drawing works by dividing the ellipse into two
regions based on the slope of the tangent. These regions are referred to as Region 1
and Region 2.
Region 1: When the slope of the tangent is less than 1, we primarily increase
the x-coordinate while adjusting the y-coordinate based on the ellipse
equation. This region is characterized by a predominantly horizontal stretch of
the ellipse.
2
Midpoint Ellipse Algorithm:
1. Input the length of the semi-major axis and semi-minor axis and obtain center
of ellipse.
3. Obtain the initial decision parameter for region 1 as: P0 = ry2 + 1/4rx2 - rx2 ry
Pk < 0 Pk >= 0
xk = xk + 1 xk = xk + 1
yk = yk yk = yk + 1
6. Obtain the initial value in region 2 using the last point (x, y) of region 1 as:
P0 = ry2 (x + 1/2)2 + rx2 (y - 1)2 - rx2 ry2
Pk <= 0 Pk > 0
xk = xk + 1 xk = xk
yk = yk - 1 yk = yk - 1
9. Now obtain the symmetric points in the three quadrants and plot the
coordinate value as: x=x+xc, y=y+yc
3
4
Code:
#include <graphics.h> int newX1 = X1 + Umax * dx;
#include <iostream> int newY1 = Y1 + Umax * dy;
#include <cmath> int newX2 = X1 + Umin * dx;
#include <algorithm> int newY2 = Y1 + Umin * dy;
5
Output:
6
Conclusion: