Bresenham's circle algorithm

Circles have the property of being highly symmetrical, which is handy when it comes to drawing them on a display screen. Consider the diagram below: |y | \\ ..... / . | . . \\ | / . . \\|/ . \--.---+---.-- . /|\\ . x . / | \\ . . | . / ..... \\ | | ```(This diagram is supposed to be a circle, try viewing it in 50 line mode). [Read More]

Routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all.

Problem Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all. Solution Let (x ^ 2 + y ^2 = r ^ 2)……………………………..1 The basic idea is to draw one quadrant and replicate it to other four quadrants. Assuming the center is given as (a,b) and radius as r units, then start X from (a+r) down to (a) and start Y from (b) up to (b+r). [Read More]

Calculate pow function

Lets look at some solutions. Solution 1 - Using recursion int pow(int x, int y) { if(y == 1) return x ; return x \* pow(x, y-1) ; } Divide and Conquer C program /\* Function to calculate x raised to the power y \*/ int power(int x, unsigned int y) { if( y == 0) return 1; else if (y%2 == 0) return power(x, y/2)\*power(x, y/2); else return x\*power(x, y/2)\*power(x, y/2); } /\* Program to test function power \*/ int main() { int x = 2; unsigned int y = 3; printf("%d", power(x, y)); getchar(); return 0; } Time Complexity: O(n) [Read More]