Lecture07 - Output Primitives (Part III)

# Lecture07 - Output Primitives (Part III) - OutputPrimitives...

This preview shows pages 1–9. Sign up to view the full content.

Output Primitives Output Primitives Part III Circle-Generating Algorithm

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 A very fine place to start A very fine place to start Let’s begin by looking at the equation of a circle: Solving for y :
3 A very fine place to start A very fine place to start And this is one of the sample codes: void circleSimple(int xCenter, int yCenter, int radius, Color c) { int x, y, r2; r2 = radius * radius; for (x = -radius; x <= radius; x++) { y = (int)(sqrt(r2 - x*x) + 0.5); setPixel(xCenter + x, yCenter + y, c); setPixel(xCenter + x, yCenter – y, c); } }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 The result The result We came across this problem with lines before… Sometimes the slope of the line tangent to a point the circle is greater than 1. Stepping in x won’t work there. So we could look for this case and step in y
5 Is it a good solution? Is it a good solution? … maybe not! But on both cases, we were taking advantage of the circle’s symmetry when we draw both positive and negative values for y (or x). This is called 2-way symmetry . Are there more symmetries to exploit?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Symmetry abounds Symmetry abounds Sure, let’s try 4-way symmetry . With just a quick hack, we get:
7 Symmetry abounds Symmetry abounds void circle4Way(int xCenter, int yCenter, int radius, Color c) { int x, y, r2; setPixel(xCenter, yCenter + radius, c); setPixel(xCenter, yCenter – radius, c); r2 = radius * radius; for (x = 1; x <= radius; x++) { y = (int)(sqrt(r2 - x*x) + 0.5); setPixel(xCenter + x, yCenter + y, c); setPixel(xCenter + x, yCenter – y, c); setPixel(xCenter - x, yCenter + y, c); setPixel(xCenter - x, yCenter – y, c); } }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The same result but in half the time … The same result but in half the time … That didn’t fix a thing. Oh sure, it’s faster – just half as many evaluations – but it’s no more correct than our first try. Why didn’t this work?
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/05/2010 for the course COMPUTER S 876 taught by Professor Ch during the Spring '10 term at Amirkabir University of Technology.

### Page1 / 24

Lecture07 - Output Primitives (Part III) - OutputPrimitives...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online