Can somebody explain the difference between Bresenham and Midpoint Circle drawing algorithms? All I am able to understand is that in both algorithms we compute coordinates of an octant instead of whole Circle and in Midpoint algo we compute those coordinates by putting middle point of the 2 possible next coordinates in Circle equation.
C++ – Bresenham Vs Midpoint Circle drawing algorithm
algorithmscgraphics
Related Solutions
While performance is really a result of implementation rather than languages, there are, in practice, faster and slower languages.
C is usually the fastest in comparisons. C compilers are relatively mature, and C programs require minimal run-time support. A C program will normally be compiled to something that can be loaded and executed, with just a little preparation on the part of the computer. (There have been C interpreters, and they were slow like you'd expect.)
Fortran is not usually in those computations, but is similar in most respects. Fortran was inherently faster in large-scale floating-point computations than the C of the original Standard, since the Fortran compiler could assume, say, that the three matrices passed to a multiplication program were disjoint, and could optimize on that basis. C compilers couldn't assume that.
Java programs are normally compiled to an artificial machine language, and that is normally compiled on the fly (just-in-time compiling). That could theoretically be faster than C-style compilation (it could make better guesses about the flow of execution, and it could tailor the compilation to the exact system in use), but in practice isn't. Java also requires more run-time support, such as a garbage collector, and the JIT compiler and runtime have to load and get going. That results in increased startup time, which can be noticeable.
Python programs are normally compiled to an artificial machine language and then interpreted, which is slower. It is possible to store the compiled files (".pyc"), but frequently only the source is stored, so to execute it is necessary to compile first and then interpret, which is slow. Also, Python has dynamic typing, which means the compiler doesn't know everything's type up front, and therefore Python functions have to be able to take different data types at runtime, which is inefficient.
There's always room for surprises. On one celebrated occasion, a CMU Common Lisp program out-number-crunched a Fortran program. Common Lisp requires garbage collection, which apparently wasn't an issue in that application, and normally is dynamically typed, but it's possible to declare all types statically. The Fortran compiler had a small inefficiency the CMU Common Lisp compiler didn't, and was duly improved afterwards.
A very basic and completely untested pseudo-code for drawing an ellipse using a parametric polar equation is below:
Function draw_ellipse(int X1, int Y1, int X2, int Y2)
RX = (X2 - X1) / 2
RY = (Y2 - Y1) / 2
CX = (X2 + X1) / 2
CY = (Y2 + Y1) / 2
for Angle = 0 to 360
X = CX + cos(Angle) * RX
Y = CY + sin(Angle) * RY
if (Angle > 0) DrawLine(LastX, LastY, X, Y)
LastX = X
LastY = Y
Next Angle
End Function
Notes/Comments:
- Assumes an unrotated ellipse.
- Change to radians (0 to 2 pi) if your language cos/sin takes angles in radians (like C/C+ does).
- You can use symmetry to reduce the loop size to 0 - 90 degrees.
- Change the drawing precision as needed by changing the loop step amount (is 1 degree as shown).
Best Answer
Bresenham's circle algorithm is simply an optimized version of the Midpoint circle algorithm. The difference is Bresenham's algorithm uses just integer arithmetics, whilst Midpoint still needs floating point. Wikipedia is (at least today) not very clear about that, but if you read that article two or three times, you might understand what the authors meant.